version increase for final release, improved warning
[bioperl-network.git] / t / IO_dip_tab.t
blobd460ed1fb350f93381d04b1ccff4d327d0b62473
1 # This is -*-Perl-*- code#
2 # Bioperl Test Harness Script for Modules
3 # $Id: protgraph.t,v 1.1 2004/03/13 23:45:32 radams Exp
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 = 16;
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         }
32         unlink "t/data/out.tab" if -e "t/data/out.tab";
35 exit 0 if $ERROR ==  1;
37 require Bio::Network::IO;
39 my $verbose = 0;
40 $verbose = 1 if $DEBUG;
42 ok 1;
45 # read new DIP format
47 my $io = Bio::Network::IO->new(
48     -format => 'dip_tab',
49     -file   => Bio::Root::IO->catfile("t","data","tab4part.tab"));
50 my $g1 = $io->next_network();
51 ok $g1->edges,5;
52 ok $g1->vertices,7;
54 # read old DIP format
56 $io = Bio::Network::IO->new(
57   -format => 'dip_tab',
58   -file   => Bio::Root::IO->catfile("t","data","tab1part.tab"),
59   -threshold => 0.6);
60 ok(defined $io);
61 ok $g1 = $io->next_network();
62 ok my $node = $g1->get_nodes_by_id('PIR:A64696');
63 my @proteins = $node->proteins;
64 ok $proteins[0]->accession_number, 'PIR:A64696';
65 my %ids = $g1->get_ids_by_node($node);
66 my $x = 0;
67 my @ids = qw(A64696 2314583 3053N);
68 for my $k (keys %ids) {
69         ok $ids{$k},$ids[$x++];
72 # test write to filehandle...
74 my $out =  Bio::Network::IO->new(
75   -format => 'dip_tab',
76   -file   => ">". Bio::Root::IO->catfile("t","data","out.tab"));
77 ok(defined $out);
78 ok $out->write_network($g1);
80 # can we round trip, is the output the same as original format?
82 my $io2 = Bio::Network::IO->new(
83   -format   => 'dip_tab',
84   -file     => Bio::Root::IO->catfile("t","data","out.tab"));
85 ok defined $io2;
86 ok      my $g2 = $io2->next_network();
87 ok $node = $g2->get_nodes_by_id('PIR:A64696');
88 @proteins = $node->proteins;
89 ok $proteins[0]->accession_number, 'PIR:A64696';
91 __END__