annotate combinedprobforallelecombination.py @ 0:20ab85af9505

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