annotate microsatcompat.py @ 4:d74dc58cbd53 draft

Uploaded
author arkarachai-fungtammasan
date Sat, 22 Aug 2015 12:12:55 -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 # remove all read that have unmatch microsat
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
3 # check only one line at a time
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
4 def complement_base(read):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
5 collect=''
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
6 for i in read:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
7 if i.upper()=='A':
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
8 collect+='T'
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
9 elif i.upper()=='T':
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
10 collect+='A'
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
11 elif i.upper()=='C':
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
12 collect+='G'
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
13 elif i.upper()=='G':
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
14 collect+='C'
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
15 return collect
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
16
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
17 def makeallpossible(read):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
18 collect=[]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
19 for i in range(len(read)):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
20 tmp= read[i:]+read[:i]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
21 collect.append(tmp)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
22 collect.append(complement_base(tmp))
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
23 return collect
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
24
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
25
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
26 fd=open(sys.argv[1])
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
27 lines=fd.xreadlines()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
28 firstcolumn=int(sys.argv[2])-1 #4
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
29 secondcolumn=int(sys.argv[3])-1 # 10
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
30 for line in lines:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
31 temp=line.strip().split('\t')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
32 temp=filter(None,temp)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
33 micro1=temp[firstcolumn]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
34 micro2=temp[secondcolumn]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
35 if micro1 in makeallpossible(micro2):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
36 print line.strip()