-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtaxanumber.py
68 lines (59 loc) · 1.53 KB
/
taxanumber.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from Bio import AlignIO
import sys
import glob
import os
import shutil
inputfolder = sys.argv[1]
if len(sys.argv)>2:
exclusion_file = sys.argv[2]
exclusion_list = []
if len(sys.argv) == 3:
print "reading exclusion list..."
exfile = open(exclusion_file, "r")
for line in exfile:
l = line.strip()
exclusion_list.append(l)
exfile.close()
print "read", len(exclusion_list), "records"
files = glob.glob(inputfolder+"/*.fas")
count = 0
counter = 0
misdata = 0
totaldata = 0
locilist = []
for f in files:
count +=1
if f.split("/")[-1] not in exclusion_list:
counter += 1
locilist.append(f)
#for seq_record in SeqIO.parse(f, "fasta"):
# counter +=1
# ali = AlignIO.read(f, "fasta")
# print f, len(ali)
# print f, len(ali)#counter
# if len(ali) > 8:
# counter += 1
# print f, "good", len(ali)
# locilist.append(f)
# for seq in ali:
# if seq.id == "Cryptostemma_sp_Peru_249":
# counter += 1
# print f, "good", len(ali)
# locilist.append(f)
print "Good %i out of total %i records" % (counter, count)
#copy files
if not os.path.exists ("./subset2/"):
os.makedirs("./subset2") #creating folder if necessary
else:
shutil.rmtree("./subset2/") #removing old files
os.makedirs("./subset2")
print "copying files:"
for x in locilist:
locusfname = x.split("/")[-1]
#print locusfname
if not os.path.exists ("./subset2/"+locusfname):
prog = "copying "+str(locusfname)+"..."
sys.stdout.write(prog+"\r")
sys.stdout.flush()
shutil.copy2(inputfolder+locusfname, "./subset2")
print "done"