-
Notifications
You must be signed in to change notification settings - Fork 48
/
gencode_parse.py
32 lines (29 loc) · 1.12 KB
/
gencode_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('file', help='GENCODE FASTA file to strip long names from and make a gene map out of')
args = parser.parse_args()
transcripts = []
with open(args.file,'r') as fid1:
with open('transcripts.fasta','w') as fid2:
with open('genemap.tsv','w') as fid3:
for line in fid1:
if line[0]=='>':
#we have a transcript name on our hands, time to get parsing
#only interested in ENST and ENSG, which are the first two fields
line = line[1:].split('|')[:2]
#not interested in the dot version number
line[0] = line[0].split('.')[0]
line[1] = line[1].split('.')[0]
#so is this a duplicate of an already registered ENST as that happens sometimes
if line[0] in transcripts:
toggle = 0
else:
toggle = 1
transcripts.append(line[0])
#now we can make our cleaned up transcript name and our gene map entry
fid2.write('>'+line[0]+'\n')
fid3.write(line[0]+'\t'+line[1]+'\n')
else:
#copy over actual transcript sequence, unless we're skipping the transcript
if toggle == 1:
fid2.write(line)