1 # This is -*-Perl-*- code#
2 # Bioperl Test Harness Script for Modules
5 use vars qw($NUMTESTS $DEBUG $ERROR);
7 $DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
10 # to handle systems with no installed Test module
11 # we include the t dir (where a copy of Test.pm is located)
13 eval { require Test; };
20 plan tests => $NUMTESTS;
21 eval { require Graph; };
23 warn "Perl's Graph needed for the bioperl-network package, skipping tests";
29 foreach ( $Test::ntest..$NUMTESTS) {
30 skip("Missing dependencies. Skipping tests",1);
34 exit 0 if $ERROR == 1;
36 require Bio::Network::ProteinNet;
37 require Bio::Network::Interaction;
38 require Bio::Network::Node;
40 require Bio::Annotation::Collection;
41 require Bio::Annotation::OntologyTerm;
44 $verbose = 1 if $DEBUG;
48 my $g = Bio::Network::ProteinNet->new();
50 my $seq1 = Bio::Seq->new(-seq => "aaaaaaa");
51 my $seq2 = Bio::Seq->new(-seq => "ttttttt");
52 my $seq3 = Bio::Seq->new(-seq => "ccccccc");
54 my $node1 = Bio::Network::Node->new(-protein => $seq1);
55 my $node2 = Bio::Network::Node->new(-protein => [($seq2,$seq3)]);
57 my $interx = Bio::Network::Interaction->new(-weight => 2,
59 $g->add_interaction(-nodes => [($node1,$node2)],
60 -interaction => $interx);
62 $interx = Bio::Network::Interaction->new(-weight => 3,
64 $g->add_interaction(-nodes => [($node1,$node2)],
65 -interaction => $interx);
67 $interx = $g->get_interaction_by_id("A");
69 ok $interx->primary_id, "A";
70 ok $interx->object_id, "A";
71 ok $interx->weight, 2;
72 my @nodes = $interx->nodes;
74 my @proteins = $nodes[0]->proteins;
75 ok $proteins[0]->seq, "aaaaaaa";
76 @proteins = $nodes[1]->proteins;
77 ok $proteins[0]->seq, "ttttttt";
79 my $nodes = $interx->nodes;
84 $interx->primary_id("B");
85 ok $interx->primary_id, "B";
87 ok $interx->weight, 7;
89 # check that Bio::Seq objects are automatically converted to Nodes
91 $interx = Bio::Network::Interaction->new(-weight => 2,
93 $g->add_interaction(-nodes => [($seq1,$seq2)],
94 -interaction => $interx);
96 $interx = $g->get_interaction_by_id("C");
97 ok $interx->primary_id, "C";
99 # add and remove Annotations
101 my $comment = Bio::Annotation::Comment->new;
102 $comment->text("Reliable");
103 my $coll = Bio::Annotation::Collection->new();
104 $coll->add_Annotation('comment',$comment);
105 ok $interx->annotation($coll);
106 my @anns = $coll->get_Annotations('comment');
108 ok $anns[0]->as_text, "Comment: Reliable";
109 my @keys = $coll->get_all_annotation_keys;
110 ok $keys[0],'comment';
111 $coll->remove_Annotations('comment');
112 @anns = $coll->get_Annotations('comment');
115 my $term = Bio::Annotation::OntologyTerm->new
117 -name => "N-acetylgalactosaminyltransferase",
119 -identifier => "000045",
120 -definition => "Catalysis of galactossaminylation",
122 -tagname => "cellular component");
123 $coll->add_Annotation($term);
124 ok $interx->annotation($coll);