File: t060oboformat2.t

package info (click to toggle)
libgo-perl 0.15-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,112 kB
  • sloc: perl: 13,147; sh: 21; makefile: 7
file content (142 lines) | stat: -rw-r--r-- 3,784 bytes parent folder | download | duplicates (8)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/local/bin/perl -w

use lib '.';

use constant NUMTESTS => 12*3;
BEGIN {
    eval { require Test; };
    use Test;    
    plan tests => NUMTESTS;
}
# All tests must be run from the software directory;
# make sure we are getting the modules from here:
use strict;
use GO::Parser;

eval {
    require "XML/Parser/PerlSAX.pm";
};
if ($@) {
    for (1..NUMTESTS) {
        skip("XML::Parser::PerlSAX not installed",1);
    }
    exit 0;
}

# ----- REQUIREMENTS -----

# make sure synonums etc are parsed
# ------------------------

my $f = shift @ARGV || "./t/data/go-truncated.obo";
check_file($f);
$f = cvt($f, 'obo_text', 'obo_xml');
check_file($f);
$f = cvt($f, 'obo_xml', 'obo_text');
check_file($f);

exit 0;


sub check_file {
    my $f = shift;

    my $parser = new GO::Parser ({ # format=>'obo_text',
                                  handler=>'obj'});
    $parser->handler->add_root;
    ok(1);
    print "Parsing: $f\n";
    $parser->parse ($f);
    ok(1);
    my $graph = $parser->handler->g;
    my $terms = $graph->find_roots;
    foreach my $term (@$terms) {
        printf "ROOT: %s\n", $term->name;
    }
    $terms = $graph->get_all_nodes;
    my $t = 0;
    my $t2 = 0;
    my $n_obs = 0;
    my $n_syns = 0;
    my $n_exact_syns = 0;
    my $n_alt_ids = 0;
    my $n_xrefs = 0;
    my $n_def_xrefs = 0;
    my $n_defs = 0;
    my $n_comments = 0;
    printf "TERMS: %d\n", scalar(@$terms);
    #ok(@$terms == 97);
    foreach my $term (@$terms) {
        my $syns = $term->synonym_list || [];
        if (@$syns) {
            printf "SYNS:%s\n", join('|',@$syns);
            $n_syns += @$syns;
        }
        my $exact_syns = $term->synonyms_by_type('exact') || [];
        if (@$exact_syns) {
            printf "EXACT SYNS:%s\n", join('|',@$exact_syns);
            $n_exact_syns += @$exact_syns;
        }
        $n_alt_ids += @{$term->alt_id_list};
        my $xrefs = $term->dbxref_list || [];
        if (@$xrefs) {
            printf "XREFS:%s\n", join('|',map {$_->as_str} @$xrefs);
            $n_xrefs += @$xrefs;
        }
        my $comment = $term->comment;
        if ($comment) {
            printf "COMMENT:%s\n", $comment;
            $n_comments++;
        }
        my $def = $term->definition;
        if ($def) {
            my $xrefs = $term->definition_dbxref_list;
            printf "DEFXREFS:%s\n", join('|', map {$_->as_str} @$xrefs);
            $n_def_xrefs += @$xrefs;
            $n_defs++;
        }
        $n_obs ++ if $term->is_obsolete;
        my $rels = $graph->get_relationships($term->acc);
        $t2 += @$rels;
        $t+= @{$graph->get_parent_relationships($term->acc)};
            foreach my $rel (@$rels) {
        	printf "EDGE|%s|%s|%s\n",
        	  $rel->subject_acc,
        	    $rel->object_acc,
        	      $rel->type;
            }
    }
    printf "total defs:%s\n", $n_defs;
    printf "total def xrefs:%s\n", $n_def_xrefs;
    printf "total xrefs:%s\n", $n_xrefs;
    printf "total comments:%s\n", $n_comments;
    printf "total syns:%s\n", $n_syns;
    printf "total EXACT syns:%s\n", $n_exact_syns;
    printf "total obs:%s\n", $n_obs;
    printf "total parent rels:%s\n", $t;
    printf "total (both ways):%s\n", $t2;
    ok($n_defs,  27);
    ok($n_xrefs,  2);
    ok($n_def_xrefs,  42);
    ok($n_comments,  2);
    ok($n_syns,  12);
    ok($n_exact_syns,  1);
    ok($n_obs,  1);
    ok($n_alt_ids,  1);
    ok($t, 37);
    ok($t2, 64);              # trailing rels counted only once
}

sub cvt {
    my $f = shift;
    my ($from, $to) = @_;
    print "$f from:$from to:$to\n";

    my $parser = new GO::Parser ({format=>$from,
				  handler=>$to});
    my $outf = "$f.$to";
    unlink $outf if -f $outf;
    $parser->handler->file($outf);
    $parser->parse($f);
    return $outf;
}