annotate combinedprobforallelecombination.py @ 1:99ec84eb0bab draft default tip

Uploaded
author arkarachai-fungtammasan
date Wed, 01 Apr 2015 17:00:21 -0400
parents 70f8259b0b30
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
1 import sys
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
2 import collections
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
3 import math
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
4 SAMPLINGCOL=11
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
5 ALLELE1COL=7
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
6 ALLELE2COL=8
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
7 SIGNCOL=4
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
8 readprofileCOL=2
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
9 motifCOL=3
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
10 filaname=sys.argv[1]
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
11 fd=open(filaname)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
12 lines=fd.readlines()
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
13 binomialcombine=collections.defaultdict(list)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
14 for line in lines:
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
15 temp=line.strip().split('\t')
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
16 allelelist=[]
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
17 allelelist.append(int(temp[ALLELE1COL-1]))
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
18 allelelist.append(int(temp[ALLELE2COL-1]))
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
19 allelelist.sort()
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
20 #allelelist=map(str,allelelist)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
21 alleleave=str(allelelist[0])+'_'+str(allelelist[1])
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
22 #alleleave=str(sum(allelelist)/2.0)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
23 ##alleleave=str(allelelist[0])+'_'+str(allelelist[1])
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
24 totalcov=len(temp[readprofileCOL-1].split(','))
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
25 motif=temp[motifCOL-1]
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
26 samplingvalue=float(temp[SAMPLINGCOL-1])
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
27 SIGN=1
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
28 binomialcombine[(totalcov,alleleave,motif)].append(SIGN*samplingvalue)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
29 allkeys= binomialcombine.keys()
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
30 allkeys.sort()
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
31 ##print allkeys
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
32 print 'read_depth'+'\t'+'allele'+'\t'+'heterozygous_prob'+'\t'+'motif'
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
33 for key in allkeys:
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
34 ##templist=[str(key[0]),key[1],str(sum(binomialcombine[key])),key[2],str(map(str,(binomialcombine[key])))]
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
35 templist=[str(key[0]),key[1],str(sum(binomialcombine[key])),key[2]]
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
36
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
37 print '\t'.join(templist)
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
38 #print allkeys#,binomialcombine
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
39
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
40
70f8259b0b30 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
41