#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
use GO::Ontology;


my ($go_file);

$go_file = "data/gene_ontology_ext.obo";

my $ontology = GO::Ontology::new();
$ontology->read($go_file);
print("Read information on ", $ontology->get_num_terms(), " terms.\n");
#$ontology->print_ids();

# my @test = (1, 2, 3, 4, 5, 6);
# my @copy;
# # subtract one from all odd numbers.
# map { if (1 == $_%2) $_--; } @test;
# map { push(@copy, $_) if defined($_); } @test;

$ontology->compute_roots();


my ($id, $term, $ancestors, $anc, $distances);

$id = "GO:0000001";
#$id = "GO:0071841";
$id = "GO:0034462";
$term = $ontology->terms($id);
print("GO term with id $id is ", $term->name(), "\n");
print("Parents of $id are ", join(" ", @{$term->get_parents()}), "\n");
print("Grandparents of $id are ", join(" ", @{$ontology->get_grandparents($id)}), "\n");
print("Ancestors of $id are ", join(" ", keys %{$ontology->get_ancestors($id)}), "\n");
# $ancestors = $ontology->get_ancestors($id);
# print("Distances of ancestors of $id are:\n");
# foreach $anc (sort { scalar($ancestors->{$a}) <=> scalar($ancestors->{$b}) } keys %$ancestors)
#   {
#     print("\t$anc: ", join(" ", @{$ancestors->{$anc}}), "\n");
#   }

my $distance = 5;
$ancestors = $ontology->get_ancestors_at_most_distance_bfs($id, $distance);
print("Distances of ancestors of $id at distance <= $distance are:\n");
foreach $anc (sort { $ancestors->{$a} <=> $ancestors->{$b} } keys %$ancestors)
  {
    print("\t$anc: ", $ancestors->{$anc}, "\n");
  }

$ancestors = $ontology->get_ancestors_at_exactly_distance_bfs($id, $distance);
print("Distances of ancestors of $id at distance = $distance are: ",
	join(" ", @$ancestors), "\n");

__END__
