-
Notifications
You must be signed in to change notification settings - Fork 15
/
FastA.split.pl
executable file
·53 lines (41 loc) · 1.09 KB
/
FastA.split.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
#!/usr/bin/env perl
#
# @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
# @update Mar-23-2015
# @license artistic license 2.0
#
use warnings;
use strict;
use Symbol;
my ($file, $base, $outN) = @ARGV;
$outN ||= 12;
($file and $base) or die "
Usage
$0 in_file.fa out_base[ no_files]
in_file.fa Input file in FastA format.
out_base Prefix for the name of the output files. It will
be appended with .<i>.fa, where <i> is a consecutive
number starting in 1.
no_files Number of files to generate. By default: 12.
";
my @outSym = ();
for my $i (1 .. $outN){
$outSym[$i-1] = gensym;
open $outSym[$i-1], ">", "$base.$i.fa" or die "I can not create the file: $base.$i.fa: $!\n";
}
my($i, $seq) = (-1, '');
open FILE, "<", $file or die "I can not read the file: $file: $!\n";
while(my $ln=<FILE>){
if($ln =~ m/^>/){
print { $outSym[$i % $outN] } $seq if $seq;
$i++;
$seq = '';
}
$seq.=$ln;
}
print { $outSym[$i % $outN] } $seq if $seq;
close FILE;
for(my $i=0; $i<$outN; $i++){
close $outSym[$i];
}
print STDERR "Sequences: $i\nFiles: $outN\n";