Treefam FamilyHandle
SummaryPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
 Treefam::FamilyHandle
Package variables
No package variables defined.
Included modules
Carp
Scalar::Util qw ( weaken )
Treefam::DBConnection
Treefam::Family
Synopsis
 use Treefam::DBConnection;
my $dbc = new Treefam::DBConnection (); my $famh = $dbc->get_FamilyHandle(); my $family = $famh->get_by_id('TF300011');
Description
 Enables retrieval of Treefam family objects.
Methods
get_all_by_domainDescriptionCode
get_all_by_domain_listDescriptionCode
get_all_by_speciesDescriptionCode
get_all_by_typeDescriptionCode
get_by_acDescriptionCode
get_by_geneDescriptionCode
get_by_idDescriptionCode
get_by_symbolDescriptionCode
newDescriptionCode
Methods description
get_all_by_domaincode    nextTop
 Arg1: string, pfam id of domain
Arg2: (optional) e-value cut-off
Description: Gets all families that have genes with the
given domain with e-value below given cut-off
(default is 1e-2).
Returntype: list of Treefam::Family objects
get_all_by_domain_listcodeprevnextTop
 Arg: list of strings, pfam ids of domains
Description: Gets all families with genes that have
all the given domains. No e-value cut-off.
Returntype: list of Treefam::Gene objects
get_all_by_speciescodeprevnextTop
 Arg1: string, species (Swissprot code or latin name)
Arg2: optional, string, type of families (A or B)
Description: Gets all families that have genes of the
given species
Returntype: list of Treefam::Family objects
get_all_by_typecodeprevnextTop
 Arg: string, type of families: A or B
Description: Gets all families of given type
Returntype: list of Treefam::Family objects
get_by_accodeprevnextTop
 Arg: Treefam family database ID
Description: A synonym for get_by_id. Gets family with
given Treefam database ID
Returntype: Treefam::Family object
get_by_genecodeprevnextTop
 Arg: Treefam::Gene object
Description: Gets family containing given gene.
Returntype: Treefam::Family object
get_by_idcodeprevnextTop
 Arg: Treefam family database ID
Description: Gets family with given Treefam database ID
Returntype: Treefam::Family object
get_by_symbolcodeprevnextTop
 Arg: family symbol
Description: Gets family with given symbol. Only curated
families have symbols.
Returntype: Treefam::Family object
newcodeprevnextTop
 Arg: Treefam::DBConnection
