3 # BioPerl module for Bio::Align::AlignI
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Align::AlignI - An interface for describing sequence alignments.
21 # get a Bio::Align::AlignI somehow - typically using Bio::AlignIO system
23 print $aln->length, "\n";
24 print $aln->num_residues, "\n";
25 print $aln->is_flush, "\n";
26 print $aln->num_sequences, "\n";
27 print $aln->percentage_identity, "\n";
28 print $aln->consensus_string(50), "\n";
30 # find the position in the alignment for a sequence location
31 $pos = $aln->column_from_residue_number('1433_LYCES', 14); # = 6;
33 # extract sequences and check values for the alignment column $pos
34 foreach $seq ($aln->each_seq) {
35 $res = $seq->subseq($pos, $pos);
38 foreach $res (keys %count) {
39 printf "Res: %s Count: %2d\n", $res, $count{$res};
44 This interface describes the basis for alignment objects.
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to
52 the Bioperl mailing list. Your participation is much appreciated.
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
59 Please direct usage questions or support issues to the mailing list:
61 I<bioperl-l@bioperl.org>
63 rather than to the module maintainer directly. Many experienced and
64 reponsive experts will be able look at the problem and quickly
65 address it. Please include a thorough description of the problem
66 with code and data examples if at all possible.
70 Report bugs to the Bioperl bug tracking system to help us keep track
71 of the bugs and their resolution. Bug reports can be submitted via the
74 http://bugzilla.open-bio.org/
76 =head1 AUTHOR - Jason Stajich
78 Email jason@bioperl.org
82 Ewan Birney, birney@ebi.ac.uk
83 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
87 The rest of the documentation details each of the object methods.
88 Internal methods are usually preceded with a _
93 # Let the code begin...
96 package Bio
::Align
::AlignI
;
100 use base
qw(Bio::Root::RootI);
102 =head1 Modifier methods
104 These methods modify the MSE by adding, removing or shuffling complete
110 Usage : $myalign->add_seq($newseq);
111 Function : Adds another sequence to the alignment. *Does not* align
112 it - just adds it to the hashes.
114 Argument : a Bio::LocatableSeq object
117 See L<Bio::LocatableSeq> for more information.
123 $self->throw_not_implemented();
129 Usage : $aln->remove_seq($seq);
130 Function : Removes a single sequence from an alignment
132 Argument : a Bio::LocatableSeq object
138 $self->throw_not_implemented();
144 Usage : $aln->purge(0.7);
147 Removes sequences above whatever %id.
149 This function will grind on large alignments. Beware!
150 (perhaps not ideally implemented)
153 Returns : An array of the removed sequences
161 $self->throw_not_implemented();
164 =head2 sort_alphabetically
166 Title : sort_alphabetically
167 Usage : $ali->sort_alphabetically
170 Changes the order of the alignment to alphabetical on name
171 followed by numerical by number.
178 sub sort_alphabetically
{
180 $self->throw_not_implemented();
183 =head1 Sequence selection methods
185 Methods returning one or more sequences objects.
190 Usage : foreach $seq ( $align->each_seq() )
191 Function : Gets an array of Seq objects from the alignment
199 $self->throw_not_implemented();
202 =head2 each_alphabetically
204 Title : each_alphabetically
205 Usage : foreach $seq ( $ali->each_alphabetically() )
208 Returns an array of sequence object sorted alphabetically
209 by name and then by start point.
210 Does not change the order of the alignment
217 sub each_alphabetically
{
219 $self->throw_not_implemented();
222 =head2 each_seq_with_id
224 Title : each_seq_with_id
225 Usage : foreach $seq ( $align->each_seq_with_id() )
228 Gets an array of Seq objects from the
229 alignment, the contents being those sequences
230 with the given name (there may be more than one)
233 Argument : a seq name
237 sub each_seq_with_id
{
239 $self->throw_not_implemented();
242 =head2 get_seq_by_pos
244 Title : get_seq_by_pos
245 Usage : $seq = $aln->get_seq_by_pos(3) # third sequence from the alignment
248 Gets a sequence based on its position in the alignment.
249 Numbering starts from 1. Sequence positions larger than
250 num_sequences() will throw an error.
252 Returns : a Bio::LocatableSeq object
253 Argument : positive integer for the sequence position
259 $self->throw_not_implemented();
262 =head1 Create new alignments
264 The result of these methods are horizontal or vertical subsets of the
270 Usage : $aln2 = $aln->select(1, 3) # three first sequences
273 Creates a new alignment from a continuous subset of
274 sequences. Numbering starts from 1. Sequence positions
275 larger than num_sequences() will throw an error.
277 Returns : a Bio::SimpleAlign object
278 Argument : positive integer for the first sequence
279 positive integer for the last sequence to include (optional)
285 $self->throw_not_implemented();
289 =head2 select_noncont
291 Title : select_noncont
292 Usage : $aln2 = $aln->select_noncont(1, 3) # first and 3rd sequences
295 Creates a new alignment from a subset of
296 sequences. Numbering starts from 1. Sequence positions
297 larger than num_sequences() will throw an error.
299 Returns : a Bio::SimpleAlign object
300 Args : array of integers for the sequences
306 $self->throw_not_implemented();
312 Usage : $aln2 = $aln->slice(20, 30)
315 Creates a slice from the alignment inclusive of start and
316 end columns. Sequences with no residues in the slice are
317 excluded from the new alignment and a warning is printed.
318 Slice beyond the length of the sequence does not do
321 Returns : a Bio::SimpleAlign object
322 Argument : positive integer for start column
323 positive integer for end column
329 $self->throw_not_implemented();
332 =head1 Change sequences within the MSE
334 These methods affect characters in all sequences without changing the
341 Usage : $ali->map_chars('\.','-')
344 Does a s/$arg1/$arg2/ on the sequences. Useful for gap
347 Notice that the from (arg1) is interpreted as a regex,
348 so be careful about quoting meta characters (eg
349 $ali->map_chars('.','-') wont do what you want)
352 Argument : 'from' rexexp
359 $self->throw_not_implemented();
365 Usage : $ali->uppercase()
366 Function : Sets all the sequences to uppercase
374 $self->throw_not_implemented();
380 Usage : $align->match_line()
381 Function : Generates a match line - much like consensus string
382 except that a line indicating the '*' for a match.
383 Argument : (optional) Match line characters ('*' by default)
384 (optional) Strong match char (':' by default)
385 (optional) Weak match char ('.' by default)
391 $self->throw_not_implemented();
397 Usage : $ali->match()
400 Goes through all columns and changes residues that are
401 identical to residue in first sequence to match '.'
402 character. Sets match_char.
404 USE WITH CARE: Most MSE formats do not support match
405 characters in sequences, so this is mostly for output
406 only. NEXUS format (Bio::AlignIO::nexus) can handle
410 Argument : a match character, optional, defaults to '.'
416 $self->throw_not_implemented();
422 Usage : $ali->unmatch()
425 Undoes the effect of method match. Unsets match_char.
428 Argument : a match character, optional, defaults to '.'
434 $self->throw_not_implemented();
440 Methods for setting and reading the MSE attributes.
442 Note that the methods defining character semantics depend on the user
443 to set them sensibly. They are needed only by certain input/output
444 methods. Unset them by setting to an empty string ('').
449 Usage : $myalign->id("Ig")
450 Function : Gets/sets the id field of the alignment
451 Returns : An id string
452 Argument : An id string (optional)
458 $self->throw_not_implemented();
464 Usage : $myalign->missing_char("?")
465 Function : Gets/sets the missing_char attribute of the alignment
466 It is generally recommended to set it to 'n' or 'N'
467 for nucleotides and to 'X' for protein.
468 Returns : An missing_char string,
469 Argument : An missing_char string (optional)
475 $self->throw_not_implemented();
481 Usage : $myalign->match_char('.')
482 Function : Gets/sets the match_char attribute of the alignment
483 Returns : An match_char string,
484 Argument : An match_char string (optional)
490 $self->throw_not_implemented();
496 Usage : $myalign->gap_char('-')
497 Function : Gets/sets the gap_char attribute of the alignment
498 Returns : An gap_char string, defaults to '-'
499 Argument : An gap_char string (optional)
505 $self->throw_not_implemented();
511 Usage : my @symbolchars = $aln->symbol_chars;
512 Function: Returns all the seen symbols (other than gaps)
513 Returns : array of characters that are the seen symbols
514 Argument: boolean to include the gap/missing/match characters
520 $self->throw_not_implemented();
523 =head1 Alignment descriptors
525 These read only methods describe the MSE in various ways.
528 =head2 consensus_string
530 Title : consensus_string
531 Usage : $str = $ali->consensus_string($threshold_percent)
532 Function : Makes a strict consensus
533 Returns : consensus string
534 Argument : Optional threshold ranging from 0 to 100.
535 The consensus residue has to appear at least threshold %
536 of the sequences at a given location, otherwise a '?'
537 character will be placed at that location.
542 sub consensus_string
{
544 $self->throw_not_implemented();
547 =head2 consensus_iupac
549 Title : consensus_iupac
550 Usage : $str = $ali->consensus_iupac()
553 Makes a consensus using IUPAC ambiguity codes from DNA
554 and RNA. The output is in upper case except when gaps in
555 a column force output to be in lower case.
557 Note that if your alignment sequences contain a lot of
558 IUPAC ambiquity codes you often have to manually set
559 alphabet. Bio::PrimarySeq::_guess_type thinks they
560 indicate a protein sequence.
562 Returns : consensus string
564 Throws : on protein sequences
569 sub consensus_iupac
{
571 $self->throw_not_implemented();
577 Usage : if( $ali->is_flush() )
580 Function : Tells you whether the alignment
581 : is flush, ie all of the same length
591 $self->throw_not_implemented();
597 Usage : $len = $ali->length()
598 Function : Returns the maximum length of the alignment.
599 To be sure the alignment is a block, use is_flush
607 $self->throw_not_implemented();
610 =head2 maxname_length
612 Title : maxname_length
613 Usage : $ali->maxname_length()
616 Gets the maximum length of the displayname in the
617 alignment. Used in writing out various MSE formats.
626 $self->throw_not_implemented();
632 Usage : $no = $ali->num_residues
633 Function : number of residues in total in the alignment
636 Note : replaces no_residues
642 $self->throw_not_implemented();
647 Title : num_sequences
648 Usage : $depth = $ali->num_sequences
649 Function : number of sequence in the sequence alignment
652 Note : replaces no_sequences
658 $self->throw_not_implemented();
661 =head2 percentage_identity
663 Title : percentage_identity
664 Usage : $id = $align->percentage_identity
665 Function: The function calculates the percentage identity of the alignment
666 Returns : The percentage identity of the alignment (as defined by the
672 sub percentage_identity
{
674 $self->throw_not_implemented();
677 =head2 overall_percentage_identity
679 Title : overall_percentage_identity
680 Usage : $id = $align->overall_percentage_identity
681 Function: The function calculates the percentage identity of
682 the conserved columns
683 Returns : The percentage identity of the conserved columns
688 sub overall_percentage_identity
{
690 $self->throw_not_implemented();
694 =head2 average_percentage_identity
696 Title : average_percentage_identity
697 Usage : $id = $align->average_percentage_identity
698 Function: The function uses a fast method to calculate the average
699 percentage identity of the alignment
700 Returns : The average percentage identity of the alignment
705 sub average_percentage_identity
{
707 $self->throw_not_implemented();
710 =head1 Alignment positions
712 Methods to map a sequence position into an alignment column and back.
713 column_from_residue_number() does the former. The latter is really a
714 property of the sequence object and can done using
715 L<Bio::LocatableSeq::location_from_column>:
717 # select somehow a sequence from the alignment, e.g.
718 my $seq = $aln->get_seq_by_pos(1);
719 #$loc is undef or Bio::LocationI object
720 my $loc = $seq->location_from_column(5);
723 =head2 column_from_residue_number
725 Title : column_from_residue_number
726 Usage : $col = $ali->column_from_residue_number( $seqname, $resnumber)
729 This function gives the position in the alignment
730 (i.e. column number) of the given residue number in the
731 sequence with the given name. For example, for the
734 Seq1/91-97 AC..DEF.GH
735 Seq2/24-30 ACGG.RTY..
736 Seq3/43-51 AC.DDEFGHI
738 column_from_residue_number( "Seq1", 94 ) returns 6.
739 column_from_residue_number( "Seq2", 25 ) returns 2.
740 column_from_residue_number( "Seq3", 50 ) returns 9.
742 An exception is thrown if the residue number would lie
743 outside the length of the alignment
744 (e.g. column_from_residue_number( "Seq2", 22 )
746 Note: If the parent sequence is represented by more than one
747 alignment sequence and the residue number is present in
748 them, this method finds only the first one.
750 Returns : A column number for the position in the alignment of the
751 given residue in the given sequence (1 = first column)
752 Args : A sequence id/name (not a name/start-end)
753 A residue number in the whole sequence (not just that
754 segment of it in the alignment)
758 sub column_from_residue_number
{
760 $self->throw_not_implemented();
763 =head1 Sequence names
765 Methods to manipulate the display name. The default name based on the
766 sequence id and subsequence positions can be overridden in various
772 Usage : $myalign->displayname("Ig", "IgA")
773 Function : Gets/sets the display name of a sequence in the alignment
775 Returns : A display name string
776 Argument : name of the sequence
777 displayname of the sequence (optional)
783 $self->throw_not_implemented();
786 =head2 set_displayname_count
788 Title : set_displayname_count
789 Usage : $ali->set_displayname_count
792 Sets the names to be name_# where # is the number of
793 times this name has been used.
800 sub set_displayname_count
{
802 $self->throw_not_implemented();
805 =head2 set_displayname_flat
807 Title : set_displayname_flat
808 Usage : $ali->set_displayname_flat()
809 Function : Makes all the sequences be displayed as just their name,
816 sub set_displayname_flat
{
818 $self->throw_not_implemented();
821 =head2 set_displayname_normal
823 Title : set_displayname_normal
824 Usage : $ali->set_displayname_normal()
825 Function : Makes all the sequences be displayed as name/start-end
831 sub set_displayname_normal
{
833 $self->throw_not_implemented();
836 =head1 Deprecated methods
841 Usage : $no = $ali->no_residues
842 Function : number of residues in total in the alignment
845 Note : deprecated in favor of num_residues()
850 # immediate deprecation
857 Usage : $depth = $ali->no_sequences
858 Function : number of sequence in the sequence alignment
861 Note : deprecated in favor of num_sequences()
866 # immediate deprecation