-
Notifications
You must be signed in to change notification settings - Fork 0
/
getting_fastaIDs.py
34 lines (29 loc) · 963 Bytes
/
getting_fastaIDs.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
## Program to recover the sequences ID from fasta files
exit = 0
## Get the name of the fasta file and test it
while exit == 0:
user_inp = raw_input("Enter the name of the fasta file: ")
if user_inp == "done":
print "See you later!"
break
try:
file = open(user_inp)
exit = 1
except:
print "Sorry, can't find this file. \nTry another name or type \"done\" to finish the program ;)"
continue
## Recover the ID of the sequences and save it in the chosen output
if exit == 1:
user_out = raw_input("Enter the name of the output file: ")
output = open(user_out,"w")
for line in file:
if line.startswith(">"):
list = line.split()
list1 = list[0]
IDs = list1.split(">")
ID1 = list[0]
ID_list = ID1.split(">")
ID2 = ID_list[1]
output.write(ID2)
output.write("\n")
output.close()