forked from fjruizruano/ngs-protocols
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_seq.py
executable file
·53 lines (37 loc) · 857 Bytes
/
extract_seq.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
from Bio import SeqIO
import sys
# open FASTA and list of sequences
try:
secu = sys.argv[1]
lis = sys.argv[2]
except:
secu = raw_input("Sequence FASTA file: ")
lis = raw_input("List name file: ")
secu = SeqIO.parse(open(secu), "fasta")
lista = [line.strip() for line in open(lis)]
# create lists
names = []
seque = []
# create a dictionary with name and sequence
print "\nCreating database...\n"
for a in secu:
names.append(a.id)
seque.append(a.seq)
dictio = dict(zip(names, seque))
# print output
output = open(lis + ".extract", "w")
i = 0
j = 0
for b in lista:
try:
output.write(">" + b + "\n")
output.write(str(dictio[b])+"\n")
print "Getting sequence %s" % b
i += 1
except:
print "Not found " + b
j += 1
pass
print "\nFOUND " + str(i) + " sequences"
print "\nNOT FOUND " + str(j) + " sequences"