PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Bio/Pipeline/SQL/NodeAdaptor.pm

https://github.com/bioperl/bioperl-pipeline
Perl | 154 lines | 96 code | 46 blank | 12 comment | 3 complexity | d04ec205ca110b36ff9e8eac1311c3b1 MD5 | raw file
Possible License(s): LGPL-2.0
  1. # $Id: .pm,v 1.51 Fri Jun 07 05:43:37 SGT 2002
  2. # BioPerl module for
  3. #
  4. # Please direct questions and support issues to <bioperl-l@bioperl.org>
  5. #
  6. # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
  7. #
  8. # Copyright Shawn Hoon
  9. #
  10. # You may distribute this module under the same terms as perl itself
  11. # POD documentation - main docs before the code
  12. =head1 NAME
  13. Bio::Pipeline::SQL::NodeAdaptor
  14. =head1 SYNOPSIS
  15. $seqio = Bio::SeqIO->new( '-format' => 'embl' , -file => 'myfile.dat');
  16. $seqobj = $seqio->next_seq();
  17. =head1 DESCRIPTION
  18. Description here.
  19. =head1 EXAMPLES
  20. A simple and fundamental block of code
  21. use Bio::SeqIO;
  22. =head1 FEEDBACK
  23. =head2 Mailing Lists
  24. User feedback is an integral part of the evolution of this and other
  25. Bioperl modules. Send your comments and suggestions preferably to one
  26. of the Bioperl mailing lists. Your participation is much appreciated.
  27. bioperl-l@bioperl.org - General discussion
  28. http://bioperl.org/wiki/Mailing_lists - About the mailing lists
  29. =head2 Support
  30. Please direct usage questions or support issues to the mailing list:
  31. L<bioperl-l@bioperl.org>
  32. rather than to the module maintainer directly. Many experienced and
  33. reponsive experts will be able look at the problem and quickly
  34. address it. Please include a thorough description of the problem
  35. with code and data examples if at all possible.
  36. =head2 Reporting Bugs
  37. Report bugs to the Bioperl bug tracking system to help us keep track
  38. the bugs and their resolution. Bug reports can be submitted via email
  39. or the web:
  40. bioperl-bugs@bioperl.org
  41. http://bio.perl.org/bioperl-bugs/
  42. =head1 AUTHOR - Shawn Hoon
  43. Email shawnh@fugu-sg.org
  44. =head1 APPENDIX
  45. The rest of the documentation details each of the object
  46. methods. Internal methods are usually preceded with a "_".
  47. =cut
  48. package Bio::Pipeline::SQL::NodeAdaptor;
  49. use Bio::Pipeline::Node;
  50. use Bio::Root::Root;
  51. use vars qw(@ISA);
  52. use strict;
  53. @ISA = qw( Bio::Pipeline::SQL::BaseAdaptor);
  54. # Let the code begin...
  55. sub get_nodes_by_group_id {
  56. my ($self,$id) = @_;
  57. my $sth = $self->prepare("SELECT node_id,node_name FROM node WHERE group_id =$id");
  58. my $sth2 = $self->prepare("SELECT distinct(group_id) FROM node where node_id=?");
  59. $sth->execute();
  60. my @nodes;
  61. while(my ($node_id,$node_name) = $sth->fetchrow_array()){
  62. $sth2->execute($node_id);
  63. my $group_ids = $sth2->fetchrow_arrayref; #get the other groups that this node belongs to
  64. my $node = Bio::Pipeline::Node->new('-id'=>$node_id,'-name'=>$node_name,'-current_group'=>$id,'-group_id'=>$group_ids);
  65. push @nodes, $node;
  66. }
  67. return @nodes;
  68. }
  69. sub get_all_nodes {
  70. my ($self) = @_;
  71. my $sth = $self->prepare("SELECT node_id,node_name FROM node GROUP BY node_id");
  72. my $sth2 = $self->prepare("SELECT distinct(group_id) FROM node where node_id=?");
  73. $sth->execute();
  74. my @nodes;
  75. while(my ($node_id,$node_name) = $sth->fetchrow_array()){
  76. $sth2->execute($node_id);
  77. my $group_ids = $sth2->fetchrow_arrayref;
  78. my $node = Bio::Pipeline::Node->new('-id'=>$node_id,'-name'=>$node_name,'-current_group'=>0,'-group_id'=>$group_ids);
  79. push @nodes, $node;
  80. }
  81. return @nodes;
  82. }
  83. sub store {
  84. my ($self, $node) = @_;
  85. if (!defined ($node->id)) {
  86. my $sth = $self->prepare( qq{
  87. INSERT INTO node
  88. SET node_name= ?,
  89. group_id= ? } );
  90. $sth->execute($node->name, $node->current_group);
  91. $sth = $self->prepare( q{
  92. SELECT last_insert_id()
  93. } );
  94. $sth->execute;
  95. my $dbID = ($sth->fetchrow_array)[0];
  96. $node->id( $dbID );
  97. }
  98. else {
  99. my $sth = $self->prepare( qq{
  100. INSERT INTO node
  101. SET node_id= ?,
  102. node_name= ?,
  103. group_id= ? } );
  104. $sth->execute($node->id, $node->name, $node->current_group );
  105. }
  106. return $node->id;
  107. }
  108. 1;