-
Notifications
You must be signed in to change notification settings - Fork 9
/
12ai2.py
executable file
·51 lines (41 loc) · 1.14 KB
/
12ai2.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
#12ai.py - make a file with unique abundances
import os,sys
### load the genotype name
work_dir=os.getcwd()
lib_path = os.path.abspath(os.getcwd())
script_dir=os.getcwd()+'/'+'scripts'
sys.path.append(lib_path)
from configuration_12 import genotype
def parse_file():
### load unique read counts
first_line=True
abu = {} ### a list to store abundace
len_type={} ### store different type of length
for line in open(infile,'r'):
line=line.strip()
token=line.split('\t')
if first_line==True:
string = 'Size'
for name in genotype:
abu[name]={}
string += ('\t'+name)
o.write(string+'\n')
else:
len_type[len(token[0])]=''
for i in range(len(genotype)):
if int(token[i+1])!=0:
if len(token[0]) in abu[genotype[i]]:
abu[genotype[i]][len(token[0])] += int(token[i+1])
else:
abu[genotype[i]][len(token[0])] = int(token[i+1])
first_line=False
for key2 in sorted(len_type.iterkeys()):
string=''
for key1 in genotype:
string += '\t'+str(abu[key1][key2])
o.write(str(key2)+string+'\n')
o.close()
if __name__ == "__main__":
infile=sys.argv[1]
o=open(sys.argv[2],'w')
parse_file()