These documents are For the HEAD of the CVS repository on July 19, 2007
Api docs for previous releases
Modware
Bioseq
Modware::Bioseq - Bio::SeqI implementing Object that queries a sequence in Chado instead of in memory.
|
No package variables defined. |
# USE CASE: PRINT THE FIRST 1000 BASES OF FEATURE_ID 1000 my $chr = Modware::Bioseq->new( -feature_id => 1000 );
print $chr->subseq (1, 1000);
# USE CASE: ADD A Bio::SeqFeatureI COMPLIANT FEATURE TO CHROMOSOME 1, THEN PRINT THE SEQUENCE my $chr = Modware::Bioseq->new( -feature_id => 1000 );
my $generic_feature = new Bio::SeqFeature::Generic( -start => 10, -end => 100, -strand => -1 );
print $generic_feature->seq->seq();
# USE CASE: CHANGE THE SEQUENCE OF FEATURE_ID 1000 my $chr = Modware::Bioseq->new( -feature_id => 1000 );
my $seq = 'ATCGATAGGCATAGA';#...# # this would be much longer in reality!!
$chr->seq( $seq );
# the new sequence is now in the database
|
This class is mainly used for chromosomes and contigs on which Bio::SeqFeature annotations will be placed, it is mainly used internally and should not generally be used as a part of the API.
This class behaves as a Bio::PrimarySeq object. The sequence remains in the database while calls to subseq and trunc are translated into sql statements to fetch only portions of that sequence from the database.
Beware of calling the 'seq' method on one of these objects, it will pull the whole sequence into memory. If it is a chromosome, this can be very large!
|
Methods description
Title : length
Usage : $len = $seq->length()
Function:
Returns : integer representing the length of the sequence.
Args :
Title : seq
Note : get/set chromsoome sequence in database
Function : returns entire seq
Returns : feature_id string
Args : none (for now)
Title : subseq
Usage : $substring = $obj->subseq(10,40);
Function: returns the subseq from start to end, where the first base
is 1 and the number is inclusive, ie 1-2 are the first two
bases of the sequence
Returns : a string
Args : integer for start position
integer for end position
Title : trunc
Usage : $subseq = $myseq->trunc(10,100);
Function: Provides a truncation of a sequence,
Example :
Returns : a fresh Bio::PrimarySeqI implementing object
Args : Two integers denoting first and last base of the sub-sequence.
Methods code
sub length
{
my ( $self, $start, $end ) = @_;
my $dbh = new Modware::DBH;
my $sth = $dbh->prepare("
SELECT SEQLEN
FROM FEATURE
WHERE FEATURE_ID = ?
");
$sth->execute( $self->primary_id() );
return $sth->fetchrow();
}
sub seq
{ my ($self, $seq) = @_;
if($seq) {
my $dbh = new Modware::DBH;
my $sth = $dbh->prepare("
UPDATE FEATURE
SET RESIDUES = ?,
SEQLEN = ?
WHERE FEATURE_ID = ?
");
$sth->execute( $seq, length( $seq ), $self->primary_id() );
return $seq;
}
else {
my $dbh = new Modware::DBH;
my $sth = $dbh->prepare("
SELECT RESIDUES
FROM FEATURE
WHERE FEATURE_ID = ?
");
$sth->execute( $self->primary_id() );
return $sth->fetchrow();
}
}
sub subseq
{ my ( $self, $start, $end ) = @_;
if( defined $start && defined $end ) {
if( $start > $end ){
$self->throw("Bad start,end parameters. Start [$start] has to be ".
"less than end [$end]");
}
if( $start <= 0 ) {
$self->throw("Bad start parameter ($start). Start must be positive.");
}
if( $end > $self->length ) {
$self->throw("Bad end parameter ($end). End must be less than the total length of sequence (total=".$self->length.")");
}
my $dbh = new Modware::DBH;
my $sth = $dbh->prepare("
SELECT SUBSTR( RESIDUES, ?, ? )
FROM FEATURE
WHERE FEATURE_ID = ?
");
my $subseq_length = $end - $start + 1;
$sth->execute( $start, $subseq_length, $self->primary_id() );
return $sth->fetchrow();
}
else {
$self->warn("Incorrect parameters to subseq - must be two integers ".
"or a Bio::LocationI object not ($start,$end)");
}
}
sub trunc
{
my ($self,$start,$end) = @_;
my $str;
if( defined $start && ref($start) &&
$start->isa('Bio::LocationI') ) {
$str = $self->subseq($start); # start is a location actually
} elsif( !$end ) {
$self->throw("trunc start,end -- there was no end for $start");
} elsif( $end < $start ) {
my $msg = "start [$start] is greater than end [$end].\n ".
"If you want to truncated and reverse complement,\n ".
"you must call trunc followed by revcom. Sorry.";
$self->throw($msg);
} else {
$str = $self->subseq($start,$end);
}
my $out = Bio::PrimarySeq->new(
'-seq' => $str,
'-display_id' => $self->display_id,
'-accession_number' => $self->accession_number,
'-alphabet' => $self->alphabet,
'-desc' => $self->desc(),
'-verbose' => $self->verbose
);
return $out;
}
General documentation
Copyright © 2006, Northwestern University
All rights reserved.
|
|