annotate pair_fetch_DNA_ff.py @ 7:3c05abb4452e default tip

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