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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3