forked from DaehwanKimLab/centrifuge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentrifuge-RemoveN.pl
executable file
·57 lines (52 loc) · 1011 Bytes
/
centrifuge-RemoveN.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
#!/usr/bin/env perl
use strict ;
use warnings ;
die "usage: a.pl xxx.fa > output.fa" if ( @ARGV == 0 ) ;
my $LINE_WIDTH = 80 ;
my $BUFFER_SIZE = 100000 ;
open FP1, $ARGV[0] ;
my $buffer = "" ;
while ( <FP1> )
{
if ( /^>/ )
{
my $line = $_ ;
if ( $buffer ne "" )
{
my $len = length( $buffer ) ;
for ( my $i = 0 ; $i < $len ; $i += $LINE_WIDTH )
{
print substr( $buffer, $i, $LINE_WIDTH ), "\n" ;
}
$buffer = "" ;
}
print $line ;
}
else
{
chomp ;
tr/nN//d ;
#my $line = uc( $_ ) ;
my $line = $_ ;
$buffer .= $line ;
if ( length( $buffer ) > $BUFFER_SIZE )
{
my $len = length( $buffer ) ;
my $i = 0 ;
for ( $i = 0 ; $i + $LINE_WIDTH - 1 < $len ; $i += $LINE_WIDTH )
{
print substr( $buffer, $i, $LINE_WIDTH ), "\n" ;
}
substr( $buffer, 0, $i, "" ) ;
}
}
}
if ( $buffer ne "" )
{
my $len = length( $buffer ) ;
for ( my $i = 0 ; $i < $len ; $i += $LINE_WIDTH )
{
print substr( $buffer, $i, $LINE_WIDTH ), "\n" ;
}
$buffer = "" ;
}