The Treefam Perl object-oriented API is a set of Perl modules that provide high-level access to the data stored in the Treefam MySQL database. It has been designed to give easy access to entities commonly used in the Treefam project such as families, genes and trees. It aims at making automatic retrieval of particular data easy. In addition, it has limited tree manipulation capabilities such as subtree extraction and node deletion. However, a larger range of efficient tree manipulation functions, including tree building, is available from the TreeBeST program. The Treefam Perl object-oriented API was written and is maintained by Jean-Karim.

Documentation is included in POD (Plain Old Documentation) form and can also be seen here.

Get the TreeFam Perl API

The code is freely available at the download page. One can also fetch the latest codes from the Subversion server which can be accessed by:

    svn co Treefam
Note that the API is closely related to TreeFam version. Please always use the latest codes to connect to the latest TreeFam MySQL database.

How to use the API

Below is an example script showing various uses of the API for data retrieval.

#!/usr/local/bin/perl -w

use strict;
use Treefam::DBConnection;

# connect to the Treefam database using default configuration
my $dbc = Treefam::DBConnection->new();

# get a family
my $famh = $dbc->get_FamilyHandle();
my $family = $famh->get_by_id('TF101166');

# get a tree
my $tree = $family->get_tree('full');

# list all leaves from the tree
foreach my $leaf($tree->get_leaves) {
  print $leaf->name,"\n";

# get all human genes in this family
my $gh = $dbc->get_GeneHandle;
my @genes = $gh->get_all_by_species('HUMAN',$family);

# list their mouse and fly orthologs
foreach my $gene(@genes) {
  my @orthologs = $gene->get_orthologs('Mus musculus','Drosophila melanogaster');
  foreach my $ortholog(@orthologs) {
    print $ortholog->symbol," (",$ortholog->species,")\n";

# get a subtree defined by 2 genes
my $gene1 = $gh->get_by_id('ENSG00000108468');
my $gene2 = $gh->get_by_id('ENSDARG00000004189');
my $subtree = $tree->get_subtree($gene1,$gene2);

# show the alignment for the subtree
print $subtree->get_alignment('nt'),"\n";

# get some subtrees rooted at chosen nodes
my @nodes = $tree->get_nodes_by_tag_value(-S=>'Euteleostomi');
my @subtrees;
foreach my $node(@nodes) {
  push @subtrees,$tree->get_subtree($node);

# find human-specific families:
my @families = $famh->get_all_by_species('Homo sapiens'); # gets families with human genes
@families = grep {scalar($_->get_species)==1} @families; # filters families with only one species
print "Found ",scalar(@families)," families with human genes only\n";