-
Notifications
You must be signed in to change notification settings - Fork 0
/
biomark_count2.py
60 lines (50 loc) · 1.5 KB
/
biomark_count2.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
#Usage: python biomark_count2.py [input file] > [name of output file]
#Example of input
#adina.csv
import sys
gene_list = []
last_gene = ''
sample_list = []
counter = 0
count_list = []
gene_list = []
count_list_counter = 0
big_count_list = []
all_genes = []
all_samples = []
d_genes = {}
d_all_samples = {}
for n, line in enumerate(open(sys.argv[1])):
if n == 0: #Header filae for biomark is 17 lines
continue
else:
dat = line.rstrip().split(',')
sample_name = dat[0] #modify as neeeded
ct = dat[17] #modify as needed
gene = dat[5] #modify as needed
all_genes.append(gene)
all_samples.append(sample_name)
all_genes_set = set(all_genes)
all_samples_set = set(all_samples)
for i in all_samples_set:
d_all_samples[i] = 0
for i in all_genes_set:
d_genes[i] = d_all_samples.copy()
for n, line in enumerate(open(sys.argv[1])):
if n == 0: #Header filae for biomark is 17 lines
continue
else:
dat = line.rstrip().split(',')
sample_name = dat[0] #modify as neeeded
ct = dat[17] #modify as needed
gene = dat[5] #modify as needed
d_genes[gene][sample_name] = ct
sample_list = sorted(list(d_all_samples.keys()))
gene_list = sorted(list(d_genes.keys()))
# Writing File
print('\t' + '\t'.join(sample_list))
for n, x in enumerate(gene_list):
print(gene_list[n], end = ''),
for m, y in enumerate(sample_list):
print('\t' + d_genes[x][y], end = '')
print('')