-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFasta.split.seq_num.pl
52 lines (47 loc) · 1 KB
/
Fasta.split.seq_num.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
#! perl
use warnings;
use strict;
use Bio::SeqIO;
use File::Basename;
use Cwd qw (abs_path getcwd);
my $fa = shift or die "Need Fasta File\n";
$fa = abs_path($fa);
my $item = shift;
$item //= 10000;
(my $name = basename $fa) =~ s/(.*?)\..*/$1/;
mkdir $name.".split" if ! -e $name.".split";
chdir $name.".split";
my $s_io = Bio::SeqIO -> new (-file => $fa, -format => "fasta");
my $c = 0;
my $d = 1;
my $p_n = 1;
my $p;
my $e_n = 0;
my $s_n = 0;
while(my $s = $s_io -> next_seq){
my $id = $s -> display_id;
my $seq = $s -> seq;
if($item == 1){
open O,'>',"$id.fa";
print O">$id\n$seq\n";
close O;
next;
}
$c += 1;
$p .= ">$id\n$seq\n";
if($c == ($d * $item)){
$e_n = $d * $item;
$s_n = $e_n - $item + 1;
open O,'>',"$name.$s_n-$e_n.fa";
print O $p;
close O;
$p = "";
$d += 1;
}
}
unless($item == 1){
my $last = $e_n + 1;
open O,'>',"$name.$last-$c.fa";
print O $p;
close O;
}