forked from ghyao/GAA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaa.pl
executable file
·260 lines (228 loc) · 9.22 KB
/
gaa.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
#!/gsc/opt/perl5-threaded/bin/perl
# gaa.pl Version 1.0
#
# Copyright 2010, 2011 Guohui Yao <gyao at wustl dot edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
use warnings;
use Cwd 'abs_path';
use File::Basename;
use Getopt::Long qw(:config no_ignore_case);
BEGIN{
my $prog_path = abs_path($0);
$prog_path = readlink($0) if readlink($0);
$lib_dir = dirname $prog_path;
push @INC, $lib_dir;
}
use GAA::UniqueGenerator;
use GAA::Simplifier;
use GAA::Filter;
use GAA::Validator;
use GAA::Planner;
use GAA::Builder;
use GAA::Gap;
use GAA::Patch;
use GAA::CE;
#VARIABLE SETUP
use vars qw/%opt/;
my $usage="
-.pl --target|-t <target.fa> : target consensus file, the contig names should be in the format of >Contig1.1
--query|-q <query.fa> : query consensus file, the contig names should be in the format of >Contig1.1
The following options are optional.
--target-qual|-T <target.qual.fa> : target quality file
--query-qual|-Q <query.qual.fa> : query quality file
--target_gap|-g <target gap file> : e.g. gap.txt for Newbler
--query_gap|-G <query gap file> : e.g. gap.txt for Newbler
--match|-m <alignment.psl> : blat target.fa query.fa -fastMap query_vs_target.psl
--pair_status_target|r <454PairStatus.txt> : generated from GSMapper
--pair_status_query|R <454PairStatus.txt> : generated from GSMapper
--ce <ce.psl> : ce status psl file
--output-dir|-o <output_dir=pwd> : default is merged_assembly under current directory
--tip-size|-p <tip_size=90> : tip tolerance
--score-cutoff-lower|-l <score_cutoff_lower=30> : confident unique contig, if score < 30
--score-cutoff-upper|-u <score-cutoff_upper=100> : confident match, if score > 100
--contig-size-cutoff|-s <contig_size_cutoff=100> : keep unique contigs of length > 100
Using -m option would shortcut the alignment step if alignment.psl alread exists.
";
#GATHER INPUT
&GetOptions(
"target|t=s" => \$opt{target},
"query|q=s" => \$opt{query},
"target-qual|T=s" => \$opt{target_qual},
"query-qual|Q=s" => \$opt{query_qual},
"target-gap|g=s" => \$opt{target_gap},
"query-gap|G=s" => \$opt{query_gap},
"match|m=s" => \$opt{match},
"pair_status_target|r=s" => \$opt{pair_status_target},
"pair_status_query|R=s" => \$opt{pair_status_query},
"ce=s" => \$opt{ce},
"output-dir|o=s" => \$opt{output_dir},
"score-cutoff-lower|l=i" => \$opt{score_cutoff_lower},
"score-cutoff-upper|u=i" => \$opt{score_cutoff_upper},
"contig-size-cutoff|s=i" => \$opt{contig_size_cutoff},
"tip-size|p=i" => \$opt{tip_size},
"no-unique|U" => \$opt{no_unique},
"no-simplifier|S" => \$opt{no_simplifier}
);
my $cmdline = join " ", $0, @ARGV;
$cmdline .= " -t $opt{target}" if defined $opt{target};
$cmdline .= " -q $opt{query}" if defined $opt{query};
$cmdline .= " -T $opt{target_qual}" if defined $opt{target_qual};
$cmdline .= " -Q $opt{query_qual}" if defined $opt{query_qual};
$cmdline .= " -g $opt{target_gap}" if defined $opt{target_gap};
$cmdline .= " -G $opt{query_gap}" if defined $opt{query_gap};
$cmdline .= " -m $opt{match}" if defined $opt{match};
$cmdline .= " -r $opt{pair_status_target}" if defined $opt{pair_status_target};
$cmdline .= " -R $opt{pair_status_query}" if defined $opt{pair_status_query};
$cmdline .= " --ce $opt{ce}" if defined $opt{ce};
$cmdline .= " -o $opt{output_dir}" if defined $opt{output_dir};
$cmdline .= " -l $opt{score_cutoff_lower}" if defined $opt{score_cutoff_lower};
$cmdline .= " -u $opt{score_cutoff_upper}" if defined $opt{score_cutoff_upper};
$cmdline .= " -s $opt{contig_size_cutoff}" if defined $opt{contig_size_cutoff};
$cmdline .= " -p $opt{tip_size}" if defined $opt{tip_size};
$cmdline .= " -U $opt{no_unique}" if defined $opt{no_unique};
$cmdline .= " -S $opt{no_simplifier}" if defined $opt{no_simplifier};
# Verify input
die "$usage\n" unless defined $opt{target} and defined $opt{query};
die "target file doesn't exist!\n$usage" unless -e $opt{target};
die "query file doesn't exist!\n$usage" unless -e $opt{query};
# Default parameters
$opt{tip_size} = 90 unless defined $opt{tip_size};
$opt{score_cutoff_lower} = 30 unless defined $opt{score_cutoff_lower};
$opt{score_cutoff_upper} = 200 unless defined $opt{score_cutoff_upper};
$opt{contig_size_cutoff} = 100 unless defined $opt{contig_size_cutoff};
$opt{merged_prefix} = basename($opt{target}) . "_n_" . basename($opt{query}); # -.fa -.qual
# Absolute path
$opt{target} = abs_path $opt{target};
$opt{query} = abs_path $opt{query};
$opt{match} = abs_path $opt{match} if defined $opt{match};
$opt{target_qual} = abs_path $opt{target_qual} if defined $opt{target_qual};
$opt{query_qual} = abs_path $opt{query_qual} if defined $opt{query_qual};
$opt{target_gap} = abs_path $opt{target_gap} if defined $opt{target_gap};
$opt{query_gap} = abs_path $opt{query_gap} if defined $opt{query_gap};
$opt{ce} = abs_path $opt{ce} if defined $opt{ce};
$opt{pair_status_target} = abs_path $opt{pair_status_target} if defined $opt{pair_status_target};
$opt{pair_status_query} = abs_path $opt{pair_status_query} if defined $opt{pair_status_query};
# Output directory
$opt{output_dir} = $ENV{'PWD'} . "/merged_assembly" unless defined $opt{output_dir};
`mkdir -p $opt{output_dir}` unless -d $opt{output_dir};
chdir $opt{output_dir};
open LOG, ">log" or die "Cannot write to log file\n";
print LOG $cmdline, "\n";
close LOG;
print STDERR "\n", `date`, ">>> GAA <<<\n\n";
# Get started with Blat Aligner
if(defined $opt{match}){
die "$opt{match} dosn't exist!$usage" unless -e $opt{match};
print STDERR "Escape mapping, proceeding to next step!\n"; }
else{
$opt{match} = "match.psl";
my $blat_cmd = "blat -fastMap $opt{target} $opt{query} $opt{match}";
print STDERR `date`, "$blat_cmd\n";
system $blat_cmd;
die "Blat Failed!\n$usage" unless -e $opt{match};
}
# Simplify
my $simplifier = GAA::Simplifier->new(
match_file => $opt{match},
score_cutoff => $opt{score_cutoff_upper} # get reliable match
);
$simplifier->simplify unless $opt{no_simplifier};
undef $simplifier;
#################################################
# Filter
my $filter = GAA::Filter->new(
match_file => "1match.unique",
target_file => $opt{target},
tip_size => $opt{tip_size}
);
my $merged_track = $filter->filt;
# Validator
my $validator = GAA::Validator->new(
# track_file => "2track",
track => $merged_track,
target_file => $opt{target},
);
my $track = $validator->validate;
# Unique contig generator
my $unique = GAA::UniqueGenerator->new(
match_file => $opt{match},
query_file => $opt{query},
score_cutoff => $opt{score_cutoff_lower},
length_cutoff => $opt{contig_size_cutoff},
# first_scaf => 0,
# unique_file => $opt{merged_prefix}.".unique.fa",
);
my ($unique_scaf, $unique_length) = $unique->generate_unique_scaf_n_length unless $opt{no_unique};
# Planner
my $planner = GAA::Planner->new(
# track_file => "v.track",
track => $track,
target_file => $opt{target},
query_file => $opt{query},
unique_scaf => $unique_scaf
);
my $plan = $planner->generate_plan;
undef $unique;
undef $filter;
undef $planner;
#################################################
# Plan Reviser
if(defined $opt{ce}){
my $patch = GAA::Patch->new(
plan_file => "3floor_plan",
ce_file => $opt{ce},
);
$patch->patch;
undef $patch;
}elsif(defined $opt{pair_status_target} and -e $opt{pair_status_target} and
defined $opt{pair_status_query} and -e $opt{pair_status_query})
{
print STDERR "Run break module: ...\n";
my $ce = GAA::CE->new(
match_file => $opt{match},
pair_status_target => $opt{pair_status_target},
pair_status_query => $opt{pair_status_query}
);
$ce->ce; # output ce.psl
my $patch = GAA::Patch->new(
plan_file => "3floor_plan",
ce_file => "ce.psl",
);
$patch->patch;
undef $patch;
}
# Builder
my $builder = GAA::Builder->new(
plan_file => "3floor_plan",
target_file => $opt{target},
query_file => $opt{query},
target_qual_file => $opt{target_qual},
query_qual_file => $opt{query_qual},
merged_prefix => $opt{merged_prefix}
);
$builder->build;
# Gap
if(defined $opt{target_gap}){
my $gap = GAA::Gap->new(
plan_file => "3floor_plan",
gap_t_file => $opt{target_gap},
target_file => $opt{target},
merged_file => $opt{merged_prefix}.".fa",
qual_file => $opt{merged_prefix}.".qual",
);
$gap->generate_gap;
}