-
Notifications
You must be signed in to change notification settings - Fork 15
/
fasta-nsplit.pl
executable file
·50 lines (49 loc) · 1.15 KB
/
fasta-nsplit.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
#!/usr/bin/perl
use warnings;
use strict;
my $seq = "";
my $shortSeqID = "";
my $seqID = "";
my $keep = 0;
my $cumLength = 0;
while(<>){
chomp;
if(/^>((.+?)( .*?\s*)?)$/){
my $newID = $1;
my $newShortID = $2;
if($seq){
my $inc = 0;
while($seq =~ s/(NNNN+)(.*)//){
my $nStretch = $1;
my $newSeq = $2;
printf(">%s.%s\n%s\n", $seqID, $inc++, $seq) if ($seq);
$cumLength += length($seq);
printf(STDERR "%s\t%d\t%d\n", $shortSeqID, $cumLength,
$cumLength + length($nStretch));
$cumLength += length($nStretch);
$seq = $newSeq;
}
printf(">%s\n%s\n", $seqID, $seq) if ($seq);
}
$seq = "";
$shortSeqID = $newShortID;
$seqID = $newID;
$cumLength = 0;
} else {
$seq .= $_;
}
}
if($seq){
my $inc = 0;
while($seq =~ s/(NNNN+)(.*)//){
my $nStretch = $1;
my $newSeq = $2;
printf(">%s.%s\n%s\n", $seqID, $inc++, $seq) if ($seq);
$cumLength += length($seq);
printf(STDERR "%s\t%d\t%d\n", $shortSeqID, $cumLength,
$cumLength + length($nStretch));
$cumLength += length($nStretch);
$seq = $newSeq;
}
printf(">%s\n%s\n", $seqID, $seq) if ($seq);
}