/usr/share/perl5/Bio/Seq/LargeLocatableSeq.pm is in libbio-perl-perl 1.6.924-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | # BioPerl module for Bio::Seq::LargeLocatableSeq
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Albert Vilella
#
# based on the Bio::LargePrimarySeq module
# by Ewan Birney <birney@sanger.ac.uk>
#
# and the Bio::LocatableSeq module
# by Ewan Birney <birney@sanger.ac.uk>
#
# Copyright Albert Vilella
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::Seq::LargeLocatableSeq - LocatableSeq object that stores sequence as
files in the tempdir
=head1 SYNOPSIS
# normal primary seq usage
use Bio::Seq::LargeLocatableSeq;
my $seq = Bio::Seq::LargeLocatableSeq->new(-seq => "CAGT-GGT",
-id => "seq1",
-start => 1,
-end => 7);
=head1 DESCRIPTION
Bio::Seq::LargeLocatableSeq - object with start/end points on it that
can be projected into a MSA or have coordinates relative to another
seq.
This object, unlike Bio::LocatableSeq, stores a sequence as a series
of files in a temporary directory. The aim is to allow someone the
ability to store very large sequences (eg, E<gt> 100MBases) in a file
system without running out of memory (eg, on a 64 MB real memory
machine!).
Of course, to actually make use of this functionality, the programs
which use this object B<must> not call $primary_seq-E<gt>seq otherwise
the entire sequence will come out into memory and probably crash your
machine. However, calls like $primary_seq-E<gt>subseq(10,100) will cause
only 90 characters to be brought into real memory.
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
https://github.com/bioperl/bioperl-live/issues
=head1 AUTHOR - Albert Vilella
Email avilella-AT-gmail-DOT-com
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
# Let the code begin...
package Bio::Seq::LargeLocatableSeq;
use vars qw($AUTOLOAD);
use strict;
use base qw(Bio::Seq::LargePrimarySeq Bio::LocatableSeq Bio::Root::IO);
=head2 new
Title : new
Usage : my $obj = Bio::Seq::LargeLocatableSeq->new();
Function: Builds a new Bio::Seq::LargeLocatableSeq object
Returns : an instance of Bio::Seq::LargeLocatableSeq
Args :
=cut
sub new {
my ($class, %params) = @_;
# don't let PrimarySeq set seq until we have
# opened filehandle
my $seq = $params{'-seq'} || $params{'-SEQ'};
if($seq ) {
delete $params{'-seq'};
delete $params{'-SEQ'};
}
my $self = $class->SUPER::new(%params);
my $mapping = exists $params{'-mapping'} ? $params{'-mapping'} : [1,1];
$self->mapping($mapping);
$self->_initialize_io(%params);
my $tempdir = $self->tempdir( CLEANUP => 1);
my ($tfh,$file) = $self->tempfile( DIR => $tempdir );
$tfh && $self->_fh($tfh);
$file && $self->_filename($file);
$self->length(0);
$seq && $self->seq($seq);
return $self;
}
=head2 length
Title : length
Usage :
Function:
Example :
Returns :
Args :
=cut
sub length {
my ($obj,$value) = @_;
if( defined $value) {
$obj->{'length'} = $value;
}
return (defined $obj->{'length'}) ? $obj->{'length'} : 0;
}
=head2 seq
Title : seq
Usage :
Function:
Example :
Returns :
Args :
=cut
sub seq {
my ($self, $data) = @_;
if( defined $data ) {
if( $self->length() == 0) {
$self->add_sequence_as_string($data);
} else {
$self->warn("Trying to reset the seq string, cannot do this with a LargeLocatableSeq - must allocate a new object");
}
}
return $self->subseq(1,$self->length);
}
=head2 subseq
Title : subseq
Usage :
Function:
Example :
Returns :
Args :
=cut
sub subseq{
my ($self,$start,$end) = @_;
my $string;
my $fh = $self->_fh();
if( ref($start) && $start->isa('Bio::LocationI') ) {
my $loc = $start;
if( $loc->length == 0 ) {
$self->warn("Expect location lengths to be > 0");
return '';
} elsif( $loc->end < $loc->start ) {
# what about circular seqs
$self->warn("Expect location start to come before location end");
}
my $seq = '';
if( $loc->isa('Bio::Location::SplitLocationI') ) {
foreach my $subloc ( $loc->sub_Location ) {
if(! seek($fh,$subloc->start() - 1,0)) {
$self->throw("Unable to seek on file $start:$end $!");
}
my $ret = read($fh, $string, $subloc->length());
if( !defined $ret ) {
$self->throw("Unable to read $start:$end $!");
}
if( $subloc->strand < 0 ) {
# $string = Bio::PrimarySeq->new(-seq => $string)->revcom()->seq();
$string = Bio::Seq::LargePrimarySeq->new(-seq => $string)->revcom()->seq();
}
$seq .= $string;
}
} else {
if(! seek($fh,$loc->start()-1,0)) {
$self->throw("Unable to seek on file ".$loc->start.":".
$loc->end ." $!");
}
my $ret = read($fh, $string, $loc->length());
if( !defined $ret ) {
$self->throw("Unable to read ".$loc->start.":".
$loc->end ." $!");
}
$seq = $string;
}
if( defined $loc->strand &&
$loc->strand < 0 ) {
# $seq = Bio::PrimarySeq->new(-seq => $string)->revcom()->seq();
$seq = Bio::Seq::LargePrimarySeq->new(-seq => $seq)->revcom()->seq();
}
return $seq;
}
if( $start <= 0 || $end > $self->length ) {
$self->throw("Attempting to get a subseq out of range $start:$end vs ".
$self->length);
}
if( $end < $start ) {
$self->throw("Attempting to subseq with end ($end) less than start ($start). To revcom use the revcom function with trunc");
}
if(! seek($fh,$start-1,0)) {
$self->throw("Unable to seek on file $start:$end $!");
}
my $ret = read($fh, $string, $end-$start+1);
if( !defined $ret ) {
$self->throw("Unable to read $start:$end $!");
}
return $string;
}
=head2 add_sequence_as_string
Title : add_sequence_as_string
Usage : $seq->add_sequence_as_string("CATGAT");
Function: Appends additional residues to an existing LargeLocatableSeq object.
This allows one to build up a large sequence without storing
entire object in memory.
Returns : Current length of sequence
Args : string to append
=cut
sub add_sequence_as_string{
my ($self,$str) = @_;
my $len = $self->length + CORE::length($str);
my $fh = $self->_fh();
if(! seek($fh,0,2)) {
$self->throw("Unable to seek end of file: $!");
}
$self->_print($str);
$self->length($len);
}
=head2 _filename
Title : _filename
Usage : $obj->_filename($newval)
Function:
Example :
Returns : value of _filename
Args : newvalue (optional)
=cut
sub _filename{
my ($obj,$value) = @_;
if( defined $value) {
$obj->{'_filename'} = $value;
}
return $obj->{'_filename'};
}
=head2 alphabet
Title : alphabet
Usage : $obj->alphabet($newval)
Function:
Example :
Returns : value of alphabet
Args : newvalue (optional)
=cut
sub alphabet{
my ($self,$value) = @_;
if( defined $value) {
$self->SUPER::alphabet($value);
}
return $self->SUPER::alphabet() || 'dna';
}
sub DESTROY {
my $self = shift;
my $fh = $self->_fh();
close($fh) if( defined $fh );
# this should be handled by Tempfile removal, but we'll unlink anyways.
unlink $self->_filename() if defined $self->_filename() && -e $self->_filename;
$self->SUPER::DESTROY();
}
1;
|