Skip to content

Commit

Permalink
Merge pull request #28 from ZKai0801/master
Browse files Browse the repository at this point in the history
fix bugs mentioned in #26
  • Loading branch information
sfchen authored Jun 28, 2020
2 parents 70f76e8 + ac29e35 commit 5958b57
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/make_fusion_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def make_fusion_gene(gene, fw, refflat):
transcripts = {}
with open(refflat, "r") as fh:
for line in fh:
if gene[0] not in line:
cur_gene, transcript, chrom, strand, start, end, _, _, _, exonstart, exonend = line.rstrip("\n").split("\t")
if gene[0] != cur_gene:
continue
_, transcript, chrom, _, start, end, _, _, _, exonstart, exonend = line.rstrip("\n").split("\t")
transcripts[transcript] = (chrom, start, end, exonstart, exonend)
transcript = get_longest_transcript(transcripts.keys(), refflat)
chrom, start, end, exonstart, exonend = transcripts[transcript]
Expand All @@ -39,15 +39,17 @@ def make_fusion_gene(gene, fw, refflat):
elif len(gene) == 2:
with open(refflat, "r") as fh:
for line in fh:
if gene[1] not in line:
_, transcript, chrom, strand, start, end, _, _, _, exonstart, exonend = line.rstrip("\n").split("\t")
if gene[1] != transcript:
continue
_, transcript, chrom, _, start, end, _, _, _, exonstart, exonend = line.rstrip("\n").split("\t")
break

# write to a file
header = f">{gene[0]}_{transcript},{chrom}:{start}-{end}\n"
fw.write(header)
exons = list(zip(exonstart.split(","), exonend.split(",")))[:-1]
if strand == "-":
exons = exons[::-1]
for index, each_exon in enumerate(exons, start=1):
fw.write(f'{index},{each_exon[0]},{each_exon[1]}\n')
fw.write("\n")
Expand Down

0 comments on commit 5958b57

Please sign in to comment.