[Bio] / FigKernelScripts / p3x-split-families.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/p3x-split-families.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1 #
2 :     # Given a families file, split into per-genus family files.
3 :     #
4 :    
5 :     use strict;
6 :     use Getopt::Long::Descriptive;
7 :     use IO::Handle;
8 :    
9 :     my($opt, $usage) = describe_options("%c %o fam-file output-dir max-id-file",
10 :     ["help|h" => "Show this help message"],
11 :     );
12 :     print($usage->text), exit 0 if $opt->help;
13 :     die($usage->text), if @ARGV != 3;
14 :    
15 :     my $fam_file = shift;
16 :     my $output_dir = shift;
17 :     my $max_id_file = shift;
18 :    
19 :     my %genus_to_fh;
20 :     my %genus_max;
21 :    
22 :     -d $output_dir or die "Output directory $output_dir does not exist\n";
23 :     open(F, "<", $fam_file) or die "Cannot open families file $fam_file: $!\n";
24 :     open(MAX, ">", $max_id_file) or die "Cannot write $max_id_file: $!\n";
25 :    
26 :     while (<F>)
27 :     {
28 :     my($gid, $genus, $num) = /^GF(\d+).*?\t([^\t]+)\t(\d+)$/;
29 :     my $fh = $genus_to_fh{$genus};
30 :     $genus_max{GLOBAL} = $gid if $gid > $genus_max{GLOBAL};
31 :     $genus_max{$genus} = $num if $num > $genus_max{$genus};
32 :     if (!$fh)
33 :     {
34 :     $fh = new IO::Handle;
35 :     open($fh, ">", "$output_dir/$genus") or die "Cannot write $output_dir/$genus: $!";
36 :     $genus_to_fh{$genus} = $fh;
37 :     }
38 :     print $fh $_;
39 :     }
40 :    
41 :     for my $genus (sort keys %genus_to_fh)
42 :     {
43 :     my $fh = $genus_to_fh{$genus};
44 :     close($fh) or warn "Error closing genus file for $genus: $!\n";
45 :     }
46 :    
47 :     for my $genus (sort keys %genus_max)
48 :     {
49 :     print MAX "$genus\t$genus_max{$genus}\n";
50 :     }
51 :     close(MAX);
52 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3