-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsplit_fasta.pl
More file actions
executable file
·45 lines (39 loc) · 886 Bytes
/
split_fasta.pl
File metadata and controls
executable file
·45 lines (39 loc) · 886 Bytes
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
#!usr/bin/perl -w
use strict;
die "Usage: perl $0 [.fa] [#splits] [output prefix]\n" unless (@ARGV == 3);
open (FA, $ARGV[0]) or die "$ARGV[0] $!\n";
my $split = $ARGV[1];
my $seq;
my @raw;
my $line_id = 0;
$/ = ">";
<FA>;
while(<FA>){
chomp;
$line_id ++;
}
close FA;
my $sub = int($line_id / $split) + 1;
print "In total, there are $line_id sequences.\n In each file, there are $sub sequences\n";
my $count_lines = 1;
my $count_files = 1;
open (FA, $ARGV[0]) or die "$ARGV[0] $!\n";
open OUT, ">$ARGV[2].$count_files.fas" or die "$ARGV[2].$count_files.fas $!\n";
<FA>;
while(<FA>){
chomp;
if($count_lines <= $sub){
print OUT ">$_";
$count_lines ++;
}else{
close OUT;
$count_files ++;
$count_lines = 1;
open OUT, ">$ARGV[2].$count_files.fas" or die "$ARGV[2].$count_files.fas $!\n";
print OUT ">$_";
$count_lines ++;
}
}
close FA;
close OUT;
print "DONE!";