-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmakeChromSizesFromFasta.py
More file actions
50 lines (41 loc) · 1.17 KB
/
Copy pathmakeChromSizesFromFasta.py
File metadata and controls
50 lines (41 loc) · 1.17 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##################################
# #
# Last modified 2018/11/19 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
import gzip
def run():
if len(sys.argv) < 2:
print 'usage: python %s inputfilename outfilename' % sys.argv[0]
sys.exit(1)
inputfilename = sys.argv[1]
outputfilename = sys.argv[2]
outfile = open(outputfilename, 'w')
if inputfilename.endswith('.gz'):
input_stream = gzip.open(inputfilename)
else:
input_stream = open(inputfilename)
LenDict={}
seq=0
chr=''
for line in input_stream:
if line[0]=='>':
if chr != '' and seq != 0:
outline = chr+'\t'+str(seq)
print outline
outfile.write(outline+'\n')
seq=0
chr=line[1:len(line)].strip()
if seq=='':
continue
else:
seq=seq+len(line.strip())
outline = chr+'\t'+str(seq)
print outline
outfile.write(outline+'\n')
outfile.close()
run()