GOBO

 view release on metacpan or  search on metacpan

t/parsetest.t  view on Meta::CPAN

my $g_AT1G = $gaf_parser->graph;
ok($g_AT1G);


$gaf_parser = new GOBO::Parsers::GAFParser(fh=>"t/data/128up.gaf");
ok($gaf_parser->has_fh);
$gaf_parser->parse;
my $g2_128up = $gaf_parser->graph;
ok($g2_128up);

is_deeply($g_128up, $g2_128up, "Checking that the GAF parsers returned the same results");

$gaf_parser = new GOBO::Parsers::GAFParser(fh=>new FileHandle("t/data/AT1G49810.gaf") );
ok($gaf_parser->has_fh);
$gaf_parser->parse;
my $g2_AT1G = $gaf_parser->graph;
ok($g2_AT1G);
is_deeply($g_AT1G, $g2_AT1G, "Checking that the GAF parsers returned the same results");


## setting the file using set_file
$gaf_parser->reset_parser;
$gaf_parser = new GOBO::Parsers::GAFParser;
$gaf_parser->set_file("t/data/128up.gaf");
ok($gaf_parser->has_fh, "set_file used to initialize the fh");  #11
$gaf_parser->parse;
undef $g2_128up;
$g2_128up = $gaf_parser->graph;
is_deeply($g_128up, $g2_128up, "set_file: GAF parsers returned the same results"); # 12

my $fh = new FileHandle("t/data/AT1G49810.gaf");
$gaf_parser->reset_parser;
$gaf_parser->set_file($fh);
ok($gaf_parser->has_fh); # 13
$gaf_parser->parse;
undef $g2_AT1G;
$g2_AT1G = $gaf_parser->graph;
is_deeply($g_AT1G, $g2_AT1G, "set_file: GAF parsers returned the same results"); # 14

# using parse_file
$gaf_parser->reset_parser;
$gaf_parser->parse_file(file => new FileHandle("t/data/128up.gaf"));
ok($gaf_parser->has_fh); # 15
undef $g2_128up;
$g2_128up = $gaf_parser->graph;
is_deeply($g_128up, $g2_128up, "parse_file: GAF parsers returned the same results"); # 16

undef $gaf_parser;
$gaf_parser = new GOBO::Parsers::GAFParser;
#$gaf_parser->parse_file(file => "t/data/AT1G49810.gaf");
$gaf_parser->parse_file("t/data/AT1G49810.gaf");
ok($gaf_parser->has_fh); # 17
undef $g2_AT1G;
$g2_AT1G = $gaf_parser->graph;
is_deeply($g_AT1G, $g2_AT1G, "parse_file: GAF parsers returned the same results"); # 18


## testing the OBO parsers...

my $tags = {
	has_x => [ qw( nodes terms relations links declared_subsets annotations instances formulae ) ],
	body_only => [ qw( nodes terms relations links annotations instances formulae ) ],
	header_only => [ qw(default_namespace date comment format_version version property_value) ],
	both => [ qw(declared_subsets) ],
};

eval { $obo_parser = new GOBO::Parsers::OBOParser(file=>'/a/load/of/bollox'); };
ok( defined $@ );

#check the OBOParser quickly...
$obo_parser = new GOBO::Parsers::OBOParser(file=>'t/data/gtp.obo');
$dh_parser = new GOBO::Parsers::OBOParserDispatchHash(file=>'t/data/gtp.obo');
ok($obo_parser->has_fh && $dh_parser->has_fh);
$obo_parser->parse;
$dh_parser->parse;
ok( $obo_parser->graph->has_terms && $dh_parser->graph->has_terms, "Checking there are terms in the graph");
cmp_deeply( $obo_parser->graph, $dh_parser->graph, "Comparing OBO and DH parser graphs");


## OK, basics done. Let's try a bit of parsing...
# this is a graph with everything in the known (obo) world in it.
$obo_parser = new GOBO::Parsers::OBOParser(file=>'t/data/obo_file_2.obo');
$dh_parser = new GOBO::Parsers::OBOParserDispatchHash(file=>'t/data/obo_file_2.obo');
my $results;
my $errs;
	
foreach my $p ($obo_parser, $dh_parser)
{	$p->parse;
	my $graph = $p->graph;
	# check that we have these entities in our graph
	foreach my $e (@{$tags->{has_x}})
	{	my $fn = "has_$e";
	#	print STDERR "fn: $fn; result of graph->fn: ". Dumper( $graph->$fn ) . "\n";
		push @$errs, $e if ! $graph->$fn;
	}
	ok( ! defined $errs, "Checking entities in the graph" );
	print STDOUT "Did not find the following entities: " . join(", ", @$errs) . "\n" if $errs && @$errs;
	
	push @{$results->{ ref($p) }}, $graph;
	
	my $g_keys;  # store the non-body stuff in g_keys
	foreach my $k (keys %$graph)
	{	next if grep { $k eq $_ } @{$tags->{body_only}};
		$g_keys->{$k} = $graph->{$k};
	}
	
	## let's try a few options now...
	
#	print STDOUT "\n\n\nStarting options testing!\n";
	
	# ignore body and header
	$p->reset_parser;
	$p->parse_file
	(file=>'t/data/obo_file_2.obo', options => { body => { ignore => '*' }, header => { ignore => '*' } });
	
	my $new_graph = $p->graph;
	#print STDOUT "ignore body and header graph: " . Dumper($new_graph);
	isa_ok( $new_graph, "GOBO::Graph", "Ignoring body and header" );

	push @{$results->{ ref($p) }}, $new_graph;




( run in 0.720 second using v1.01-cache-2.11-cpan-ceb78f64989 )