[Bio] / FigKernelPackages / NRTools.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/NRTools.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1 #
2 :     # Tools for dealing with nonredundant databases - finding sources, building NR, etc.
3 :     #
4 :    
5 :     package NRTools;
6 :    
7 : olson 1.2 use strict;
8 :    
9 : olson 1.1 use base qw(Exporter);
10 :     use vars qw(@EXPORT);
11 :    
12 : olson 1.2 eval {
13 :     require Job48;
14 :     import Job48;
15 :     };
16 :    
17 :     @EXPORT = qw(scan_NR_dir scan_seed_dir scan_rast_jobs);
18 : olson 1.1
19 :    
20 :     =head3 scan_NR_dir()
21 :    
22 :     usage: scan_NR_dir(\%nr_hash, $dirname)
23 :    
24 :     Scan a directory containing SEED-formatted NR directories, and fill in
25 :     %nr_hash with entries of the form $nr_hash->{name} = { name => dirname, path => full path to NR dir, size => size of fasta file}
26 :    
27 :     =cut
28 :    
29 :     sub scan_NR_dir
30 :     {
31 : olson 1.2 my($nr_hash, $dir, $options) = @_;
32 : olson 1.1
33 :     my $dh = new DirHandle($dir);
34 :     while (defined($_ = $dh->read()))
35 :     {
36 :     next if /^\./;
37 : olson 1.4 next if $_ eq 'SEED'; # Ignore the export of SEED data that lives here.
38 :    
39 : olson 1.2 next if $options->{skip} and /$options->{skip}/;
40 : olson 1.1 my $path = "$dir/$_";
41 :     my $fasta = "$path/fasta";
42 :     if (-f $fasta)
43 :     {
44 :     if (! -f "$path/assigned_functions")
45 :     {
46 :     warn "NR directory $path missing assigned_functions\n";
47 :     }
48 :     if (! -f "$path/org.table")
49 :     {
50 :     warn "NR directory $path missing org.table\n";
51 :     }
52 :     $nr_hash->{$_} = { type => "NR", name => $_, path => $path, fasta_path => $fasta, size => -s $fasta };
53 :     }
54 :     }
55 :     $dh->close();
56 :     }
57 :    
58 :     =head3 scan_seed_dir()
59 :    
60 :     usage: @fasta = scan_seed_dir(\%nr_hash, dirname)
61 :    
62 :     Scan a SEED organism directory, creating entries as in scan_NR_dir.
63 :    
64 :     =cut
65 :    
66 :     sub scan_seed_dir
67 :     {
68 :     my($nr_hash, $dir, $opts) = @_;
69 :    
70 :     my $dh = new DirHandle($dir);
71 :     my $n = 0;
72 :     while ($_ = $dh->read())
73 :     {
74 :     next if /^\./;
75 :     #next if /^9999999.\d+$/;
76 :    
77 :     #
78 :     # Strip environmental sequences.
79 :     #
80 :     # c.f. seed-tech mail thread of 2/8/2007 for discusson on the rationale of the following
81 :     # logic.
82 :     #
83 :     # next if $fig->is_environmental($_);
84 :     next if /^4{7}/ or /^9{7}/;
85 :    
86 :     my $path = "$dir/$_";
87 :    
88 :     next unless -d $path;
89 :     next if (-e "$path/DELETED");
90 :    
91 :     my $fasta = "$path/Features/peg/fasta";
92 :     if (-f $fasta)
93 :     {
94 :     $nr_hash->{$_} = { type => "seed_org", name => $_, path => $path,
95 :     fasta_path => $fasta, size => -s _ };
96 :     }
97 :     last if $opts->{limit} && $n++ > $opts->{limit};
98 :     }
99 :     $dh->close();
100 :     }
101 :    
102 : olson 1.2 =head3 scan_seed_dir()
103 :    
104 :     usage: @jobs = scan_rast_jobs($dir)
105 :    
106 :     Scan the given RAST job directory, finding all completed jobs that are marked
107 : olson 1.4 with import.candidate nonzero and import.action set to "import".
108 : olson 1.2
109 :     =cut
110 :    
111 :     sub scan_rast_jobs
112 :     {
113 :     my($jobs, $dir) = @_;
114 :    
115 :     my $dh = new DirHandle($dir);
116 :    
117 : olson 1.3 if (!$dh)
118 :     {
119 :     warn "Cannot open directory $dir: $!";
120 :     return;
121 :     }
122 :    
123 : olson 1.2 while (defined($_ = $dh->read()))
124 :     {
125 :     next unless /^\d+$/;
126 :    
127 :     my $job = Job48->new("$dir/$_");
128 :     next unless $job;
129 :     next unless $job->meta->get_metadata("status.final") eq "complete";
130 : olson 1.4 next unless $job->meta->get_metadata("import.candidate") > 0;
131 :     next unless $job->meta->get_metadata("import.action") eq 'import';
132 :     my $stat = $job->meta->get_metadata('import.status');
133 :     next if $stat eq 'computed' or $stat eq 'installed';
134 : olson 1.2
135 :     push(@$jobs, $job);
136 :     }
137 :     }
138 :    
139 : olson 1.1 1;
140 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3