[Bio] / FigKernelScripts / svr_metabolic_reconstruction.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/svr_metabolic_reconstruction.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 : olson 1.2 use ANNOserver;
4 :     use Getopt::Long;
5 :     use strict;
6 : parrello 1.1
7 :    
8 :     # This is a SAS Component
9 :    
10 :     =head1 svr_metabolic_reconstruction
11 :    
12 :     Get a metabolic reconstruction from a set of functional roles.
13 :    
14 :     By a metabolic reconstruction we mean a detailed list of subsystems
15 :     that we believe are present in a genome or environmental sample, along
16 :     with the specific variant codes that are attached to occurrences of
17 :     the specified subsystems.
18 :    
19 :     If you have a file with tab-delimited fields in which the last field
20 : parrello 1.3 in each line is a functional assignment, then
21 : parrello 1.1
22 :     svr_metabolic_reconstruction < file > extended.file
23 :    
24 :     will produce a file in which each line contains a functional role that
25 : parrello 1.3 is part of an active subsystem. Note that because each functional assignment
26 :     can contain multiple functional roles, a single incoming assignment can produce
27 :     many such lines. For each such line, two extra columns, the variant code and the
28 :     subsystem, will be added. Input lines corresponding to functional roles not
29 :     placed in active subsystems will be written to STDERR (and will not appear in
30 :     STDOUT).
31 : parrello 1.1
32 :     Thus, if one had a FASTA file of protein sequences from some complete
33 :     genome or environmental sample, then
34 :    
35 :     svr_assign_using_figfams < ProteinSequences | svr_metabolic_reconstruction > reconstruction 2> unplaced.hits
36 :    
37 :     would give you the assignments of function plus the unplaced
38 :     sequences.
39 :    
40 :     =cut
41 :    
42 : olson 1.2 my $show_ids;
43 :     my $url = "";
44 :    
45 :     my $usage = "Usage: metabolic_reconstruction [--id] < file";
46 :    
47 :     my $rc = GetOptions("id" => \$show_ids,
48 :     "url=s" => \$url);
49 :    
50 :     if (!$rc || @ARGV > 0)
51 :     {
52 :     die "$usage\n";
53 :     }
54 : parrello 1.1
55 : olson 1.2 my $ss = ANNOserver->new(url => $url);
56 : parrello 1.1
57 :     my $file = "/tmp/tmpmetabolic.$$";
58 :    
59 :     open(TMP,">$file") || die "could not open $file: $!";
60 :    
61 :     #spool input file to a tmp file. At the end read it back, look up the role in the results hash, write out.
62 :     #if no hit in teh result hash, write to stderr
63 :    
64 : olson 1.2 my %roles;
65 :    
66 :     while (<STDIN>)
67 :     {
68 :     print TMP $_;
69 :     chomp;
70 :     my @in = split "\t";
71 :     my $last = $#in;
72 :     if ($show_ids)
73 :     {
74 :     $roles{$in[$last]} = $in[$last - 1];
75 :     }
76 :     else
77 :     {
78 :     $roles{$in[$last]} = 0;
79 :     }
80 : parrello 1.1 }
81 : olson 1.2 close TMP;
82 : parrello 1.1
83 : olson 1.2 my @role_id;
84 :     while (my($key, $value) = each %roles) {
85 : parrello 1.1 push (@role_id, [$key, $value]);
86 :     }
87 :    
88 : olson 1.2 my @res = $ss->metabolic_reconstruction(-roles => \@role_id);
89 : parrello 1.1 #returns subsys, role, [id]
90 :    
91 : olson 1.2 my %role_hits;
92 : parrello 1.1 foreach my $r (@res) {
93 : olson 1.2 foreach my $res (@$r) {
94 :     my $ss_var = $res->[0];
95 :     my $role = $res->[1];
96 :     $role_hits{$role} = $ss_var;
97 :     if (defined($show_ids)) {
98 :     my $id = $res->[2];
99 :     $roles{$role} = $id;
100 : parrello 1.1 }
101 : olson 1.2 }
102 : parrello 1.1 }
103 :    
104 :     open(TMP,"<$file") || die "could not open $file: $!";
105 :    
106 :     while (<TMP>) {
107 : olson 1.2 chomp;
108 :     my @in = split "\t";
109 :     my $last = $#in;
110 :     my $role = $in[$last];
111 : parrello 1.1 if ($role_hits{$role}) {
112 : olson 1.2 my $ss_var = $role_hits{$role};
113 :     $ss_var =~ /(^.*:)(.+)/;
114 :     my $ss = $1;
115 :     my $var = $2;
116 :     $ss =~ s/:$//;
117 :     print $_;
118 :     print "\t", $ss, "\t", $var, "\n";
119 : parrello 1.1 } else {
120 : olson 1.2 print STDERR $_, "\n";;
121 : parrello 1.1 }
122 :     }
123 : olson 1.2 close(TMP);
124 : parrello 1.1
125 :     unlink $file;
126 :    
127 :     exit;
128 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3