annotate pair_fetch_DNA_ff.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 #!/usr/bin/env python
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
2 # pair_fetch_DNA_ff.py
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
3 # Function: filter microsat and flanking region by quality score;
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
4 # remove read with any base that has lower quality score than "quality_require" within "flanking_base" and convert from snoope to fastq
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
5 # Note that require flanking length need to be screen by Bob snoope script first
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
6
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
7 # Author: Arkarachai Fungtammasan
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
8 # Version 1.0.0 (15 July 2012)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
9 # Input format: length_of_repeat[0] left_flank_length[1] right_flank_length[2] repeat_motif[3] hamming_distance[4] read_name[5] read_sequence[6] read_quality[7]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
10 # Output format: two fastq file. First file contain left flank. Second file contain right flank.
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
11 # Command: python pair_fetch_DNA_ff.py input.txt
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
12
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
13 import sys
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
14 from galaxy import eggs
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
15
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
16 def stop_err(msg):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
17 sys.stderr.write(msg)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
18 sys.exit()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
19
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
20 # read file name
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
21
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
22
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
23
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
24 filename=sys.argv[1]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
25 L_filename=sys.argv[2]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
26 R_filename=sys.argv[3]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
27 quality_require=sys.argv[4]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
28 flanking_base=sys.argv[5]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
29 try:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
30 quality_require=int(quality_require)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
31 flanking_base=int(flanking_base)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
32 except Exception, eee:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
33 print eee
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
34 stop_err("Quality score cutoff and Length of flanking regions that require quality screening must be integer")
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
35
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
36 fd=open(filename)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
37 fdd1=open(L_filename,'w')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
38 fdd2=open(R_filename,'w')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
39 lines=fd.xreadlines()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
40 for line in lines:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
41 temp=line.strip().split('\t')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
42 temp=filter(None,temp)
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
43 #get index
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
44 left_flank=(0,int(temp[1]))
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
45 microsat=(int(temp[1]),int(temp[1])+int(temp[0]))
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
46 right_flank=(int(temp[1])+int(temp[0]),int(temp[1])+int(temp[0])+int(temp[2]))
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
47 flag=0
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
48 #filter length of left and right flank
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
49 if (right_flank[1]-right_flank[0])<flanking_base:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
50 continue
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
51 if (left_flank[1]-left_flank[0])<flanking_base:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
52 continue
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
53 #filter quality score
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
54 for i in temp[7][microsat[0]-flanking_base:microsat[1]+flanking_base]:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
55 if ord(i)<(quality_require+33):
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
56 flag=1
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
57 else:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
58 flag=flag
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
59 #print out to seperated files
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
60 if flag ==0:
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
61 newname= temp[5]##+'_'+temp[3]+'_'+temp[0]
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
62 fdd1.writelines('@'+newname+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
63 fdd2.writelines('@'+newname+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
64 fdd1.writelines(temp[6][left_flank[0]:left_flank[1]]+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
65 fdd2.writelines(temp[6][right_flank[0]:right_flank[1]]+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
66 fdd1.writelines('+'+newname+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
67 fdd2.writelines('+'+newname+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
68 fdd1.writelines(temp[7][left_flank[0]:left_flank[1]]+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
69 fdd2.writelines(temp[7][right_flank[0]:right_flank[1]]+'\n')
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
70
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
71 fd.close()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
72 fdd1.close()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
73 fdd2.close()
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
74
07588b899c13 Uploaded
arkarachai-fungtammasan
parents:
diff changeset
75