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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3