Update
[bioperl-network.git] / t / Interaction.t
blobe5b780425083047f1775326076bde2aef82864d3
1 # This is -*-Perl-*- code#
2 # Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7         use Bio::Root::Test;
8         test_begin(-tests => 23,
9                            -requires_module => 'Graph');
11         use_ok('Bio::Network::ProteinNet');
12         use_ok('Bio::Network::Interaction');
13         use_ok('Bio::Network::Node');
14         use_ok('Bio::Seq');
15         use_ok('Bio::Annotation::Comment');
16         use_ok('Bio::Annotation::Collection');
17         use_ok('Bio::Annotation::OntologyTerm');
20 my $verbose = test_debug();
22 my $g = Bio::Network::ProteinNet->new();
24 my $seq1 = Bio::Seq->new(-seq => "aaaaaaa");
25 my $seq2 = Bio::Seq->new(-seq => "ttttttt");
26 my $seq3 = Bio::Seq->new(-seq => "ccccccc");
28 my $node1 = Bio::Network::Node->new(-protein => $seq1);
29 my $node2 = Bio::Network::Node->new(-protein => [($seq2,$seq3)]);
31 my $interx = Bio::Network::Interaction->new(-weight => 2,
32                                                                                                                   -id => "A");
33 $g->add_interaction(-nodes => [($node1,$node2)],
34                                                   -interaction => $interx);
36 $interx = Bio::Network::Interaction->new(-weight => 3,
37                                                                                                                 -id => "B");
38 $g->add_interaction(-nodes => [($node1,$node2)],
39                                                   -interaction => $interx);
41 $interx = $g->get_interaction_by_id("A");
43 ok $interx->primary_id eq "A";
44 ok $interx->object_id eq "A";
45 ok $interx->weight == 2;
46 my @nodes = $interx->nodes;
47 ok $#nodes == 1;
48 my @proteins = $nodes[0]->proteins;
49 ok $proteins[0]->seq eq "aaaaaaa";
50 @proteins = $nodes[1]->proteins;
51 ok $proteins[0]->seq eq "ttttttt";
53 my $nodes = $interx->nodes;
54 ok $nodes == 2;
56 # set values
58 $interx->primary_id("B");
59 ok $interx->primary_id eq "B";
60 $interx->weight(7);
61 ok $interx->weight == 7;
63 # check that Bio::Seq objects are automatically converted to Nodes
65 $interx = Bio::Network::Interaction->new(-weight => 2,
66                                                                                                           -id => "C");
67 $g->add_interaction(-nodes => [($seq1,$seq2)],
68                                                   -interaction => $interx);
70 $interx = $g->get_interaction_by_id("C");
71 ok $interx->primary_id eq "C";
73 # add and remove Annotations
75 my $comment = Bio::Annotation::Comment->new;
76 $comment->text("Reliable");
77 my $coll = Bio::Annotation::Collection->new();
78 $coll->add_Annotation('comment',$comment);
79 ok $interx->annotation($coll);
80 my @anns = $coll->get_Annotations('comment');
81 ok scalar @anns == 1;
82 ok $anns[0]->as_text, "Comment: Reliable";
83 my @keys = $coll->get_all_annotation_keys;
84 ok $keys[0] eq 'comment';
85 $coll->remove_Annotations('comment');
86 @anns = $coll->get_Annotations('comment');
87 ok scalar @anns == 0;
89 my $term = Bio::Annotation::OntologyTerm->new
90 (-term => "",
91  -name => "N-acetylgalactosaminyltransferase",
92  -label => "test",
93  -identifier => "000045",
94  -definition => "Catalysis of galactossaminylation",
95  -ontology => "GO",
96  -tagname => "cellular component");
97 $coll->add_Annotation($term);
98 ok $interx->annotation($coll);
101 __END__