| 1 | #!/usr/bin/env perl | ||
| 2 | # PODNAME: inst-qual-filter.pl | ||
| 3 | # ABSTRACT: Discard low-quality nt seqs in FASTA files (optimized) | ||
| 4 | # CONTRIBUTOR: Valerian LUPO <valerian.lupo@uliege.be> | ||
| 5 | |||
| 6 | use Modern::Perl '2011'; | ||
| 7 | use autodie; | ||
| 8 | |||
| 9 | use Getopt::Euclid qw(:vars); | ||
| 10 | use Smart::Comments; | ||
| 11 | |||
| 12 | use Bio::MUST::Core; | ||
| 13 | use Bio::MUST::Core::Constants qw(:seqtypes); | ||
| 14 | use Bio::MUST::Core::Utils qw(secure_outfile); | ||
| 15 | use aliased 'Bio::MUST::Core::Ali'; | ||
| 16 | |||
| 17 | |||
| 18 | my @bad_seqs; | ||
| 19 | |||
| 20 | my $purity_filter = sub { | ||
| 21 | my $seq = shift; | ||
| 22 | |||
| 23 | # compute purity | ||
| 24 | my $purity = $seq->purity; | ||
| 25 | if ($purity < $ARGV_min_purity) { | ||
| 26 | push @bad_seqs, $seq; | ||
| 27 | return; | ||
| 28 | } | ||
| 29 | |||
| 30 | # store allowed seqs | ||
| 31 | my $str = '>' . $seq->full_id . "\n"; | ||
| 32 | $str .= $seq->wrapped_str; | ||
| 33 | |||
| 34 | return $str; | ||
| 35 | }; | ||
| 36 | |||
| 37 | for my $infile (@ARGV_infiles) { | ||
| 38 | # --out-suffix is required in this script | ||
| 39 | my $outfile = secure_outfile($infile, $ARGV_out_suffix); | ||
| 40 | |||
| 41 | ### Processing: $infile | ||
| 42 | Ali->instant_store( | ||
| 43 | $outfile, { infile => $infile, coderef => $purity_filter } | ||
| 44 | ); | ||
| 45 | } | ||
| 46 | |||
| 47 | if ($ARGV_filter_out) { | ||
| 48 | |||
| 49 | ### Storing filtered seqs in: $ARGV_filter_out | ||
| 50 | my $ali = Ali->new( seqs => \@bad_seqs, guessing => 0 ); | ||
| 51 | $ali->store_fasta($ARGV_filter_out); | ||
| 52 | } | ||
| 53 | |||
| 54 | __END__ |