Skip to content

Commit

Permalink
Update primary_transcript.py for python3, resolves #345
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemms committed Feb 13, 2020
1 parent 5bbcbee commit acf4ce5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/primary_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def ScanTags(fn):
"""
tags = set()
tokens = []
with open(fn, 'rb') as infile:
with open(fn, 'r') as infile:
for line in infile:
if not line.startswith(">"): continue
tokens.append([t.split(":", 1) for t in line.rstrip().split() if ":" in t])
Expand All @@ -26,15 +26,15 @@ def ScanTags(fn):

def ScanTags_NCBI(fn):
genes = []
with open(fn, 'rb') as infile:
with open(fn, 'r') as infile:
for line in infile:
if not line.startswith(">"): continue
genes.append(line[1:].split(".", 1)[0])
print("%d sequences, %d genes" % (len(genes), len(set(genes))))

def ScanTags_with_fn(fn, gene_name_fn):
genes = []
with open(fn, 'rb') as infile:
with open(fn, 'r') as infile:
for line in infile:
if not line.startswith(">"): continue
genes.append(gene_name_fn(line))
Expand All @@ -50,7 +50,7 @@ def GetGeneName(acc_line):
def CreatePrimaryTranscriptsFile(fn, dout, gene_name_fn=GetGeneName):
# Get genes and lengths
max_gene_lens = defaultdict(int)
with open(fn, 'rb') as infile:
with open(fn, 'r') as infile:
lines = [l.rstrip() for l in infile]
N = len(lines) - 1
nAcc = 0
Expand Down Expand Up @@ -88,7 +88,7 @@ def CreatePrimaryTranscriptsFile(fn, dout, gene_name_fn=GetGeneName):
# Parse file second time and only write out sequences that are longest variant
nGenesWriten = 0
outfn = dout + os.path.basename(fn)
with open(outfn, 'wb') as outfile:
with open(outfn, 'w') as outfile:
iLine = -1
while iLine < N:
iLine += 1
Expand Down

0 comments on commit acf4ce5

Please sign in to comment.