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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3