-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaskLowerWithN.pl
74 lines (59 loc) · 1.18 KB
/
maskLowerWithN.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
#!/usr/bin/env perl
=head1 Author
Dinghua Li <[email protected]>
=head1 Usage
maskLowerWithN.pl [options] <in.fa>
=head1 Options
-l min len [15]
=cut
use warnings;
use strict;
use Getopt::Long;
my $min_len = 15;
GetOptions(
"l=i" => \$min_len
);
unless (@ARGV >= 1) {
die `pod2text $0`;
}
my $in;
if ($ARGV[0] eq "-") {
$in = *STDIN;
} elsif ($ARGV[0] =~ /^(\S+)\.gz/) {
open($in, "gzip -cd $ARGV[0] |") or die "cannot open $ARGV[0]";
} else {
open($in, "<", "$ARGV[0]") or die "cannot open $ARGV[0]";
}
close($out_file);
sub split_fa {
my $name = undef;
my @seqs = undef;
while (my $line = <$in>) {
chomp $line;
if ($line =~ /^>/) {
write_seq($name, @seqs) if defined($name);
$name = $line;
@seqs = ();
$seq_size = 0;
} else {
$acc_size += length($line);
push(@seqs, $line);
}
}
write_seq($name, @seqs) if defined($name);
close($in) unless $fa_fn eq "-";
}
sub write_seq {
my ($name, @seqs) = @_;
$acc_size += $seq_size;
if ($acc_size > $chunk_size) {
$acc_size = $seq_size;
$file_idx++;
close($out_file);
open($out_file, ">", $prefix.".".$file_idx);
}
print $out_file $name."\n";
foreach my $seq (@seqs) {
print $out_file $seq."\n";
}
}