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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3