ModuleBuildBioperl -> Bio::Root::Build
[bioperl-network.git] / t / Interaction.t
blobb30b9ff0c8abdad21298e969b08e6715f473840b
1 # This is -*-Perl-*- code#
2 # Bioperl Test Harness Script for Modules
3 # $Id$
5 use vars qw($NUMTESTS $DEBUG $ERROR);
6 use strict;
7 $DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
9 BEGIN {
10         # to handle systems with no installed Test module
11         # we include the t dir (where a copy of Test.pm is located)
12         # as a fallback
13         eval { require Test; };
14         $ERROR = 0;
15         if ( $@ ) {
16                 use lib 't';
17         }
18         use Test;
19         $NUMTESTS = 17;
20         plan tests => $NUMTESTS;
21         eval { require Graph; };
22         if ($@) {
23                 warn "Perl's Graph needed for the bioperl-network package, skipping tests";
24                 $ERROR = 1;
25         }
28 END {
29         foreach ( $Test::ntest..$NUMTESTS) {
30                 skip("Missing dependencies. Skipping tests",1);
31         }
34 exit 0 if $ERROR ==  1;
36 require Bio::Network::ProteinNet;
37 require Bio::Network::Interaction;
38 require Bio::Network::Node;
39 require Bio::Seq;
40 require Bio::Annotation::Collection;
41 require Bio::Annotation::OntologyTerm;
43 my $verbose = 0;
44 $verbose = 1 if $DEBUG;
46 ok 1;
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,
58                                                                                                                 -id => "A");
59 $g->add_interaction(-nodes => [($node1,$node2)],
60                                                   -interaction => $interx);
62 $interx = Bio::Network::Interaction->new(-weight => 3,
63                                                                                                                 -id => "B");
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;
73 ok $#nodes, 1;
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;
80 ok $nodes, 2;
82 # set values
84 $interx->primary_id("B");
85 ok $interx->primary_id, "B";
86 $interx->weight(7);
87 ok $interx->weight, 7;
89 # check that Bio::Seq objects are automatically converted to Nodes
91 $interx = Bio::Network::Interaction->new(-weight => 2,
92                                                                                                           -id => "C");
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');
107 ok scalar @anns, 1;
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');
113 ok scalar @anns, 0;
115 my $term = Bio::Annotation::OntologyTerm->new
116 (-term => "",
117  -name => "N-acetylgalactosaminyltransferase",
118  -label => "test",
119  -identifier => "000045",
120  -definition => "Catalysis of galactossaminylation",
121  -ontology => "GO",
122  -tagname => "cellular component");
123 $coll->add_Annotation($term);
124 ok $interx->annotation($coll);
127 __END__