[bug 2714]
[bioperl-live.git] / Bio / Assembly / Singlet.pm
blob96f44eee3ae85d39af32db9bff245ef8e7018cc5
1 # $Id$
3 # BioPerl module for Bio::Assembly::Singlet
4 #
5 # Cared for by Chad Matsalla <bioinformatics1 at dieselwurks.com>
7 # Copyright Chad Matsalla
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::Assembly::Singlet - Perl module to hold and manipulate
16 singlets from sequence assembly contigs.
18 =head1 SYNOPSIS
20 # Module loading
21 use Bio::Assembly::IO;
23 # Assembly loading methods
24 $aio = Bio::Assembly::IO->new( -file => 'test.ace.1',
25 -format => 'phrap' );
27 $assembly = $aio->next_assembly;
28 foreach $singlet ($assembly->all_singlets) {
29 # do something
32 # OR, if you want to build the singlet yourself,
34 use Bio::Assembly::Singlet;
35 $singlet = Bio::Assembly::Singlet->new( -seqref => $seq );
37 =head1 DESCRIPTION
39 A singlet is a sequence that phrap was unable to align to any other sequences.
41 =head1 FEEDBACK
43 =head2 Mailing Lists
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to the
47 Bioperl mailing lists Your participation is much appreciated.
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
52 =head2 Reporting Bugs
54 Report bugs to the Bioperl bug tracking system to help us keep track
55 the bugs and their resolution. Bug reports can be submitted via the
56 web:
58 http://bugzilla.open-bio.org/
60 =head1 AUTHOR - Chad S. Matsalla
62 bioinformatics1 at dieselwurks.com
64 =head1 APPENDIX
66 The rest of the documentation details each of the object
67 methods. Internal methods are usually preceded with a _
69 =cut
72 package Bio::Assembly::Singlet;
74 use strict;
76 use Bio::SeqFeature::Collection;
77 use Bio::Seq::PrimaryQual;
78 use base qw(Bio::Assembly::Contig Bio::Root::Root Bio::Align::AlignI);
80 =head2 new
82 Title : new
83 Usage : $singlet = $io->new( -seqref => $seq )
84 Function: Create a new singlet object
85 Returns : A Bio::Assembly::Singlet object
86 Args : -seqref => Bio::Seq-compliant sequence object for the singlet
88 =cut
90 sub new {
91 my ($class, @args) = @_;
92 my $self = $class->SUPER::new(@args);
93 my ($seqref) = $self->_rearrange([qw(SEQREF)], @args);
94 $self->{'_seqref'} = undef;
95 if (defined $seqref) {
96 $self->seqref($seqref);
98 return $self;
101 =head2 seqref
103 Title : seqref
104 Usage : $seqref = $singlet->seqref($seq);
105 Function: Get/set the sequence to which this singlet refers
106 Returns : A Bio::Seq-compliant object
107 Args : A Bio::Seq-compliant object
109 =cut
111 sub seqref {
112 my ($self,$seq) = @_;
113 if (defined $seq) { $self->_seq_to_singlet($seq) };
114 return $self->{'_seqref'};
117 =head2 _seq_to_singlet
119 Title : _seq_to_singlet
120 Usage : $singlet->seqref($seq)
121 Function: Transform a sequence into a singlet
122 Returns : A Bio::Assembly::Singlet object
123 Args : A Bio::Seq-compliant object
125 =cut
127 sub _seq_to_singlet {
128 my ($self, $seq) = @_;
129 # Object type checking
130 $self->throw("Unable to process non Bio::Seq-compliant object [".ref($seq)."]")
131 unless (defined $seq && ($seq->isa("Bio::Seq") || $seq->isa("Bio::LocatableSeq")) );
132 # Sanity check
133 $self->throw("Unable to have more than one seqref in a singlet")
134 if (defined $self->{'_seqref'});
135 # From sequence to locatable sequence
136 my $seq_id = $seq->id();
137 my $lseq = Bio::LocatableSeq->new(
138 -seq => $seq->seq(),
139 -start => 1,
140 -end => $seq->length(),
141 -strand => 1,
142 -id => $seq_id
144 # Add new sequence
145 $self->add_seq($lseq);
146 # Creating singlet ID, seqref and consensus
147 $self->id($seq_id);
148 $self->{'_seqref'} = $seq;
149 $self->set_consensus_sequence($lseq);
150 if ($seq->isa("Bio::Seq::Quality")) {
151 $self->set_consensus_quality($seq);
153 return;