annotate combinedprobforallelecombination.py @ 12:a3113043abb0 draft

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