forked from mpg-age-bioinformatics/htseq-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.genome
executable file
·32 lines (29 loc) · 1.03 KB
/
make.genome
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
#!/usr/bin/env python
import os
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--multifasta", help="multifasta file")
parser.add_argument("-o", "--output_file", help="Output file")
args = parser.parse_args()
infile=os.path.realpath(str(args.multifasta))
output=args.output_file
seq=[]
with open(output, "w") as fout:
with open(infile, "r") as fa:
for line in fa:
l=line.split("\n")[0]
if ">" in l:
if len(seq) > 0:
seq="".join(seq)
print "##contig=<ID="+ref+",length="+str(len(seq))+">"
sys.stdout.flush()
fout.write(str(ref).split(" ")[0]+"\t"+str(len(seq))+"\n")
ref=l.split(">")[1]
seq=[]
else:
seq.append(l)
seq="".join(seq)
print "##contig=<ID="+ref+",length="+str(len(seq))+">"
sys.stdout.flush()
fout.write(str(ref).split(" ")[0]+"\t"+str(len(seq))+"\n")