Bio::LiveSeq
SeqI
Toolbar
Summary
Bio::LiveSeq::SeqI - Abstract sequence interface class for LiveSeq
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Description
This class implements BioPerl PrimarySeqI interface for Live Seq objects.
One of the main difference in LiveSequence compared to traditional
"string" sequences is that coordinate systems are flexible. Typically
gene nucleotide numbering starts from 1 at the first character of the
initiator codon (A in ATG). This means that negative positions are
possible and common!
Secondly, the sequence manipulation methods do not return a new
sequence object but change the current object. The current status can
be written out to BioPerl sequence objects.
Methods
Methods description
Title : accession_number Usage : $unique_biological_key = $obj->accession_number; Function: Returns the unique biological id for a sequence, commonly called the accession_number. Notice that primary_id() provides the unique id for the implemetation, allowing multiple objects to have the same accession number in a particular implementation.
For objects with no accession_number this method returns "unknown".
Returns : a string
Args : none |
Title : all_labels Usage : @labels = $obj->all_labels() Function: all the labels of every nucleotide an object is composed of Returns : an array of labels Args : none |
Title : alphabet Usage : if( $obj->alphabet eq 'dna' ) { /Do Something/ } Function: Returns the type of sequence being one of 'dna', 'rna' or 'protein'. This is case sensitive.
Returns : a string either 'dna','rna','protein'.
Args : none
Note : "circular dna" is set as dna |
Title : change Usage : $substring = $obj->change('AA', 10); Function: changes, modifies, mutates the LiveSequence Examples: $obj->change('', 10); delete nucleotide #10 $obj->change('', 10, 2); delete two nucleotides starting from #10 $obj->change('G', 10); change nuc #10 to 'G' $obj->change('GA', 10, 4); replace #10 and 3 following with 'GA' $obj->change('GA', 10, 2)); is same as $obj->change('GA', 10); $obj->change('GA', 10, 0 ); insert 'GA' before nucleotide at #10 $obj->change('GA', 10, 1); GA inserted before #10, #10 deleted $obj->change('GATC', 10, 2); GATC inserted before #10, #10 deleted $obj->change('GATC', 10, 6); GATC inserted before #10, #10-#15 deleted
Returns : a string of deleted bases (if any) or 1 (everything OK)
Errorcode: -1
Args : seq, string, or '' ('' = undef = 0 = deletion)
start, integer
length, integer (optional) |
Title : coordinate_start Usage : $coordstartlabel=$obj->coordinate_start() : $coordstartlabel=$obj->coordinate_start($label) Function: returns and optionally sets the first label of the coordinate system used For some objects only labels inside the object or in frame (for Translation objects) will be allowed to get set as coordinate start
Returns : label. It returns 0 if label not found.
Errorcode -1
Args : an optional reference $label that is position 1 |
Title : desc Usage : $desc = $obj->desc; : $desc = $obj->desc("ABCD"); Function: Returns or sets the description of the object. If there is no description, it will return "unknown"; Returns : A string Args : None |
Title : display_id Usage : $id_string = $obj->display_id(); Function: returns the display id, alias the common name of the object
The semantics of this is that it is the most likely string
to be used as an identifier of the sequence, and likely to
have "human" readability. The id is equivalent to the ID
field of the GenBank/EMBL databanks and the id field of the
Swissprot/sptrembl database. In fasta format, the >(\S+) is
presumed to be the id, though some people overload the id
to embed other information.
See also: accession_number
Returns : a string
Args : none |
Title : end Usage : $endlabel=$obj->end() Function: returns the label of the last nucleotide of the object (exon, CDS) Returns : label Args : none |
Title : follows Usage : $seq->follows($firstlabel,$secondlabel) : $seq->follows($firstlabel,$secondlabel,$strand) Function: checks if SECONDlabel follows FIRSTlabel, undependent of the strand i.e. it checks downstream for forward strand and upstream for reverse strand Returns : 1 or 0 Errorcode -1 Args : two labels an optional strand (1 or -1) argument if strand argument is not given, it will default to the object argument. This argument is useful when a call is issued from a child of a parent object containing the subseq method |
Title : gene Usage : my $gene=$obj->gene; Function: Gets or sets the reference to the LiveSeq::Gene object. Objects that are features of a LiveSeq Gene will have this attribute set automatically.
Returns : reference to an object of class Gene
Note : if Gene object is not set, this method will return 0;
Args : none or reference to object of class Bio::LiveSeq::Gene |
Title : label Usage : $seq->label($position) : $seq->label($position,$firstlabel) Examples: $nextlabel=$seq->label(2,$label) -> retrieves the following label : $prevlabel=$seq->label(-1,$label) -> retrieves the preceding label
Function: returns the label of the nucleotide at $position from current
coordinate start
Returns : a label. It returns 0 if label not found.
Errorcode -1
Args : a position,
an optional reference $firstlabel that is to be used as position 1
an optional strand (1 or -1) argument
if strand argument is not given, it will default to the object
argument. This argument is useful when a call is issued from a child
of a parent object containing the subseq method |
Title : labelchange Function: Exactly like change but uses a /label/ instead than a position as second argument. This allows for multiple changes in a LiveSeq without the burden of recomputing positions. I.e. for a multiple change in two different points of the LiveSeq, the approach would be the following: fetch the correct labels out of the two different positions (method: label($position)) and then use the labelchange() method to modify the sequence using those labels instead than relying on the positions (that would have modified after the first change). |
Title : labelsubseq Usage : $dna->labelsubseq(); : $dna->labelsubseq($startlabel); : $dna->labelsubseq($startlabel,$length); : $dna->labelsubseq($startlabel,undef,$endlabel); e.g. : $dna->labelsubseq(4,undef,8); Function: prints the sequence as string. The difference between labelsubseq and normal subseq is that it uses /labels/ as arguments, instead than positions. This allows for faster and more efficient lookup, skipping the (usually) lengthy conversion of positions into labels. This is expecially useful for manipulating with high power LiveSeq objects, knowing the labels and exploiting their usefulness. Returns : a string Errorcode -1 Args : without arguments it returns the entire sequence with a startlabel it returns the sequence downstream that label if a length is specified, it returns only that number of bases if an endlabel is specified, it overrides the length argument and prints instead up to that label (included) Defaults: $startlabel defaults to the beginning of the entire sequence $endlabel defaults to the end of the entire sequence |
Title : length Usage : $seq->length(); Function: returns the number of nucleotides (or the number of aminoacids) in the entire sequence Returns : an integer Errorcode -1 Args : none |
Title : name Usage : $name = $obj->name; : $name = $obj->name("ABCD"); Function: Returns or sets the name of the object. If there is no name, it will return "unknown"; Returns : A string Args : None |
Title : obj_valid Usage : if ($obj->obj_valid) {do something;} Function: Checks if start and end labels are still valid for the ojbect, i.e. tests if the LiveSeq object is still valid Returns : boolean Args : none |
Title : position Usage : $seq->position($label) : $seq->position($label,$firstlabel) Function: returns the position of nucleotide at $label Returns : the position of the label from current coordinate start Errorcode 0 Args : a label pointing to a certain nucleotide (e.g. start of exon) an optional "firstlabel" as reference to count from an optional strand (1 or -1) argument if strand argument is not given, it will default to the object argument. This argument is useful when a call is issued from a child of a parent object containing the subseq method |
Title : positionchange Function: Exactly like change. I.e. change() defaults to positionchange() |
Title : primary_id Usage : $unique_implementation_key = $obj->primary_id; Function: Returns the unique id for this object in this implementation. This allows implementations to manage their own object ids in a way the implementation can control. Clients can expect one id to map to one object.
For sequences with no primary_id, this method returns
a stringified memory location.
Returns : A string
Args : None |
Title : seq Usage : $string = $obj->seq() Function: Returns the complete sequence of an object as a string of letters. Suggested cases are upper case for proteins and lower case for DNA sequence (IUPAC standard), Returns : a string |
Title : source Usage : $name = $obj->source; : $name = $obj->source("Homo sapiens"); Function: Returns or sets the organism that is source of the object. If there is no source, it will return "unknown"; Returns : A string Args : None |
Title : start Usage : $startlabel=$obj->start() Function: returns the label of the first nucleotide of the object (exon, CDS) Returns : label Args : none |
Title : strand Usage : $strand=$obj->strand() $obj->strand($strand) Function: gets or sets strand information, being 1 or -1 (forward or reverse) Returns : -1 or 1 Args : none OR -1 or 1 |
Title : subseq Usage : $substring = $obj->subseq(10,40); : $substring = $obj->subseq(10,undef,4); 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
Start cannot be larger than end but can be equal.
Allows for negative numbers $obj->subseq(-10,-1). By
definition, there is no 0!
-5 -1 1 5
gctagcgcccaac atggctcgctg
This allows to retrieve sequences upstream from given position.
The precedence is from left to right: if END is given LENGTH is
ignored.
Examples: $obj->subseq(-10,undef,10) returns 10 elements before position 1
$obj->subseq(4,8) returns elements from the 4th to the 8th, inclusive
Returns : a string
Errorcode: -1
Args : start, integer, defaults to start of the sequence
end, integer, '' or undef, defaults to end of the sequence
length, integer, '' or undef
an optional strand (1 or -1) 4th argument
if strand argument is not given, it will default to the object
argment. This argument is useful when a call is issued from a child
of a parent object containing the subseq method |
Title : valid Usage : $boolean = $obj->valid($label) Function: tests if a label exists inside the object Returns : boolean Args : label |
Methods code
sub _delete
{ my ($self,$label,$length)=@_;
my $strand=$self->strand();
my $endlabel=$self->label($length,$label,$strand); unless ($endlabel > 0) { $self->warn("No valid endlabel found for executing the deletion!");
return (-1);
}
$self->_deletecheck($label,$endlabel);
my $deletedseq;
if ($strand == 1) {
$deletedseq=$self->{'seq'}->splice_chain($label,undef,$endlabel);
} else {
$deletedseq=$self->{'seq'}->splice_chain($endlabel,undef,$label);
$deletedseq=reverse($deletedseq); $deletedseq =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/; }
return ($deletedseq);
}
} |
sub _mutate
{ my ($self,$label,$newseq,$length)=@_; my ($i,$base,$nextlabel);
my @labels; my $strand=$self->strand();
if ($length == 1) { @labels=($label);
} else {
my $endlabel=$self->label($length,$label,$strand); unless ($endlabel > 0) { $self->warn("No valid endlabel found for executing the mutation!");
return (-1);
}
if ($length == 2) { @labels=($label,$endlabel);
} else {
@labels=($label); while ($label != $endlabel) {
$nextlabel=$self->label(2,$label,$strand); push (@labels,$nextlabel);
$label=$nextlabel; }
}
}
if ($strand == -1) { $newseq =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/; }
my $errorcheck; $i = 0;
foreach $base (split(//,$newseq)) {
$errorcheck += $self->{'seq'}->set_value_at_label($base,$labels[$i]);
$i++;
}
if ($errorcheck != $length) {
$self->warn("Some error occurred while mutating!");
return (-1);
} else {
return (1);
} } |
sub _praeinsert
{ my ($self,$label,$newseq)=@_;
my ($insertbegin,$insertend);
my $strand=$self->strand();
if ($strand == 1) {
($insertbegin,$insertend)=($self->{'seq'}->praeinsert_string($newseq,$label));
} else { $newseq=reverse($newseq);
$newseq =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/; ($insertend,$insertbegin)=($self->{'seq'}->postinsert_string($newseq,$label));
}
if (($insertbegin==0)||($insertend==0)) {
$self->warn("Some error occurred while inserting!");
return (-1);
} else {
return ($insertbegin,$insertend);
}
}
} |
sub accession_number
{ my ($self,$value) = @_;
if (defined $value) {
$self->{'accession_number'} = $value;
}
unless (exists $self->{'accession_number'}) {
return "unknown";
} else {
return $self->{'accession_number'};
} } |
sub all_labels
{ my $self = shift;
my ($start,$end) = ($self->start(),$self->end());
my $labels;
if ($self->strand() == 1) {
$labels=$self->{'seq'}->down_labels($start,$end);
} else {
$labels=$self->{'seq'}->up_labels($start,$end);
}
return (@{$labels}); } |
sub alphabet
{ my %valid_type = map {$_, 1} qw( dna rna protein );
my ($self,$value) = @_;
if (defined $value) {
$value =~ s/circular dna/dna/;
unless ( $valid_type{$value} ) {
$self->warn("Molecular type '$value' is not a valid type");
}
$self->{'alphabet'} = $value;
}
return $self->{'alphabet'}; } |
sub change
{ &positionchange; } |
sub coordinate_start
{ my ($self,$label) = @_;
if ($label) {
if ($self->valid($label)) {
$self->{'coordinate_start'} = $label;
} else {
$self->warn("The label you are trying to set as coordinate_start is not valid for this object");
}
}
my $coord_start = $self->{'coordinate_start'};
if ($coord_start) {
return $coord_start;
} else {
return $self->start();
} } |
sub delete_Obj
{ my $self = shift;
my @values= values %{$self};
my @keys= keys %{$self};
foreach my $key ( @keys ) {
delete $self->{$key};
}
foreach my $value ( @values ) {
if (index(ref($value),"LiveSeq") != -1) { eval {
$value->delete_Obj;
};
} elsif (index(ref($value),"ARRAY") != -1) { my @array=@{$value};
my $element;
foreach $element (@array) {
eval {
$element->delete_Obj;
};
}
} elsif (index(ref($value),"HASH") != -1) { my %hash=%{$value};
my $element;
foreach $element (%hash) {
eval {
$element->delete_Obj;
};
}
}
}
return(1);
}
1; } |
sub desc
{ my ($self,$value) = @_;
if (defined $value) {
$self->{'desc'} = $value;
}
unless (exists $self->{'desc'}) {
return "unknown";
} else {
return $self->{'desc'};
} } |
sub display_id
{ my ($self,$value) = @_;
if(defined $value) {
$self->{'display_id'} = $value;
}
return $self->{'display_id'}; } |
sub end
{ my ($self) = @_;
return $self->{'end'}; } |
sub follows
{ my ($self,$firstlabel,$secondlabel,$strand)=@_;
unless (defined ($strand)) { $strand=$self->strand;
}
if ($strand == 1) {
return ($self->{'seq'}->is_downstream($firstlabel,$secondlabel));
} else {
return ($self->{'seq'}->is_upstream($firstlabel,$secondlabel));
}
}
} |
sub gene
{ my ($self,$value) = @_;
if (defined $value) {
$self->{'gene'} = $value;
}
unless (exists $self->{'gene'}) {
return (0);
} else {
return $self->{'gene'};
} } |
sub label
{ my ($self,$position,$firstlabel,$strand)=@_;
my $label;
unless (defined ($firstlabel)) {
$firstlabel=$self->coordinate_start;
}
unless ($position) { $self->warn("Position not given or position 0");
return (-1);
}
unless (defined ($strand)) { $strand=$self->strand;
}
if ($strand == 1) {
if ($position > 0) {
$label=$self->{'seq'}->down_get_label_at_pos($position,$firstlabel)
} else { $label=$self->{'seq'}->up_get_label_at_pos(1 - $position,$firstlabel)
}
} else {
if ($position > 0) {
$label=$self->{'seq'}->up_get_label_at_pos($position,$firstlabel)
} else { $label=$self->{'seq'}->down_get_label_at_pos(1 - $position,$firstlabel)
}
}
return $label; } |
sub labelchange
{ my ($self,$newseq,$label,$length)=@_;
unless ($self->valid($label)) {
if ($self->{'seq'}->valid($label)) {
shift @_;
return($self->{'seq'}->labelchange(@_));
} else {
$self->warn("Label\' $label\' not valid for executing a LiveSeq change");
return (-1);
}
}
unless ($newseq) { if (defined($length)) {
unless ($length >= 0) {
$self->warn("No sense having length < 0 in a deletion");
return (-1);
}
} else {
$self->warn("Length not defined for deletion!");
return (-1);
}
return $self->_delete($label,$length);
}
my $newseqlength=CORE::length($newseq);
if (defined($length)) {
unless ($length >= 0) {
$self->warn("No sense having length < 0 in a change()");
return (-1);
}
} else {
$length=$newseqlength; }
if ($length == 0) { my ($insertbegin,$insertend)=$self->_praeinsert($label,$newseq);
if ($insertbegin == -1) {
return (-1);
} else {
return (1);
}
}
if ($newseqlength == $length) { return $self->_mutate($label,$newseq,$length);
}
my $strand=$self->strand();
my $afterendlabel=$self->label($length+1,$label,$strand); unless ($afterendlabel > 0) { $self->warn("No valid afterendlabel found for executing the complex mutation!");
return (-1);
}
my $deleted=$self->_delete($label,$length); if ($deleted == -1) { return (-1);
} else { my ($insertbegin,$insertend)=$self->_praeinsert($afterendlabel,$newseq);
if ($insertbegin == -1) {
return (-1);
} else {
return (1);
}
}
}
} |
sub labelsubseq
{ my ($self,$start,$length,$end,$unsecuremode) = @_;
if (defined $unsecuremode && $unsecuremode eq "unsecuremoderequested")
{ unless ($start) {
$start=$self->start;
}
if ($end) {
if ($end == $start) {
$length=1;
undef $end;
} else {
undef $length;
}
} else {
unless ($length) {
$end=$self->end;
}
}
} else {
if ($start) {
unless ($self->{'seq'}->valid($start)) {
$self->warn("Start label not valid"); return (-1);
}
}
if ($end) {
if ($end == $start) {
$length=1;
undef $end;
} else {
unless ($self->{'seq'}->valid($end)) {
$self->warn("End label not valid"); return (-1);
}
unless ($self->follows($start,$end) == 1) {
$self->warn("End label does not follow Start label!"); return (-1);
}
undef $length;
}
}
}
if ($self->strand() == 1) {
return $self->{'seq'}->down_chain2string($start,$length,$end);
} else { my $str = $self->{'seq'}->up_chain2string($start,$length,$end);
$str =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/;
return $str;
} } |
sub length
{ my $self=shift;
my ($start,$end,$strand)=($self->start(),$self->end(),$self->strand());
if ($strand == 1) {
return $self->{'seq'}->down_subchain_length($start,$end);
} else {
return $self->{'seq'}->up_subchain_length($start,$end);
} } |
sub name
{ my ($self,$value) = @_;
if (defined $value) {
$self->{'name'} = $value;
}
unless (exists $self->{'name'}) {
return "unknown";
} else {
return $self->{'name'};
} } |
sub obj_valid
{ my $self=shift;
unless (($self->{'seq'}->valid($self->start()))&&($self->{'seq'}->valid($self->end()))) {
return (0);
}
return (1); } |
sub position
{ my ($self,$label,$firstlabel,$strand)=@_;
unless (defined ($strand)) { $strand=$self->strand;
}
unless (defined ($firstlabel)) {
$firstlabel=$self->coordinate_start;
}
unless ($self->valid($label)) {
$self->warn("label not valid");
return (0);
}
if ($firstlabel == $label) {
return (1);
}
my ($coordpos,$position0,$position);
$position0=$self->{'seq'}->down_get_pos_of_label($label);
$coordpos=$self->{'seq'}->down_get_pos_of_label($firstlabel);
$position=$position0-$coordpos+1;
if ($position <= 0) {
$position--;
}
if ($strand == -1) {
return (1-$position);
} else {
return ($position);
} } |
sub positionchange
{ my ($self,$newseq,$position,$length)=@_;
unless ($position) {
$self->warn("Position not given or position 0");
return (-1);
}
my $label=$self->label($position);
unless ($label > 0) { $self->warn("No valid label found at that position!");
return (-1);
}
return ($self->labelchange($newseq,$label,$length)); } |
sub primary_id
{ my ($self,$value) = @_;
if(defined $value) {
$self->{'primary_id'} = $value;
}
unless (exists $self->{'primary_id'}) {
return "$self";
} else {
return $self->{'primary_id'};
} } |
sub seq
{ my $self = shift;
my ($start,$end) = ($self->start(),$self->end());
if ($self->strand() == 1) {
return $self->{'seq'}->down_chain2string($start,undef,$end);
} else { my $str = $self->{'seq'}->up_chain2string($start,undef,$end);
$str =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/;
return $str;
} } |
sub source
{ my ($self,$value) = @_;
if (defined $value) {
$self->{'source'} = $value;
}
unless (exists $self->{'source'}) {
return "unknown";
} else {
return $self->{'source'};
} } |
sub start
{ my ($self) = @_;
return $self->{'start'};
} |
sub strand
{ my ($self,$strand) = @_;
if ($strand) {
if (($strand != 1)&&($strand != -1)) {
$self->warn("strand information not changed because strand identifier not valid");
} else {
$self->{'strand'} = $strand;
}
}
return $self->{'strand'}; } |
sub subseq
{ my ($self,$pos1,$pos2,$length,$strand) = @_;
$strand=$self->strand;
my ($str,$startlabel,$endlabel);
if (defined ($length)) {
if ($length < 1) {
$self->warn("No sense asking for a subseq of length < 1");
return (-1);
}
}
unless (defined ($pos1)) {
$startlabel=$self->start;
} else {
if ($pos1 == 0) { $self->warn("Position cannot be 0!"); return (-1);
}
if ((defined ($pos2))&&($pos1>$pos2)) {
$self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
}
$startlabel=$self->label($pos1);
if ($startlabel < 1) {
$self->warn("position $pos1 not valid as start of subseq!"); return (-1);
}
}
unless (defined ($pos2)) {
unless (defined ($length)) {
$endlabel=$self->end;
}
} else {
if ($pos2 == 0) { $self->warn("Position cannot be 0!"); return (-1);
}
undef $length;
if ((defined ($pos1))&&($pos1>$pos2)) {
$self->warn("1st position($pos1) cannot be > 2nd position($pos2)!"); return (-1);
}
$endlabel=$self->label($pos2);
if ($endlabel < 1) {
$self->warn("position $pos2 not valid as end of subseq!"); return (-1);
}
}
if ($strand == 1) {
$str = $self->{'seq'}->down_chain2string($startlabel,$length,$endlabel);
} else { $str = $self->{'seq'}->up_chain2string($startlabel,$length,$endlabel);
$str =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/;
}
return $str; } |
sub valid
{ my ($self,$label)=@_;
my $checkme;
my @labels=$self->all_labels;
foreach $checkme (@labels) {
if ($label == $checkme) {
return (1); }
}
return (0);
} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bio.perl.org/MailList.html - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/
AUTHOR - Joseph A.L. Insana | Top |
Email:
Insana@ebi.ac.uk,
jinsana@gmx.netAddress:
EMBL Outstation, European Bioinformatics Institute
Wellcome Trust Genome Campus, Hinxton
Cambs. CB10 1SD, United Kingdom
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
Some note on the terminology/notation of method names:
label: a unique pointer to a single nucleotide
position: the position of a nucleotide according to a particular coordinate
system (e.g. counting downstream from a particular label taken as
number 1)
base: the one letter code for a nucleotide (i.e.: "a" "t" "c" "g")
a base is the "value" that an "element" of a "chain" can assume
(see documentation on the Chain datastructure if interested)