script/split-matrix.pl untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 70 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # PODNAME: split-matrix.pl
3 # ABSTRACT: Extract individual gene ALIs from a SCaFoS supermatrix
4  
5 use Modern::Perl '2011';
6 use autodie;
7  
8 use File::Basename;
9 use Getopt::Euclid qw(:vars);
10 use Path::Class qw(dir file);
11 use Smart::Comments;
12  
13 use Bio::MUST::Core;
14 use Bio::MUST::Core::Constants qw(:files);
15 use aliased 'Bio::MUST::Core::Ali';
16 use aliased 'Bio::MUST::Core::SeqMask';
17  
18  
19 ### Gene ALIs extracted from: $ARGV_alifile
20 my $ali = Ali->load($ARGV_alifile);
21 $ali->gapify_seqs;
22  
23 for my $infile (@ARGV_infiles) {
24  
25 ### Processing: $infile
26  
27 # create directory named after filename
28 my ($filename) = fileparse($infile, qr{\.[^.]*}xms);
29 my $dir = dir($filename)->relative;
30 $dir->mkpath();
31  
32 open my $in, '<', $infile;
33  
34 LINE:
35 while (my $line = <$in>) {
36 chomp $line;
37  
38 # skip empty lines and other comment lines
39 next LINE if $line =~ $EMPTY_LINE
40 || $line =~ $COMMENT_LINE;
41  
42 # build mask from gene coordinates
43 my ($gene, $begin, $end) = split /\t+/xms, $line;
44 my $mask = SeqMask->blocks2mask( [ [ $begin, $end ] ] );
45  
46 # extract gene and filter empty seqs
47 my $masked = $mask->filtered_ali($ali);
48 my @seqs = $masked->filter_seqs( sub { $_->nomiss_seq_len > 1 } );
49 my $gene_ali = Ali->new( seqs => \@seqs );
50  
51 ### Output gene ALI in: $gene
52 my $outfile = file($dir, $gene);
53 $gene_ali->store($outfile);
54 }
55 }
56  
57 __END__