-
Notifications
You must be signed in to change notification settings - Fork 0
/
Illumina_MySeq_16SAmplicon_analysis.pl
executable file
·285 lines (215 loc) · 8.93 KB
/
Illumina_MySeq_16SAmplicon_analysis.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env perl
use strict;
use warnings;
#--INCLUDE PACKAGES-----------------------------------------------------------
use IO::String;
use Cwd;
#use substr;
#-----------------------------------------------------------------------------
#----SUBROUTINES--------------------------------------------------------------
#-----------------------------------------------------------------------------
sub get_file_data
{
my ($file_name) = @_;
my @file_content;
open (PROTEINFILE, $file_name);
@file_content = <PROTEINFILE>;
close PROTEINFILE;
return @file_content;
} # end of subroutine get_file_data;
sub WriteArrayToFile
{
my ($filename, @in) = @_;
my $a = join (@in, "\n");
open (OUTFILE, ">$filename");
foreach my $a (@in)
{
print OUTFILE $a;
print OUTFILE "\n";
}
close (OUTFILE);
}
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
my $ForwardReads = $ARGV[0];
my $ReverseReads = $ARGV[1];
my $ResultDirectory = $ARGV[2];
if (not defined $ARGV[2] ) {
$ResultDirectory = cwd();
}
system ("mkdir ".$ResultDirectory."/temp/");
#-----------------------------------------------------------------------------
#-join reads------------------------------------------------------------------
#-----------------------------------------------------------------------------
my $join_filename = $ResultDirectory."/temp/".substr($ForwardReads,0,10);
my $confstring = "fastq-join ".$ForwardReads." ".$ReverseReads." -o ".$join_filename;
printf "\n\n".$confstring."\n\n";
system ($confstring);
#-----------------------------------------------------------------------------
#-trim to Q30-----------------------------------------------------------------
#-----------------------------------------------------------------------------
my $join_filename_q30 = $ResultDirectory."/temp/".substr($ForwardReads,0,10).".q30.fastq";
$confstring = "read_fastq -e base_33 -i ".$join_filename."join | trim_seq -m 30 | write_fastq -o ".$join_filename_q30." -x\n";
printf $confstring."\n\n";
system ($confstring);
#-----------------------------------------------------------------------------
#-converto fasta-----------------------------------------------------------------
#-----------------------------------------------------------------------------
my $join_filename_q30_fasta =$join_filename_q30;
chop ($join_filename_q30_fasta);
$join_filename_q30_fasta = $join_filename_q30_fasta."a";
$confstring = "read_fastq -e base_33 -i ".$join_filename_q30." | write_fasta -o ".$join_filename_q30_fasta." -x";
printf $confstring."\n\n";
system ($confstring);
#-----------------------------------------------------------------------------
#-find out which barcodes are prsent -----------------------------------------
#-----------------------------------------------------------------------------
$confstring = "perl /opt/local/scripts/create_mapping_de_novo.pl ".$join_filename_q30_fasta;
printf $confstring."\n\n";
system ($confstring);
my @bacrodes = get_file_data ($ResultDirectory."/temp/"."detected.barcodes"); chomp (@bacrodes);
#-----------------------------------------------------------------------------
#-trim to barcodes on forward side -------------------------------------------
#-----------------------------------------------------------------------------
my @ftemp;
my @rtemp;
my @ttemp;
my $seqs_trimmed = 0;
my $barcode_not_found =0;
my $seqs_barcode_f_direction =0;
my @alltags;
open my $FILEA, "< $join_filename_q30_fasta";
while (<$FILEA>)
{
my $lineA = $_;
$_ = <$FILEA>;
my $lineB = $_;
my $found_barcode =0;
my $posl=-1;
#printf "\n\n".$lineB."\n";
foreach my $tag (@bacrodes)
{
# chomp($tag);
if ($found_barcode == 0)
{
if (index ($lineB, $tag) != -1)
{
$found_barcode =1;
push(@alltags,$tag);
$posl = index ($lineB, $tag);
if ($posl > 0)
{
$lineB = substr($lineB,$posl);
$seqs_trimmed =$seqs_trimmed +1;
}
}
} else {last;}
}
if ($found_barcode > 0)
{
# $lineA =~ s/-/:/g;$lineA =~ s/ /:/g;
push (@ftemp, $lineA);
push (@ftemp, $lineB);
$found_barcode =0;
$seqs_barcode_f_direction=$seqs_barcode_f_direction+1;
}
else
{
$barcode_not_found = $barcode_not_found +1;
$found_barcode =0;
# $lineA =~ s/-/:/g;$lineA =~ s/ /:/g;
push (@ttemp, $lineA);
push (@ttemp, $lineB);
}
}
close $FILEA;
printf "Number of seqeunces trimmed in forward direction:".$seqs_trimmed."\n\n";
printf "Number of sequences without barcode in forward direction:".$barcode_not_found."\n\n";
printf "Number of sequences found with barcode in forward direction:".$seqs_barcode_f_direction."\n\n";
chomp (@ftemp); chomp (@ttemp);
WriteArrayToFile($ResultDirectory."/temp/"."ftemp.fasta",@ftemp);
WriteArrayToFile($ResultDirectory."/temp/"."ttemp.fasta",@ttemp);
#-----------------------------------------------------------------------------
#-lets try the reverse side -------------------------------------------
#-----------------------------------------------------------------------------
my $seqs_barcode_r_direction =0;
$barcode_not_found =0;
my $join_filename_q30_fasta_r = $join_filename_q30.".r.fasta";
#$confstring = "fastx_reverse_complement -i ".$join_filename_q30_fasta." -o ".$join_filename_q30_fasta_r;
$confstring = "fastx_reverse_complement -i ".$ResultDirectory."/temp/ttemp.fasta -o ".$join_filename_q30_fasta_r;
printf $confstring."\n\n";
system ($confstring);
open $FILEA, "< $join_filename_q30_fasta_r";
while (<$FILEA>)
{
my $lineA = $_;
$_ = <$FILEA>;
my $lineB = $_;
my $found_barcode =0;
my $posl;
foreach my $tag (@bacrodes)
{
# chomp($tag);
if ($found_barcode == 0)
{
if (index ($lineB, $tag) != -1)
{
$found_barcode =1;
push(@alltags,$tag);
$posl = index ($lineB, $tag);
if ($posl > 0)
{
$lineB = substr($lineB,$posl);
$seqs_trimmed =$seqs_trimmed +1;
}
}
} else {last;}
}
if ($found_barcode > 0)
{
push (@rtemp, $lineA);
push (@rtemp, $lineB);
$found_barcode =0;
$seqs_barcode_r_direction=$seqs_barcode_r_direction+1;
}
else
{
$barcode_not_found = $barcode_not_found +1;
$found_barcode =0;
}
}
close $FILEA;
printf "Number of seqeunces trimmed in reverse direction:".$seqs_trimmed."\n\n";
printf "Number of sequences without barcode in reverse direction:".$barcode_not_found."\n\n";
printf "Number of sequences found with barcode in reverse direction:".$seqs_barcode_r_direction."\n\n";
chomp (@rtemp);
WriteArrayToFile($ResultDirectory."/temp/"."rtemp.fasta",@rtemp);
#-----------------------------------------------------------------------------
#-create final output file -------------------------------------------
#-----------------------------------------------------------------------------
system ("cat ".$ResultDirectory."/temp/ftemp.fasta ".$ResultDirectory."/temp/rtemp.fasta > ".$ResultDirectory."/".substr($ForwardReads,0,10).".q30.FR.fasta");
#-----------------------------------------------------------------------------
#-cleanup -------------------------------------------
#-----------------------------------------------------------------------------
#system ("rm -rf temp/");
# -------------------------------------------------------------
# Extract your reads and barcodes
# -------------------------------------------------------------
#extract_barcodes.py -f GoM_16S_Sept.fastq -m GoM_Sept_Mapping.txt --attempt_read_reorientation -l 12 -o processed_seqs
# -------------------------------------------------------------
# Split libraries
# -------------------------------------------------------------
#split_libraries_fastq.py -i processed_seqs/reads.fastq -b processed_seqs/barcodes.fastq -m GoM_Sept_Mapping.txt -o processed_seqs/Split_Output/ --barcode_type 12
# -------------------------------------------------------------
# Pick your OTUs
# -------------------------------------------------------------
#wget http://mgmic.oscer.ou.edu/sequence_data/tutorials/qiime_jamie/qiime_parameters_silva111.par
#pick_de_novo_otus.py -i processed_seqs/Split_Output/seqs.fna -o OTUs_silva -p qiime_parameters_silva111.par
# -------------------------------------------------------------
# remove chimeras
# -------------------------------------------------------------
# -------------------------------------------------------------
# Run QIIME core diversity analysis
# -------------------------------------------------------------
#core_diversity_analyses.py -o cdout_silva/ -i OTUs_silva/otu_table.biom -m GoM_Sept_Mapping.txt -t OTUs_silva/rep_set.tre -e 20