File: InterProParser.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (104 lines) | stat: -rw-r--r-- 3,179 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*-Perl-*-
## Bioperl Test Harness Script for Modules
## $GNF: projects/gi/symgene/src/perl/seqproc/t/InterProParser.t,v 1.7 2003/02/07 22:05:58 pdimitro Exp $

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

use strict;
my $error;
use lib '..','.','./blib/lib';
use vars qw($NUMTESTS $DEBUG);
$DEBUG = $ENV{'BIOPERLDEBUG'} || 0;

BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    $error = 0;
    if( $@ ) {
        use lib 't';
    }
    use Test; 
    $NUMTESTS = 47;
    plan tests => $NUMTESTS;
    eval { 
	require XML::Parser;	
    };
    if( $@ ) { 	
	print STDERR "XML::Parser not installed. This means that InterPro Ontology Parsing module is not usable. Skipping tests.\n";	
	$error = 1;
    }   
}

END { 
    foreach ( $Test::ntest..$NUMTESTS) {
	skip('Unable to run all of the InterProParser tests (missing XML::Parser)',1);
    }
}

if( $error == 1 ) { 
    exit(0); 
}

require Bio::OntologyIO;
require Bio::Root::IO;

my $io = Bio::Root::IO->new();

ok (1);

my $ipp = Bio::OntologyIO->new( -format => 'interpro',
				-file =>
				$io->catfile('t','data','interpro_short.xml'),
				-ontology_engine => 'simple' );
ok ($ipp);

my $ip;
while(my $ont = $ipp->next_ontology()) {
    # there should be only one ontology
    ok ($ip, undef);
    $ip = $ont;
}
#print $ip->to_string."\n";
my @rt = sort { $a->name cmp $b->name; } $ip->get_root_terms();

# there should be 4 root terms: InterPro Domain, InterPro Family,
# InterPro Repeat, and InterPro PTM (Post Translational Modification)
#
# I added 2 more terms, Active_site and Binding_site. -Juguang
ok (scalar(@rt), 6);

# every InterPro term should have an ontology,
foreach ($ip->get_leaf_terms, @rt) {
    ok ($_->ontology);
    ok ($_->ontology->name, "InterPro",
	"term ".$_->name." not in ontology InterPro");
}

# there are 6 fully instantiated InterPro terms in total, which should be returned as the leafs
ok (scalar($ip->get_leaf_terms()), 8);
# roots and leafs together:
ok (scalar($ip->get_all_terms()), 13);

# descendants and children (synonymous here because of depth 1)
# note that the sort should have placed Domain first and Family second
ok (scalar($ip->get_descendant_terms($rt[2])), 4); # 4 InterPro Domains
ok (scalar($ip->get_child_terms($rt[2])), 4);      # dto.
ok (scalar($ip->get_descendant_terms($rt[3])), 3); # 3 Interpro Family
ok (scalar($ip->get_child_terms($rt[3])), 3);      # dto.

# test for ancestors and parents (synonymous here because of depth 1)
foreach my $t ($ip->get_leaf_terms) {
    # every InterPro term has exactly one parent - namely either 
    # Domain, Family, Repeat, or PTM(Post Transl. Modification)
    if (!($t->identifier eq "Repeat" || $t->identifier eq "PTM" 
        || $t->identifier eq'Active_site' || $t->identifier eq'Binding_site')) {
	ok (scalar($ip->get_parent_terms($t)), 1);
	ok (scalar($ip->get_ancestor_terms($t)), 1);
    }
}

# test for secondary accession map
ok(scalar(keys %{$ipp->secondary_accessions_map}), 2);