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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3