-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfa-split_on_Ns.pl
executable file
·73 lines (60 loc) · 1.78 KB
/
fa-split_on_Ns.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
#!/usr/bin/env perl
use strict;
use Bio::SeqIO;
my(@Options, $verbose, $sep, $minlen);
setOptions();
my $in = Bio::SeqIO->new(-fh=>\*ARGV, -format=>'Fasta');
my $out = Bio::SeqIO->new(-fh=>\*STDOUT, -format=>'Fasta');
my $nread=0;
my $nwrote=0;
while (my $seq = $in->next_seq) {
print STDERR $seq->display_id,"\n" if $verbose;
$nread++;
if ($seq->seq =~ m/N/i) {
my $count=0;
for my $s (split m/N+/i, $seq->seq) {
next unless length($s) >= $minlen;
$count++;
print STDERR "\t$count\n" if $verbose;
$out->write_seq( Bio::Seq->new(
-id=>$seq->display_id.$sep.$count,
-seq=>$s,
# -desc=>$seq->desc
));
$nwrote++;
}
}
else {
$out->write_seq($seq);
$nwrote++;
}
}
print STDERR "Read $nread, wrote $nwrote sequences.\n";
#----------------------------------------------------------------------
# Option setting routines
sub setOptions {
use Getopt::Long;
@Options = (
{OPT=>"help", VAR=>\&usage, DESC=>"This help"},
{OPT=>"v|verbose+", VAR=>\$verbose, DEFAULT=>0, DESC=>"Verbose"},
{OPT=>"sep=s", VAR=>\$sep, DEFAULT=>'_', DESC=>"Separator string for IDs"},
{OPT=>"l|minlen=i", VAR=>\$minlen, DEFAULT=>31, DESC=>"Minimum length"},
);
# (@ARGV < 2) && (usage());
&GetOptions(map {$_->{OPT}, $_->{VAR}} @Options) || usage();
# Now setup default values.
foreach (@Options) {
if (defined($_->{DEFAULT}) && !defined(${$_->{VAR}})) {
${$_->{VAR}} = $_->{DEFAULT};
}
}
}
sub usage {
print "Usage: $0 [options] scaffolds.fasta > contigs.fasta\n";
foreach (@Options) {
printf " --%-13s %s%s.\n",$_->{OPT},$_->{DESC},
defined($_->{DEFAULT}) ? " (default '$_->{DEFAULT}')" : "";
}
exit(1);
}
#----------------------------------------------------------------------