-
Notifications
You must be signed in to change notification settings - Fork 1
/
ORPA.pl
293 lines (259 loc) · 8.14 KB
/
ORPA.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/perl
#
#AUTHOR
#Guiqi Bi :fenghen360@126.com
#VERSION
#ORPA v1.0
#COPYRIGHT & LICENCE
#This script is free software; you can redistribute it and/or modify it.
#This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of merchantability or fitness for a particular purpose.
my $USAGE = "\nusage:
<general>:
perl ORPA.pl -method=[Gblocks|trimAl|BMGE|noisy] <file.aln> <seqdump.txt> <output.fasta> --iqtree
or
perl ORPA.pl -method=[Gblocks|trimAl|BMGE|noisy] <file.aln> <seqdump.txt> <output.fasta>
<large numbers of sequences files>:
perl ORPA.pl -method=[Gblocks|trimAl|BMGE|noisy] <file.aln> <seqdump.txt> <output.fasta> --rmdup
or
perl ORPA.pl -method=[Gblocks|trimAl|BMGE|noisy] <file.aln> <seqdump.txt> <output.fasta> --rmdup --iqtree
parameters:
-method=[Gblocks|trimAl|BMGE|noisy] To choose which program to be used in alignment trimming. (Default: Gblocks).
<file.aln> FASTA alignment file, which is downloaded from NCBI Multiple Sequence Alignment Viewer.
<seqdump.txt> Complete sequence seqdump file,which is download from NCBI BLAST online tool results.
<output.fasta> The final constructed multiple sequence alignment matrix file.
--iqtree Optional, use built-in iqtree to construct phylogenetic tree.
(Built-in Iqtree operating parameters:-st DNA -nt AUTO -bb 1000 -alrt 1000 -m MFP)
--rmdup Remove duplicate reference sequences of merge files with large numbers of sequences.\n";
my $method;
my $aln = $ARGV[1];
my $seqdump = $ARGV[2];
my $out = $ARGV[3];
my $rmdup_out = "rmdup_$out";
my $rmdup;
my $iqtree;
my $character_length;
foreach my $paras (@ARGV){
if ($paras=~/-help/){
print $USAGE;
exit;
}
if ($paras=~/-h/){
print $USAGE;
exit;
}
if ($paras=~/method/){
$method=(split "=", $paras)[1];
}
if ($paras=~/--iqtree/){
$iqtree=1;
}
if ($paras=~/--rmdup/){
$rmdup=1;
}
}
if (!$ARGV[1]){
print $USAGE;
exit;
print "Please provide the raw blast alignment file download from MSA viewer!\n"
}
if (!$ARGV[2]){
print $USAGE;
exit;
print "Please provide the raw sequence file download from blastn results.\n"
}
if (!$ARGV[3]){
print $USAGE;
exit;
print "Please provide the name of output file.\n"
}
print "\n\n\n
********************
****ORPA start!****
********************\n";
#-------------------------------------------------------------------------------------------
my @list = ();
open (LIST,$seqdump) or die "Cannot open file $seqdump: $!\n";
while (<LIST>) {
if (/^>(.*)/) {
my @y = split /\|/, $1;
my @w;
@w = split /\s/, $y[1];
my $id = "$w[0]-$w[1]";
push @list, $id;
}
}
close LIST;
#-------------------------------------------------------------------------------------------
my %seq = ();
my $sid = ();
my $seq_number;
open (IN, $aln) or die "Cannot open file $aln: $!\n";;
while (<IN>) {
if (/^\>(\S+)/) {
$seq_number=0;
$sid = $1;
my @w = split /\|/, $sid;
$sid = $w[1];
}
else {
$_=~tr/BDHIKMNRSVWY/NNNNNNNNNNNN/;
$seq_number++;
my $compare_number2= $_ =~m/\w/g;
my $compare_number1= $seq{$sid}[$seq_number-1]=~m/\w/g;
if($compare_number2 >= $compare_number1){
$seq{$sid}[$seq_number-1] = $_;}
else{next;}
}
}
close IN;
open (OUT, ">$aln.temp") or die "Cannot create file $outs: $!\n";
foreach my $id (keys %seq) {
print OUT ">$id\n";
for my $outseq (0..$seq_number){
print OUT $seq{"$id"}[$outseq];}
}
close OUT;
#-------------------------------------------------------------------------------------------
my @trimed=glob("*.temp");
foreach my $trimed(@trimed){
if("$method" eq "Gblocks"){system("./bin/Gblocks $trimed out");}
if("$method" eq "trimAl"){system("./bin/trimal -in $trimed -out ${trimed}-gb -fasta -htmlout $trimed.html -automated1");}
if("$method" eq "BMGE"){system("java -jar ./bin/BMGE.jar -i $trimed -t DNA -s YES -of ${trimed}-gb -oh $trimed.html");}
if("$method" eq "noisy"){system("./bin/noisy $trimed");}
unlink ("$trimed");
}
#-------------------------------------------------------------------------------------------
if("$method" eq "Gblocks"){
my @gb=glob("*.temp-gb");
foreach my $gb(@gb){
my $delete=0;
open(GB, "<$gb")||die "Can't open $in:$!\n";
open(GBOUT, ">>$gb.out")||die "Can't open $in:$!\n";
while(<GB>){
if(/^>/){print GBOUT "$_";}
elsif(/^\w{10}\s/i){
$delete++;
$_=~s/\s//g;
print GBOUT "$_\n";
}
}
close(GB);
close(GBOUT);
if ($delete==0){unlink("$gb.out");}
unlink ("$gb");
my $temp_name2=$gb.".out";
$temp_name2=~s/temp-gb\.out/fasta/g;
rename("$gb.out","$temp_name2");
}}
if("$method" eq "trimAl"){
my @gb=glob("*.temp-gb");
foreach my $gb(@gb){
my $delete=0;
open(GB, "<$gb")||die "Can't open $in:$!\n";
open(GBOUT, ">>$gb.out")||die "Can't open $in:$!\n";
while(<GB>){
if(/^>/){print GBOUT "$_";}
elsif(/^[A|T|C|G|N|-]+\n/i){
$delete++;
print GBOUT "$_";
}
}
close(GB);
close(GBOUT);
if ($delete==0){unlink("$gb.out");}
unlink ("$gb");
my $temp_name2=$gb;
$temp_name2=~s/temp-gb/fasta/g;
rename("$gb.out","$temp_name2");
}}
if("$method" eq "BMGE"){
my @gb=glob("*.temp-gb");
foreach my $gb(@gb){
my $delete=0;
open(GB, "<$gb")||die "Can't open $in:$!\n";
open(GBOUT, ">>$gb.out")||die "Can't open $in:$!\n";
while(<GB>){
if(/^>/){print GBOUT "$_";}
elsif(/^[A|T|C|G|N|-]+\n/i){
$delete++;
print GBOUT "$_";
}
}
close(GB);
close(GBOUT);
if ($delete==0){unlink("$gb.out");}
unlink ("$gb");
my $temp_name2=$gb;
$temp_name2=~s/temp-gb/fasta/g;
rename("$gb.out","$temp_name2");
}}
if("$method" eq "noisy"){
my @gb=glob("*.fas");
foreach my $gb(@gb){
my $delete=0;
open(GB, "<$gb")||die "Can't open $in:$!\n";
open(GBOUT, ">>$gb.out")||die "Can't open $in:$!\n";
while(<GB>){
if(/^>/){$_=~s/ //g;print GBOUT "$_";}
elsif(/^[A|T|C|G|N|-]+\n/i){
$delete++;
print GBOUT "$_";
}
}
close(GB);
close(GBOUT);
if ($delete==0){unlink("$gb.out");}
unlink ("$gb");
my $temp_name2=$gb;
$temp_name2=~s/_out\.fas/\.fasta/g;
rename("$gb.out","$temp_name2");
}}
#-------------------------------------------------------------------------------------------
my %seq2 = ();
my $sid2 = ();
open (INI, "$aln.fasta") or die "Cannot open file $aln.fasta: $!\n";;
while (<INI>) {
if (/^\>(\S+)/) {
chomp;
$sid2 = $1;
}
else {
$seq2{$sid2} .= $_;
}
}
close INI;
my @query = keys %seq2;
my $end_name;
open (OUT, ">$out") or die "Cannot create file $outs: $!\n";
foreach my $id (@list) {
my @new= split /-/,$id;
if($new[0]=~m/Query/){print OUT ">$new[1]\n";}
print OUT $seq2{"$new[0]"};
}
close OUT;
unlink ("$aln.fasta");
if (defined $rmdup){
system("./bin/seqkit rmdup -n $out -o $rmdup_out");
system("rm $out ");
system("mv $rmdup_out $out");
}
if (defined $iqtree){
my $iqtree_dir=$out."_iqtree_results";
warn "Constructed ML tree by iqtree\nPlease check results in the dir $iqtree_dir\n";
system("mkdir $iqtree_dir");
system("cp $out $iqtree_dir/");
system("./bin/iqtree -s $iqtree_dir/$out -st DNA -nt AUTO -bb 1000 -alrt 1000 -m MFP |tee iqtree.log");
}
open(CAN,"$out")||die "Can'not open $out file\n";
my $count=0;
my $can_all;
while (<CAN>) {
if($count==2){last;}
if($_=~/>/){$count++;next;}
else{chomp;$can_all.=$_;}
}
$character_length=length($can_all);
close(CAN);
print "The extracted alignments were writen in $out\n";
print "\nThe length of alignment is $character_length bp\n\n";
print "ORPA DATA PREPRATION COMPLETED! ENJOY IT!!\n\n\n";