-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsplitup.pl
executable file
·58 lines (50 loc) · 1.56 KB
/
splitup.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
53
54
55
56
57
58
#!/usr/bin/perl
# Script: splitup.pl
# Description: splits each sequence of a single multi-sequence fasta file into multiple single-sequence fasta files
# Author: Steven Ahrendt
# email: [email protected]
# Date: 09.23.2011
############################
## ** bp_dpsplit.pl is standard bioperl implementation
####################################
use warnings;
use strict;
use Bio::Seq;
use Bio::SeqIO;
use Getopt::Long;
#####-----Global Variables-----#####
my $input;
my $size = 1;
my ($help,$verb);
GetOptions ('i|input=s' => \$input,
's|size=s' => \$size,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "Usage: splitup.pl -i fastafile [-s size]\nOutput to directory containing files\n";
die $usage if $help;
die "No input.\n$usage" if (!$input);
#####-----Main-----#####
my $input_db = Bio::SeqIO->new(-file => $input,
-format => 'fasta');
my $seq_no = 0; # counter for number of seqs written to a specific file
my $file_no = 0; # counter for file being written to
my $outdir = "$input\_files/";
system("mkdir $outdir");
my @tmp = split(/\./,$input);
my $ext = pop @tmp;
my $filename = join(".",@tmp);
while(my $seq_obj = $input_db->next_seq)
{
my $ofilename = join(".",$filename,$file_no,$ext);
$ofilename = join("",$outdir,$ofilename);
my $outfile = Bio::SeqIO->new(-file => ">>$ofilename",
-format => 'fasta');
$outfile->write_seq($seq_obj);
$seq_no++;
if($seq_no >= $size)
{
$file_no++;
$seq_no = 0;
}
}
#$seqio_obj->write_seq($seq_obj);