[bug 2621]
[bioperl-live.git] / Bio / Tools / EPCR.pm
blob01ed3a5bbc7204dd73c2441781390c8448e14c5e
1 # $Id$
3 # BioPerl module for Bio::Tools::EPCR
5 # Cared for by Jason Stajich <jason-at-bioperl.org>
7 # Copyright Jason Stajich
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::Tools::EPCR - Parse ePCR output and make features
17 =head1 SYNOPSIS
19 # A simple annotation pipeline wrapper for ePCR data
20 # assuming ePCR data is already generated in file seq1.epcr
21 # and sequence data is in fasta format in file called seq1.fa
23 use Bio::Tools::EPCR;
24 use Bio::SeqIO;
25 my $parser = Bio::Tools::EPCR->new(-file => 'seq1.epcr');
26 my $seqio = Bio::SeqIO->new(-format => 'fasta', -file => 'seq1.fa');
27 my $seq = $seqio->next_seq || die("cannot get a seq object from SeqIO");
29 while( my $feat = $parser->next_feature ) {
30 # add EPCR annotation to a sequence
31 $seq->add_SeqFeature($feat);
33 my $seqout = Bio::SeqIO->new(-format => 'embl');
34 $seqout->write_seq($seq);
37 =head1 DESCRIPTION
39 This object serves as a parser for ePCR data, creating a
40 Bio::SeqFeatureI for each ePCR hit. These can be processed or added
41 as annotation to an existing Bio::SeqI object for the purposes of
42 automated annotation.
44 =head1 FEEDBACK
46 =head2 Mailing Lists
48 User feedback is an integral part of the evolution of this and other
49 Bioperl modules. Send your comments and suggestions preferably to
50 the Bioperl mailing list. Your participation is much appreciated.
52 bioperl-l@bioperl.org - General discussion
53 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 =head2 Reporting Bugs
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via the
59 web:
61 http://bugzilla.open-bio.org/
63 =head1 AUTHOR - Jason Stajich
65 Email jason-at-bioperl.org
67 =head1 APPENDIX
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
72 =cut
75 # Let the code begin...
78 package Bio::Tools::EPCR;
79 use strict;
81 use Bio::SeqFeature::FeaturePair;
82 use Bio::SeqFeature::Generic;
84 use base qw(Bio::Root::Root Bio::SeqAnalysisParserI Bio::Root::IO);
86 =head2 new
88 Title : new
89 Usage : my $epcr = Bio::Tools::EPCR->new(-file => $file,
90 -primary => $fprimary,
91 -source => $fsource,
92 -groupclass => $fgroupclass);
93 Function: Initializes a new EPCR parser
94 Returns : Bio::Tools::EPCR
95 Args : -fh => filehandle
97 -file => filename
99 -primary => a string to be used as the common value for
100 each features '-primary' tag. Defaults to
101 'sts'. (This in turn maps to the GFF 'type'
102 tag (aka 'method')).
104 -source => a string to be used as the common value for
105 each features '-source' tag. Defaults to
106 'e-PCR'. (This in turn maps to the GFF 'source'
107 tag)
109 -groupclass => a string to be used as the name of the tag
110 which will hold the sts marker namefirst
111 attribute. Defaults to 'name'.
113 =cut
115 sub new {
116 my($class,@args) = @_;
118 my $self = $class->SUPER::new(@args);
119 my ($primary, $source,
120 $groupclass) = $self->_rearrange([qw(PRIMARY
121 SOURCE
122 GROUPCLASS)],@args);
123 $self->primary(defined $primary ? $primary : 'sts');
124 $self->source(defined $source ? $source : 'e-PCR');
125 $self->groupclass(defined $groupclass ? $groupclass : 'name');
127 $self->_initialize_io(@args);
128 return $self;
131 =head2 next_feature
133 Title : next_feature
134 Usage : $seqfeature = $obj->next_feature();
135 Function: Returns the next feature available in the analysis result, or
136 undef if there are no more features.
137 Example :
138 Returns : A Bio::SeqFeatureI implementing object, or undef if there are no
139 more features.
140 Args : none
142 =cut
144 sub next_feature {
145 my ($self) = @_;
146 my $line = $self->_readline;
147 return unless defined($line);
148 chomp($line);
149 my($seqname,$location,$mkrname, $rest) = split(/\s+/,$line,4);
151 my ($start,$end) = ($location =~ /(\S+)\.\.(\S+)/);
153 # `e-PCR -direct` results code match strand in $rest as (+) and (-). Decode it if present.
154 my $strandsign;
155 if ($rest =~ m/^\(([+-])\)(.*)$/) {
156 ($strandsign,$rest) = ($1, $2);
157 } else {
158 $strandsign = "?";
160 my $strand = $strandsign eq "+" ? 1 : $strandsign eq "-" ? -1 : 0;
162 my $markerfeature = Bio::SeqFeature::Generic->new
163 ( '-start' => $start,
164 '-end' => $end,
165 '-strand' => $strand,
166 '-source' => $self->source,
167 '-primary' => $self->primary,
168 '-seq_id' => $seqname,
169 '-tag' => {
170 $self->groupclass => $mkrname,
171 ($rest ? ('Note' => $rest ) : ()),
173 #$markerfeature->add_tag_value('Note', $rest) if defined $rest;
174 return $markerfeature;
177 =head2 source
179 Title : source
180 Usage : $obj->source($newval)
181 Function:
182 Example :
183 Returns : value of source (a scalar)
184 Args : on set, new value (a scalar or undef, optional)
187 =cut
189 sub source{
190 my $self = shift;
191 return $self->{'_source'} = shift if @_;
192 return $self->{'_source'};
195 =head2 primary
197 Title : primary
198 Usage : $obj->primary($newval)
199 Function:
200 Example :
201 Returns : value of primary (a scalar)
202 Args : on set, new value (a scalar or undef, optional)
205 =cut
207 sub primary{
208 my $self = shift;
209 return $self->{'_primary'} = shift if @_;
210 return $self->{'_primary'};
213 =head2 groupclass
215 Title : groupclass
216 Usage : $obj->groupclass($newval)
217 Function:
218 Example :
219 Returns : value of groupclass (a scalar)
220 Args : on set, new value (a scalar or undef, optional)
223 =cut
225 sub groupclass{
226 my $self = shift;
228 return $self->{'_groupclass'} = shift if @_;
229 return $self->{'_groupclass'};