[Bio] / FigKernelPackages / SAPtutorial.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/SAPtutorial.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6, Mon Aug 10 17:42:33 2009 UTC revision 1.7, Wed Aug 19 17:04:38 2009 UTC
# Line 32  Line 32 
32      use SAPserver;      use SAPserver;
33    
34      my $sapServer = SAPserver->new();      my $sapServer = SAPserver->new();
35      my $resultHash = $sapServer->taxonomy_of({ ids => ['360108.3', '100226.1'],      my $resultHash = $sapServer->taxonomy_of({ -ids => ['360108.3', '100226.1'],
36                                                 format => 'names' });                                                 -format => 'names' });
37      for my $id (keys %$resultHash) {      for my $id (keys %$resultHash) {
38          my $taxonomy = $resultHash->{$id};          my $taxonomy = $resultHash->{$id};
39          print "$id: " . join(" ", @$taxonomy) . "\n";          print "$id: " . join(" ", @$taxonomy) . "\n";
# Line 53  Line 53 
53  than a hash reference. So, for example, the above I<taxonomy_of> call could  than a hash reference. So, for example, the above I<taxonomy_of> call could
54  also be written like this.  also be written like this.
55    
56      my $resultHash = $sapServer->taxonomy_of(ids => ['360108.3', '100226.1'],      my $resultHash = $sapServer->taxonomy_of(-ids => ['360108.3', '100226.1'],
57                                               format => 'names');                                               -format => 'names');
58    
59  =head2 A Simple Example: Genome Taxonomies  =head2 A Simple Example: Genome Taxonomies
60    
# Line 100  Line 100 
100    
101  Now we ask for the representatives and the taxonomies.  Now we ask for the representatives and the taxonomies.
102    
103      my $representativeHash = $sapServer->representative(ids => $genomeIDs);      my $representativeHash = $sapServer->representative(-ids => $genomeIDs);
104      my $taxonomyHash = $sapServer->taxonomy_of(ids => $genomeIDs,      my $taxonomyHash = $sapServer->taxonomy_of(-ids => $genomeIDs,
105                                                 format => 'names');                                                 -format => 'names');
106    
107  Our data is now contained in a pair of hash tables. The following loop  Our data is now contained in a pair of hash tables. The following loop
108  stiches them together to produce the output.  stiches them together to produce the output.
# Line 147  Line 147 
147      use SAPserver;      use SAPserver;
148    
149      my $sapServer = SAPserver->new(singleton => 1);      my $sapServer = SAPserver->new(singleton => 1);
150      my $genomeIDs = $sapServer->all_genomes(complete => 1);      my $genomeIDs = $sapServer->all_genomes(-complete => 1);
151      $genomeIDs = [ keys %$genomeIDs ];      $genomeIDs = [ keys %$genomeIDs ];
152      for my $genomeID (@$genomeIDs) {      for my $genomeID (@$genomeIDs) {
153          my $repID = $sapServer->representative(ids => $genomeID);          my $repID = $sapServer->representative(-ids => $genomeID);
154          my $taxonomy = $sapServer->taxonomy_of(ids => $genomeID,          my $taxonomy = $sapServer->taxonomy_of(-ids => $genomeID,
155                                                 format => 'names');                                                 -format => 'names');
156          # Format the taxonomy string.          # Format the taxonomy string.
157          my $taxonomyString = join(" ", @$taxonomy);          my $taxonomyString = join(" ", @$taxonomy);
158          # Print the result.          # Print the result.
# Line 282  Line 282 
282      # Read all the gene IDs.      # Read all the gene IDs.
283      my @genes = map { chomp; $_ } <STDIN>;      my @genes = map { chomp; $_ } <STDIN>;
284      # Compute the functional roles.      # Compute the functional roles.
285      my $results = $sapServer->ids_to_functions(ids => \@genes, source => 'UniProt');      my $results = $sapServer->ids_to_functions(-ids => \@genes, -source => 'UniProt');
286      # Loop through the genes.      # Loop through the genes.
287      for my $gene (@genes) {      for my $gene (@genes) {
288          # Did we find a result?          # Did we find a result?
# Line 327  Line 327 
327      # Read all the gene IDs.      # Read all the gene IDs.
328      my @genes = map { chomp; $_ } <STDIN>;      my @genes = map { chomp; $_ } <STDIN>;
329      # Compute the functional roles.      # Compute the functional roles.
330      my $results = $sapServer->ids_to_subsystems(ids => \@genes, source => 'UniProt');      my $results = $sapServer->ids_to_subsystems(-ids => \@genes, -source => 'UniProt');
331      # Loop through the genes.      # Loop through the genes.
332      for my $gene (@genes) {      for my $gene (@genes) {
333          # Did we find a result?          # Did we find a result?
# Line 407  Line 407 
407      while (my $genomeID = <STDIN>) {      while (my $genomeID = <STDIN>) {
408          chomp $genomeID;          chomp $genomeID;
409          # Get the subsystems for this genome.          # Get the subsystems for this genome.
410          my $subHash = $sapServer->genomes_to_subsystems(ids => $genomeID);          my $subHash = $sapServer->genomes_to_subsystems(-ids => $genomeID);
411          # The data returned for each genome (and in our case there's only one)          # The data returned for each genome (and in our case there's only one)
412          # includes the subsystem name and the variant code. The following          # includes the subsystem name and the variant code. The following
413          # statement strips away the variant codes, leaving only the subsystem          # statement strips away the variant codes, leaving only the subsystem
414          # names.          # names.
415          my $subList = [ map { $_->[0] } @{$subHash->{$genomeID}} ];          my $subList = [ map { $_->[0] } @{$subHash->{$genomeID}} ];
416          # Ask for the genes in each subsystem, using NCBI identifiers.          # Ask for the genes in each subsystem, using NCBI identifiers.
417          my $roleHashes = $sapServer->ids_in_subsystems(subsystems => $subList,          my $roleHashes = $sapServer->ids_in_subsystems(-subsystems => $subList,
418                                                       genome => $genomeID,                                                         -genome => $genomeID,
419                                                       source => 'NCBI',                                                         -source => 'NCBI',
420                                                       roleForm => 'full');                                                         -roleForm => 'full');
421          # The hash maps each subsystem ID to a hash of roles to lists of feature          # The hash maps each subsystem ID to a hash of roles to lists of feature
422          # IDs. We therefore use three levels of nested loops to produce our          # IDs. We therefore use three levels of nested loops to produce our
423          # output lines. At the top level we have a hash mapping subsystem IDs          # output lines. At the top level we have a hash mapping subsystem IDs
# Line 467  Line 467 
467      while (my $genomeID = <STDIN>) {      while (my $genomeID = <STDIN>) {
468          chomp $genomeID;          chomp $genomeID;
469          # Get the subsystems for this genome.          # Get the subsystems for this genome.
470          my $subHash = $sapServer->genomes_to_subsystems(ids => $genomeID);          my $subHash = $sapServer->genomes_to_subsystems(-ids => $genomeID);
471          # The data returned for each genome (and in our case there's only one)          # The data returned for each genome (and in our case there's only one)
472          # includes the subsystem name and the variant code. The following          # includes the subsystem name and the variant code. The following
473          # statement strips away the variant codes, leaving only the subsystem          # statement strips away the variant codes, leaving only the subsystem
474          # names.          # names.
475          my $subList = [ map { $_->[0] } @{$subHash->{$genomeID}} ];          my $subList = [ map { $_->[0] } @{$subHash->{$genomeID}} ];
476          # Ask for the genes in each subsystem, using NCBI identifiers.          # Ask for the genes in each subsystem, using NCBI identifiers.
477          my $genesHash = $sapServer->ids_in_subsystems(subsystems => $subList,          my $genesHash = $sapServer->ids_in_subsystems(-subsystems => $subList,
478                                                       genome => $genomeID,                                                        -genome => $genomeID,
479                                                       source => 'NCBI',                                                        -source => 'NCBI',
480                                                       roleForm => 'none',                                                        -roleForm => 'none',
481                                                       grouped => 1);                                                        -grouped => 1);
482          # The hash maps each subsystem ID to a comma-delimited list of gene IDs.          # The hash maps each subsystem ID to a comma-delimited list of gene IDs.
483          for my $subsystem (sort keys %$genesHash) {          for my $subsystem (sort keys %$genesHash) {
484              my $genes = $genesHash->{$subsystem};              my $genes = $genesHash->{$subsystem};
# Line 544  Line 544 
544          my ($sapServer, $ssName, $genomeID) = @_;          my ($sapServer, $ssName, $genomeID) = @_;
545          # Because we specify "roleForm => none", we get back one long          # Because we specify "roleForm => none", we get back one long
546          # gene list.          # gene list.
547          my $geneList = $sapServer->ids_in_subsystems(subsystems => $ssName,          my $geneList = $sapServer->ids_in_subsystems(-subsystems => $ssName,
548                                                       genome => $genomeID,                                                       -genome => $genomeID,
549                                                       roleForm => 'none');                                                       -roleForm => 'none');
550          # Convert the gene list to a comma-delimited string.          # Convert the gene list to a comma-delimited string.
551          my $geneString = join(", ", @$geneList);          my $geneString = join(", ", @$geneList);
552          # Get a list of operons.          # Get a list of operons.
553          my $opList = $sapServer->make_runs(groups => $geneString);          my $opList = $sapServer->make_runs(-groups => $geneString);
554          # Loop through the operons.          # Loop through the operons.
555          for my $opString (@$opList) {          for my $opString (@$opList) {
556              # Get the first feature's ID.              # Get the first feature's ID.
557              my ($front) = split /\s*,/, $opString, 2;              my ($front) = split /\s*,/, $opString, 2;
558              # Grab its upstream region. We'll include the operon string as the              # Grab its upstream region. We'll include the operon string as the
559              # comment text.              # comment text.
560              my $fasta = $sapServer->upstream(ids => $front,              my $fasta = $sapServer->upstream(-ids => $front,
561                                               comments => { $front => $opString },                                               -comments => { $front => $opString },
562                                               skipGene => 1);                                               -skipGene => 1);
563              # Print the result.              # Print the result.
564              print "$fasta\n";              print "$fasta\n";
565          }          }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3