Skip to content

Commit

Permalink
Merge pull request #326 from ConesaLab/fastq_gz_support
Browse files Browse the repository at this point in the history
Added compatibility for .gz compressed fastq isoforms to SQANTI3_QC
  • Loading branch information
Fabian-RY authored Sep 12, 2024
2 parents d8a5ffa + 8c25e27 commit 57d30b1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sqanti3_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import math
import csv
import numpy as np
import gzip

from statistics import mean
from collections import defaultdict, Counter, namedtuple
from collections.abc import Iterable
Expand Down Expand Up @@ -517,7 +519,7 @@ def correctionPlusORFpred(args, genome_dict):
print("Skipping aligning of sequences because GTF file was provided.", file=sys.stdout)

ind = 0
with open(args.isoforms, 'r') as isoforms_gtf:
with open(args.isoforms) as isoforms_gtf:
for line in isoforms_gtf:
if line[0] != "#" and len(line.split("\t"))!=9:
sys.stderr.write("\nERROR: input isoforms file with not GTF format.\n")
Expand Down Expand Up @@ -2149,10 +2151,16 @@ def rename_isoform_seqids(input_fasta, force_id_ignore=False):
:return: output fasta with the cleaned up sequence ID, is_fusion flag
"""
type = 'fasta'
with open(input_fasta) as h:
# gzip.open and open have different default open modes:
# gzip.open uses "rb" (read in binary format)
# open uses "rt" (read in text format)
# This can be solved by making explicit the read text mode (which is required
# by SeqIO.parse)
open_function = gzip.open if input_fasta.endswith('.gz') else open
with open_function(input_fasta, mode="rt") as h:
if h.readline().startswith('@'): type = 'fastq'
f = open(input_fasta[:input_fasta.rfind('.')]+'.renamed.fasta', 'w')
for r in SeqIO.parse(open(input_fasta), type):
f = open(input_fasta[:input_fasta.rfind('.')]+'.renamed.fasta', mode='wt')
for r in SeqIO.parse(open_function(input_fasta, "rt"), type):
m1 = seqid_rex1.match(r.id)
m2 = seqid_rex2.match(r.id)
m3 = seqid_fusion.match(r.id)
Expand Down

0 comments on commit 57d30b1

Please sign in to comment.