Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/SeqIO/raw.pm @ 0:1f6dce3d34e0
Uploaded
| author | mahtabm |
|---|---|
| date | Thu, 11 Apr 2013 02:01:53 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1f6dce3d34e0 |
|---|---|
| 1 #----------------------------------------------------------------------------- | |
| 2 # PACKAGE : Bio::SeqIO::raw | |
| 3 # AUTHOR : Ewan Birney <birney@ebi.ac.uk> | |
| 4 # CREATED : Feb 16 1999 | |
| 5 # REVISION: $Id: raw.pm,v 1.15.2.1 2003/02/05 21:55:21 jason Exp $ | |
| 6 # | |
| 7 # Copyright (c) 1997-9 bioperl, Ewan Birney. All Rights Reserved. | |
| 8 # This module is free software; you can redistribute it and/or | |
| 9 # modify it under the same terms as Perl itself. | |
| 10 # | |
| 11 # _History_ | |
| 12 # | |
| 13 # Ewan Birney <birney@ebi.ac.uk> developed the SeqIO | |
| 14 # schema and the first prototype modules. | |
| 15 # | |
| 16 # This code is based on his Bio::SeqIO::Fasta module with | |
| 17 # the necessary minor tweaks necessary to get it to read | |
| 18 # and write raw formatted sequences made by | |
| 19 # chris dagdigian <dag@sonsorol.org> | |
| 20 # | |
| 21 # October 18, 1999 Largely rewritten by Lincoln Stein | |
| 22 # | |
| 23 # Copyright Ewan Birney | |
| 24 # | |
| 25 # You may distribute this module under the same terms as perl itself | |
| 26 | |
| 27 # POD documentation - main docs before the code | |
| 28 | |
| 29 =head1 NAME | |
| 30 | |
| 31 Bio::SeqIO::raw - raw sequence file input/output stream | |
| 32 | |
| 33 =head1 SYNOPSIS | |
| 34 | |
| 35 Do not use this module directly. Use it via the L<Bio::SeqIO> class. | |
| 36 | |
| 37 =head1 DESCRIPTION | |
| 38 | |
| 39 This object can transform Bio::Seq objects to and from raw flat | |
| 40 file databases. | |
| 41 | |
| 42 | |
| 43 =head1 FEEDBACK | |
| 44 | |
| 45 =head2 Mailing Lists | |
| 46 | |
| 47 User feedback is an integral part of the evolution of this | |
| 48 and other Bioperl modules. Send your comments and suggestions preferably | |
| 49 to one of the Bioperl mailing lists. | |
| 50 Your participation is much appreciated. | |
| 51 | |
| 52 bioperl-l@bioperl.org - General discussion | |
| 53 http://www.bioperl.org/MailList.shtml - About the mailing lists | |
| 54 | |
| 55 =head2 Reporting Bugs | |
| 56 | |
| 57 Report bugs to the Bioperl bug tracking system to help us keep track | |
| 58 the bugs and their resolution. | |
| 59 Bug reports can be submitted via email or the web: | |
| 60 | |
| 61 bioperl-bugs@bio.perl.org | |
| 62 http://bugzilla.bioperl.org/ | |
| 63 | |
| 64 =head1 AUTHORS | |
| 65 | |
| 66 Ewan Birney E<lt>birney@ebi.ac.ukE<gt> | |
| 67 Lincoln Stein E<lt>lstein@cshl.orgE<gt> | |
| 68 | |
| 69 =head1 CONTRIBUTORS | |
| 70 | |
| 71 Jason Stajich E<lt>jason@bioperl.org<gt> | |
| 72 | |
| 73 =head1 APPENDIX | |
| 74 | |
| 75 The rest of the documentation details each of the object methods. | |
| 76 Internal methods are usually preceded with a _ | |
| 77 | |
| 78 =cut | |
| 79 | |
| 80 | |
| 81 # Let the code begin... | |
| 82 | |
| 83 package Bio::SeqIO::raw; | |
| 84 use strict; | |
| 85 use vars qw(@ISA); | |
| 86 | |
| 87 use Bio::SeqIO; | |
| 88 use Bio::Seq::SeqFactory; | |
| 89 | |
| 90 @ISA = qw(Bio::SeqIO); | |
| 91 | |
| 92 sub _initialize { | |
| 93 my($self,@args) = @_; | |
| 94 $self->SUPER::_initialize(@args); | |
| 95 if( ! defined $self->sequence_factory ) { | |
| 96 $self->sequence_factory(new Bio::Seq::SeqFactory | |
| 97 (-verbose => $self->verbose(), | |
| 98 -type => 'Bio::Seq')); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 =head2 next_seq | |
| 103 | |
| 104 Title : next_seq | |
| 105 Usage : $seq = $stream->next_seq() | |
| 106 Function: returns the next sequence in the stream | |
| 107 Returns : Bio::Seq object | |
| 108 Args : | |
| 109 | |
| 110 | |
| 111 =cut | |
| 112 | |
| 113 sub next_seq{ | |
| 114 my ($self,@args) = @_; | |
| 115 ## When its 1 sequence per line with no formatting at all, | |
| 116 ## grabbing it should be easy :) | |
| 117 | |
| 118 my $nextline = $self->_readline(); | |
| 119 if( !defined $nextline ){ return undef; } | |
| 120 | |
| 121 my $sequence = uc($nextline); | |
| 122 $sequence =~ s/\W//g; | |
| 123 | |
| 124 return $self->sequence_factory->create(-seq => $sequence); | |
| 125 } | |
| 126 | |
| 127 =head2 write_seq | |
| 128 | |
| 129 Title : write_seq | |
| 130 Usage : $stream->write_seq($seq) | |
| 131 Function: writes the $seq object into the stream | |
| 132 Returns : 1 for success and 0 for error | |
| 133 Args : Array of Bio::PrimarySeqI objects | |
| 134 | |
| 135 | |
| 136 =cut | |
| 137 | |
| 138 sub write_seq { | |
| 139 my ($self,@seq) = @_; | |
| 140 foreach my $seq (@seq) { | |
| 141 $self->throw("Must provide a valid Bio::PrimarySeqI object") | |
| 142 unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI'); | |
| 143 $self->_print($seq->seq, "\n") or return; | |
| 144 } | |
| 145 $self->flush if $self->_flush_on_write && defined $self->_fh; | |
| 146 return 1; | |
| 147 } | |
| 148 | |
| 149 =head2 write_qual | |
| 150 | |
| 151 Title : write_qual | |
| 152 Usage : $stream->write_qual($seq) | |
| 153 Function: writes the $seq object into the stream | |
| 154 Returns : 1 for success and 0 for error | |
| 155 Args : Bio::Seq object | |
| 156 | |
| 157 | |
| 158 =cut | |
| 159 | |
| 160 sub write_qual { | |
| 161 my ($self,@seq) = @_; | |
| 162 my @qual = (); | |
| 163 foreach (@seq) { | |
| 164 unless ($_->isa("Bio::Seq::SeqWithQuality")){ | |
| 165 warn("You cannot write raw qualities without supplying a Bio::Seq::SeqWithQuality object! You passed a ", ref($_), "\n"); | |
| 166 next; | |
| 167 } | |
| 168 @qual = @{$_->qual}; | |
| 169 if(scalar(@qual) == 0) { | |
| 170 $qual[0] = "\n"; | |
| 171 } | |
| 172 | |
| 173 $self->_print (join " ", @qual,"\n") or return; | |
| 174 | |
| 175 } | |
| 176 return 1; | |
| 177 } | |
| 178 1; |
