[Bio] / FigKernelScripts / split_fasta.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/split_fasta.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1 #
2 :     # Split a fasta file into chunks of about the same size.
3 :     #
4 :    
5 :     use strict;
6 :     use Getopt::Long::Descriptive;
7 :     use File::Temp;
8 :    
9 :     my($opt, $usage) = describe_options("%c %o fasta-input output-basename size ",
10 :     ["help|h", "show this help message"]);
11 :     print($usage->text), exit 0 if $opt->help;
12 :     die($usage->text) if @ARGV < 1;
13 :    
14 :     my $nr_file = shift;
15 :     my $out_base = shift;
16 :     my $block_size = shift;
17 :    
18 :     open(F, "<", $nr_file) or die "Cannot open $nr_file: $!";
19 :    
20 :     my $out_idx = 1;
21 :     my $out_file = sprintf("$out_base%04d", $out_idx++);
22 :     open(OUT, ">", $out_file) or die "Cannot write $out_file: $!";
23 :     my $cur_size = 0;
24 :    
25 :     while (<F>)
26 :     {
27 :     if (/^>/)
28 :     {
29 :     if ($cur_size > $block_size)
30 :     {
31 :     close(OUT);
32 :     my $out_file = sprintf("$out_base%04d", $out_idx++);
33 :     open(OUT, ">", $out_file) or die "Cannot write $out_file: $!";
34 :     $cur_size = 0;
35 :     }
36 :     }
37 :     print OUT $_;
38 :     $cur_size += length($_);
39 :     }
40 :     close(OUT);
41 :     close(F);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3