Created
January 24, 2022 20:47
-
-
Save ressy/7a73874eabcec8c584c8336e9120e424 to your computer and use it in GitHub Desktop.
Quick clumsy script to convert an Illumina InterOp/ExtractionMetricsOut.bin v2 file into CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Quick clumsy script to convert an Illumina InterOp/ExtractionMetricsOut.bin v2 | |
file into CSV. | |
http://illumina.github.io/interop/extraction_v2.html | |
""" | |
import sys | |
import csv | |
from struct import unpack | |
from pathlib import Path | |
BASES = ["a", "c", "g", "t"] | |
FIELDS = ["lane", "tile", "cycle"] + [f"focus_{b}" for b in BASES] + [f"max_int_{b}" for b in BASES] + ["datestamp"] | |
with open(sys.argv[1], "rb") as f_in: | |
writer = csv.writer(sys.stdout, lineterminator="\n") | |
version, record_size = unpack("<BB", f_in.read(2)) | |
sys.stderr.write(f"Version: {version}\n") | |
sys.stderr.write(f"Record Size: {record_size}\n") | |
if version != 2 or record_size != 38: | |
sys.stderr.write( | |
"ERROR: Expected version 2 with record size 38, not " | |
f"version {version} with record size {record_size}\n") | |
sys.exit(1) | |
writer.writerow(FIELDS) | |
while True: | |
data = f_in.read(record_size) | |
if len(data) != record_size: | |
break | |
writer.writerow(unpack("<HHHffffHHHHQ", data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment