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
| #!/usr/bin/perl
use strict;
use warnings;
use Carp qw(confess);
use Getopt::Long;
use Bio::SeqIO;
my ($fasta_file,$out_file);
my ($int,$cut,$len);
my (%hash,%dico);
GetOptions("fasta=s" => \$fasta_file,"seed=i" => \$int ,"out=s" => \$out_file);
#open (OUT, ">"."$input"."_"."$number".".fasta") or die "Cannot open outfile!";
my $in = Bio::SeqIO->new( -file => $fasta_file, '-format' => 'Fasta' );
open(my $out,'>',$out_file) or die "$out_file : $!\n\n";
while ( my $seq = $in->next_seq()){
my $id = $seq->primary_id ;
my $sequence = $seq->seq ;
$len = $seq->length();
my $count = 0;
while($len >= $int){
$cut = substr($sequence,$count);
push(@{$dico{$id}->{'sequence'}}, $cut);
$len--;
$count++;
}
}
foreach my $data (keys(%dico)){
my $i=0;
foreach my $seq (@{$dico{$data}->{'sequence'}}){
print {$out} "$data"."_nb$i"."\n$seq\n";
$i++;
}
} |