[Bio] / FigKernelScripts / svr_run_RAST_jobs.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/svr_run_RAST_jobs.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1 #!/usr/bin/perl
2 :    
3 :     #
4 :     # This is a SAS Component.
5 :     #
6 :    
7 :     use RASTserver;
8 :     use strict;
9 :     use Data::Dumper;
10 : olson 1.4 use Getopt::Long;
11 : olson 1.1
12 : olson 1.6 my $usage = "Usage: $0 [--determineFamily] [--url server-url] [--nonActive] [--verbose] [--test] username password < contig-id-list\n";
13 : olson 1.4
14 :     my $verbose;
15 : gdpusch 1.3 my $use_test_server = 0;
16 : olson 1.5 my $non_active = 0;
17 :     my $url;
18 : olson 1.6 my $determine_family = 0;
19 : olson 1.5 if (!GetOptions('verbose' => \$verbose,
20 :     "nonActive" => \$non_active,
21 :     "url=s" => \$url,
22 : olson 1.6 "determineFamily" => \$determine_family,
23 : olson 1.5 'test' => \$use_test_server))
24 : olson 1.4 {
25 :     die $usage;
26 : gdpusch 1.3 }
27 : olson 1.4
28 :     @ARGV == 2 or die $usage;
29 : olson 1.1
30 :     my $username = shift;
31 :     my $password = shift;
32 : olson 1.5 my $opts = {};
33 :     if ($url)
34 :     {
35 :     $opts->{-server} = $url;
36 :     }
37 :     if ($use_test_server)
38 :     {
39 :     $opts->{-test} = 1;
40 :     }
41 :     my $rast = RASTserver->new($username, $password, $opts);
42 : olson 1.1
43 :     my @input_ids = <STDIN>;
44 :     chomp @input_ids;
45 :    
46 :     my @job_sets;
47 :     my $redundancies_seen;
48 :    
49 : olson 1.2 my $tmpdir = "/tmp/rast_submit.tmp.$$";
50 :     mkdir $tmpdir;
51 :    
52 : olson 1.1 my %seen;
53 :     for my $id (@input_ids)
54 :     {
55 :     next if $seen{$id};
56 :    
57 :     my $res = $rast->get_contig_ids_in_project_from_entrez({ -contig_id => $id } );
58 :     # print Dumper($res);
59 :     my $project_ids = $res->{ids};
60 :     my $redundancies = $res->{redundancy_report};
61 :    
62 :     if (@$redundancies)
63 :     {
64 :     for my $redundancy (@$redundancies)
65 :     {
66 :     print STDERR join("\t", @$redundancy), "\n";
67 :     $redundancies_seen++;
68 :     }
69 :     }
70 :     else
71 :     {
72 :     push(@job_sets, $project_ids);
73 :     map { $seen{$_} = 1 } @$project_ids;
74 :     }
75 :     }
76 :    
77 :     if ($redundancies_seen)
78 :     {
79 : olson 1.2 die "Not submitting jobs, redundancies were found\n";
80 : olson 1.1 }
81 :    
82 :     #
83 :     # Pull contigs
84 :     #
85 :    
86 :     my @jobs;
87 :    
88 :     my $idx = 1;
89 :     for my $ids (@job_sets)
90 :     {
91 : olson 1.2 print "Retrieve @$ids from Entrez\n";
92 : olson 1.1 my $data = $rast->get_contigs_from_entrez({ -id => $ids });
93 : olson 1.2 my $file= "$tmpdir/data.$idx";
94 : olson 1.1 $idx++;
95 :     open(F, ">", $file) or die "Cannot open $file: $!";
96 :     for my $ent (@$data)
97 :     {
98 :     my $txt = $ent->{contents};
99 :     my $id = $ent->{id};
100 :     $ent->{contents} = '';
101 : olson 1.2 print "Contig information for $id:\n";
102 :     print "\t$_\t$ent->{$_}\n" for keys %$ent;
103 : olson 1.1 print F $txt;
104 :     }
105 :     close(F);
106 :     push(@jobs, { file => $file, data => $data, ids => $ids });
107 :     }
108 :    
109 :     #
110 :     # Submit to RAST. The data hash looks like this:
111 :     # $VAR1 = {
112 :     # 'length' => '16660',
113 :     # 'project' => '15760',
114 :     # 'name' => 'Mycobacterium gilvum PYR-GCK',
115 :     # 'contents' => '',
116 :     # 'id' => 'NC_009341',
117 :     # 'taxonomy_id' => '350054'
118 :     # };
119 :     #
120 :    
121 :     for my $jobdata (@jobs)
122 :     {
123 : olson 1.2 my($file, $data, $ids) = @$jobdata{qw(file data ids)};
124 : olson 1.1
125 :     my @biggest = sort { $b->{length} <=> $a->{length} } @$data;
126 : olson 1.2
127 : olson 1.1 my $biggest = $biggest[0];
128 :    
129 :     my $taxonomy = $biggest->{taxonomy};
130 :    
131 :     my $submit_params = {
132 :     -filetype => 'genbank',
133 :     -taxonomyID => $biggest->{taxonomy_id},
134 :     -domain => $biggest->{domain},
135 :     -organismName => $biggest->{name},
136 :     -file => $file,
137 :     -geneticCode => $biggest->{genetic_code},
138 :     -keepGeneCalls => 0,
139 :     -geneCaller => 'RAST',
140 : olson 1.5 -nonActive => $non_active,
141 : olson 1.6 -determineFamily => $determine_family,
142 : olson 1.1 };
143 :    
144 : olson 1.2 print "Submitting job to RAST for contigs @$ids with these parameters:\n";
145 :     print "\t$_\t$submit_params->{$_}\n" for keys %$submit_params;
146 :    
147 : olson 1.1
148 :     my $res = $rast->submit_RAST_job($submit_params);
149 : olson 1.2
150 :     if ($res->{status} eq 'ok')
151 :     {
152 :     my $job = $res->{job_id};
153 :     print "Successfully submitted job $job\n";
154 :     }
155 :     else
156 :     {
157 :     print "There was an error on submission: $res->{error_msg}\n";
158 :     }
159 : olson 1.1 }
160 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3