Description: Creates a new family object handle
Returntype: Treefam::FamilyHandle
Methods code
get_all_by_domaindescriptionprevnextTop
sub get_all_by_domain {
  my $self = shift;
  my $pfamid = shift;
  unless ($pfamid) {
    croak "Pfam domain id required";
  }
  my $cutoff = shift if @_;
  if (!$cutoff) {
    $cutoff = 1e-2;
  }
  my @families;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $query = qq(SELECT DISTINCT t1.AC FROM fam_genes t1, pfam p
                 WHERE t1.ID = p.ID
                 AND p.PFAM_ID = ?
                 AND t1.FAM_TYPE IN ('A','B') );
  my $sth = $dbh->prepare($query);
  $sth->execute($pfamid);
  while (my ($familyID)=$sth->fetchrow_array()) {
    push (@families,$self->get_by_id($familyID));
  }
  $sth->finish();

  return @families;
}
get_all_by_domain_listdescriptionprevnextTop
sub get_all_by_domain_list {
  my $self = shift;
  my @pfamids = @_;
  unless ($pfamids[0]) {
    croak "Pfam domain ids required";
  }
  my @genes;
  my %seen;
  # remove duplicates
my @uniq_pfamids = grep { !$seen{$_}++ } @pfamids; %seen = (); foreach my $pfamid(@uniq_pfamids) { map { $seen{$_->ID}++ if $_ } $self->get_all_by_domain($pfamid,10000); } my $n = scalar(@uniq_pfamids); my @IDs = grep { $seen{$_}==$n } keys %seen; while (my $ID=shift @IDs) { push (@genes,$self->get_by_id($ID)); } return @genes; } 1;
}
get_all_by_speciesdescriptionprevnextTop
sub get_all_by_species {
  my ($self,$species,$type) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $query;
  if ($type) {
    $query = qq( SELECT DISTINCT t.AC FROM fam_genes t, genes g, species sp
                 WHERE t.ID = g.ID
                 AND  g.TAX_ID = sp.TAX_ID
                 AND t.FAM_TYPE = '$type'
                 AND (sp.SWCODE = ? OR sp.TAXNAME = ?) );
  }
  else {
    $query = qq( SELECT DISTINCT t1.AC FROM fam_genes t1, genes g, species s
                 WHERE t1.ID = g.ID
                 AND  g.TAX_ID = s.TAX_ID
                 AND t1.FAM_TYPE IN ('A','B')
                 AND (s.SWCODE = ? OR s. TAXNAME = ?) );
}
my
$sth = $dbh->prepare($query);
$sth->execute($species,$species);
my
@families;
while ( my (
$familyID) = $sth->fetchrow_array()) {
push
@families,$self->get_by_id($familyID);
}
$sth->finish();
return
@families;

}
get_all_by_typedescriptionprevnextTop
sub get_all_by_type {
  my ($self,$type) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  $type = ($type eq 'A') ? 'familyA' : 'familyB';
  my $query = qq( SELECT DISTINCT AC FROM $type );
  my $sth = $dbh->prepare($query);
  $sth->execute();
  my @families;
  while ( my ($familyID) = $sth->fetchrow_array()) {
    push @families,$self->get_by_id($familyID);
  }
  $sth->finish();
  return @families;
}
get_by_acdescriptionprevnextTop
sub get_by_ac {
  my ($self,$familyID) = @_;
  return $self->get_by_id($familyID);
}
get_by_genedescriptionprevnextTop
sub get_by_gene {
  my ($self,$gene) = @_;
  my $geneID = ref($gene) ? $gene->ID() : $gene;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  # get family with the highest HMMER score
my $query = qq( SELECT DISTINCT t.AC FROM hmmer_matches h, fam_genes t LEFT JOIN genes g ON t.ID=g.ID WHERE g.GID= ? AND h.ID=g.ID AND t.FAM_TYPE IN ('A','B') ORDER BY h.SCORE DESC ); my $sth = $dbh->prepare($query); $sth->execute($geneID); my ($familyID) = $sth->fetchrow_array(); $sth->finish(); if ($familyID) { return $self->get_by_id($familyID); } else { return undef; }
}
get_by_iddescriptionprevnextTop
sub get_by_id {
  my ($self,$familyID) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $type;
  if ($familyID=~/^TF1/) {
    $type =  'familyA';
  }
  elsif($familyID=~/^TF3/) {
    $type = 'familyB';
  }
  else {
    $type = 'familyC';
  }
  my $query = qq( SELECT COUNT(*) FROM $type WHERE AC= ? );
  my $sth= $dbh->prepare ($query);
  # check if family exists in database
$sth->execute($familyID); my ($count) = $sth->fetchrow_array(); unless ($count) { return undef; } return new Treefam::Family($dbc,$familyID,$type);
}
get_by_symboldescriptionprevnextTop
sub get_by_symbol {
  my ($self,$symbol) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $sth = $dbh->prepare("SELECT AC FROM familyA
                           WHERE symbol=?");
  $sth->execute($symbol);
  my ($familyID) = $sth->fetchrow_array();
  $sth->finish();

  return undef if( !defined $familyID );

  return $self->get_by_id($familyID);
}
newdescriptionprevnextTop
sub new {
  my $class = shift;
  my $self = {};
  $self->{'DBConnection'} = shift;
  weaken($self->{'DBConnection'});
  bless ($self, $class);

  return $self;
}
General documentation
CONTACTTop
 jkh1@sanger.ac.uk