Treefam GeneHandle
SummaryPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
 Treefam::GeneHandle
Package variables
No package variables defined.
Included modules
Carp
Scalar::Util qw ( weaken )
Treefam::DBConnection
Treefam::Gene
Synopsis
 use Treefam::DBConnection;
my $dbc = new Treefam::DBConnection (); my $gene_handle = $dbc->get_GeneHandle(); my $gene = $gene_handle->get_by_id('ENSG00000087586');
Description
 Enables retrieval of Treefam::Gene objects.
Methods
get_all_by_domainDescriptionCode
get_all_by_domain_listDescriptionCode
get_all_by_familyDescriptionCode
get_all_by_nameDescriptionCode
get_all_by_speciesDescriptionCode
get_by_idDescriptionCode
get_by_sequence_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 genes with the given domain with
e-value below given cut-off (default is 1e-2).
Returntype: list of Treefam::Gene objects
get_all_by_domain_listcodeprevnextTop
 Arg: list of strings, pfam ids of domains
Description: Gets all genes with all the given domains.
No e-value cut-off.
Returntype: list of Treefam::Gene objects
get_all_by_familycodeprevnextTop
 Arg: Treefam::Family
Description: Gets genes belonging to the given family
Returntype: list of Treefam::Gene objects
get_all_by_namecodeprevnextTop
 Arg: string
Description: Gets genes with names matching given string
Returntype: list of Treefam::Gene objects
get_all_by_speciescodeprevnextTop
 Arg1: string, species name
Arg2: optional, Treefam::Family object
Description: Gets all genes of given species present in
the family if one is given, otherwise returns
all genes of the requested species found in
Treefam.
Returntype: list of Treefam::Gene objects
get_by_idcodeprevnextTop
 Arg: gene ID
Description: Gets gene with given ID
Returntype: Treefam::Gene object
get_by_sequence_idcodeprevnextTop
 Arg: sequence/transcript ID
Description: Gets gene with given ID
Returntype: Treefam::Gene object
get_by_symbolcodeprevnextTop
 Arg: gene symbol
Description: Gets gene with given symbol
Returntype: Treefam::Gene object
newcodeprevnextTop
 Arg: Treefam::DBConnection
Description: Creates a new gene object handle
Returntype: Treefam::GeneHandle
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 @genes;
  my %seen;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $query = qq(SELECT DISTINCT g.GID
                 FROM genes g, pfam p
                 WHERE p.PFAM_ID = ?
                 AND p.EVALUE <= $cutoff
                 AND p.ID = g.ID);
  my $sth = $dbh->prepare($query);
  $sth->execute($pfamid);
  while (my ($ID)=$sth->fetchrow_array()) {
    push (@genes,$self->get_by_id($ID));
  }
  $sth->finish();

  return @genes;
}
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_familydescriptionprevnextTop
sub get_all_by_family {
  my ($self,$family) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $familyID = $family->ID;
  my $sth = $dbh->prepare("SELECT DISTINCT g.GID FROM genes g, fam_genes t
                           WHERE t.AC= ? AND t.ID=g.ID");
  $sth->execute($familyID);
  my @genes=();
  while (my ($g)=$sth->fetchrow_array()) {
    push (@genes,$self->get_by_id($g));
  }
  $sth->finish();

  return @genes;
}
get_all_by_namedescriptionprevnextTop
sub get_all_by_name {
  my ($self,$name) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $sth = $dbh->prepare("SELECT DISTINCT g.GID FROM genes g WHERE g.desc LIKE '%$name%' ");
  $sth->execute();
  my @genes=();
  while (my ($g)=$sth->fetchrow_array()) {
    push (@genes,$self->get_by_id($g));
  }
  $sth->finish();

  return @genes;
}
get_all_by_speciesdescriptionprevnextTop
sub get_all_by_species {
  my ($self,$species,$family) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $sth;
  if ($family) {
    my $familyID = ref($family)? $family->ID : $family;
    $sth = $dbh->prepare("SELECT DISTINCT g.GID
                          FROM genes g, species s, fam_genes t
                          WHERE g.tax_id = s.tax_id
                          AND (s.taxname = ? OR s.swcode = ?)
                          AND g.id = t.id
                          AND t.ac = ?");
    $sth->execute($species,$species,$familyID);
  }
  else {
    $sth = $dbh->prepare("SELECT DISTINCT g.GID
                          FROM genes g, species s
                          WHERE g.tax_id = s.tax_id
                          AND (s.taxname = ? OR s.swcode = ?)");
    $sth->execute($species,$species);
  }
  my @genes=();
  while (my ($g)=$sth->fetchrow_array()) {
    push (@genes,$self->get_by_id($g));
  }
  $sth->finish();

  return @genes;
}
get_by_iddescriptionprevnextTop
sub get_by_id {
  my ($self,$geneID) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  # check if gene exists in database
my $query = qq( SELECT COUNT(*) FROM genes WHERE GID= ? ); my $sth= $dbh->prepare ($query); $sth->execute($geneID); my ($count) = $sth->fetchrow_array(); unless ($count) { return undef; } return new Treefam::Gene($dbc,$geneID);
}
get_by_sequence_iddescriptionprevnextTop
sub get_by_sequence_id {
  my ($self,$ID) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $query = qq( SELECT GID FROM genes WHERE ID= ? OR TID= ?);
  my $sth= $dbh->prepare ($query);
  $sth->execute($ID,$ID);
  my ($geneID) = $sth->fetchrow_array();

  return undef if (!defined($geneID));

  my $gene = Treefam::Gene->new($dbc,$geneID);
  $gene->sequence_id($ID);

  return $gene;
}
get_by_symboldescriptionprevnextTop
sub get_by_symbol {
  my ($self,$symbol) = @_;
  my $dbc = $self->{'DBConnection'};
  my $dbh = $dbc->{'database_handle'};
  my $sth = $dbh->prepare("SELECT DISTINCT GID FROM genes
                           WHERE symbol=?");
  $sth->execute($symbol);
  my ($geneID) = $sth->fetchrow_array();
  $sth->finish();

  return undef if ( !defined $geneID );

  return $self->get_by_id($geneID);
}
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