File: centrifuge-RemoveN.pl

package info (click to toggle)
centrifuge 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 11,864 kB
  • sloc: cpp: 51,936; perl: 1,919; python: 1,538; makefile: 618; sh: 352
file content (57 lines) | stat: -rwxr-xr-x 1,011 bytes parent folder | download
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 = "" ;
}