18
18
use Bio::Location::Simple;
20
my $location = Bio::Location::Simple->new(-start => 1, -end => 100,
20
my $location = Bio::Location::Simple->new(
23
26
if( $location->strand == -1 ) {
24
printf "complement(%d..%d)\n", $location->start, $location->end;
27
printf "complement(%d..%d)\n", $location->start, $location->end;
26
printf "%d..%d\n", $location->start, $location->end;
29
printf "%d..%d\n", $location->start, $location->end;
107
110
Function: get/set the start of this range
108
111
Returns : the start of this range
109
112
Args : optionaly allows the start to be set
110
: using $loc->start($start)
113
using $loc->start($start)
115
my ($self, $value) = @_;
118
my ($self, $value) = @_;
116
119
$self->{'_start'} = $value if defined $value ;
118
121
$self->throw("Only adjacent residues when location type ".
134
137
Args : optionaly allows the end to be set
135
138
: using $loc->end($start)
136
139
Note : If start is set but end is undefined, this now assumes that start
137
is the same as end but throws a warning (i.e. it assumes this is
138
a possible error). If start is undefined, this now throws an
140
is the same as end but throws a warning (i.e. it assumes this is
141
a possible error). If start is undefined, this now throws an
144
my ($self, $value) = @_;
146
$self->{'_end'} = $value if defined $value ;
148
#assume end is the same as start if not defined
149
if (!defined $self->{'_end'}) {
150
if (!defined $self->{'_start'}) {
151
$self->warn('Can not set Bio::Location::Simple::end() equal to start; start not set');
154
$self->warn('Setting end to equal start['. $self->{'_start'}. ']');
155
$self->{'_end'} = $self->{'_start'};
157
$self->throw("Only adjacent residues when location type ".
158
"is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
159
$self->{'_end'}. "]" )
160
if defined $self->{'_start'} && defined $self->{'_end'} &&
161
$self->location_type eq 'IN-BETWEEN' &&
162
($self->{'_end'} - 1 != $self->{'_start'});
164
return $self->{'_end'};
147
my ($self, $value) = @_;
149
$self->{'_end'} = $value if defined $value ;
151
# Assume end is the same as start if not defined
152
if (!defined $self->{'_end'}) {
153
if (!defined $self->{'_start'}) {
154
$self->warn('Can not set Bio::Location::Simple::end() equal to start; start not set');
157
$self->warn('Setting end to equal start['. $self->{'_start'}. ']');
158
$self->{'_end'} = $self->{'_start'};
160
$self->throw("Only adjacent residues when location type ".
161
"is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
162
$self->{'_end'}. "]" )
163
if defined $self->{'_start'} && defined $self->{'_end'} &&
164
$self->location_type eq 'IN-BETWEEN' &&
165
($self->{'_end'} - 1 != $self->{'_start'});
167
return $self->{'_end'};
281
284
my ($self, $value) = @_;
283
286
if( defined $value || ! defined $self->{'_location_type'} ) {
284
$value = 'EXACT' unless defined $value;
286
if (! defined $RANGEDECODE{$value}) {
287
$value = '\^' if $value eq '^';
288
$value = '\.\.' if $value eq '..';
289
$value = $RANGEENCODE{$value};
291
$self->throw("Did not specify a valid location type. [$value] is no good")
292
unless defined $value;
293
$self->{'_location_type'} = $value;
287
$value = 'EXACT' unless defined $value;
289
if (! defined $RANGEDECODE{$value}) {
290
$value = '\^' if $value eq '^';
291
$value = '\.\.' if $value eq '..';
292
$value = $RANGEENCODE{$value};
294
$self->throw("Did not specify a valid location type. [$value] is no good")
295
unless defined $value;
296
$self->{'_location_type'} = $value;
295
298
$self->throw("Only adjacent residues when location type ".
296
"is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
297
$self->{'_end'}. "]" )
298
if $self->{'_location_type'} eq 'IN-BETWEEN' &&
299
"is IN-BETWEEN. Not [". $self->{'_start'}. "] and [".
300
$self->{'_end'}. "]" )
301
if $self->{'_location_type'} eq 'IN-BETWEEN' &&
299
302
defined $self->{'_start'} &&
300
303
defined $self->{'_end'} &&
301
304
($self->{'_end'} - 1 != $self->{'_start'});
345
348
if( $self->start == $self->end ) {
348
351
$str = $self->start . $RANGEDECODE{$self->location_type} . $self->end;
350
353
if($self->is_remote() && $self->seq_id()) {
351
$str = $self->seq_id() . ":" . $str;
354
$str = $self->seq_id() . ":" . $str;
353
356
if( defined $self->strand &&
354
$self->strand == -1 ) {
355
$str = "complement(".$str.")";
357
$self->strand == -1 ) {
358
$str = "complement(".$str.")";
360
364
=head2 valid_Location
362
366
Title : valid_Location
373
377
# trunc is untested, and as of now unannounced method for truncating a
374
378
# location. This is to eventually be part of the procedure to
375
# truncate a sequence with annotatioin and properly remap the location
379
# truncate a sequence with annotation and properly remap the location
376
380
# of all the features contained within the truncated segment.
378
382
# presumably this might do things a little differently for the case
381
385
# in short- you probably don't want to use this method.
384
my ($self,$start,$end,$relative_ori) = @_;
385
my $newstart = $self->start - $start+1;
386
my $newend = $self->end - $start+1;
387
my $newstrand = $relative_ori * $self->strand;
390
if( $newstart < 1 || $newend > ($end-$start+1) ) {
391
$out = Bio::Location::Simple->new();
392
$out->start($self->start);
393
$out->end($self->end);
394
$out->strand($self->strand);
395
$out->seq_id($self->seqid);
398
$out = Bio::Location::Simple->new();
399
$out->start($newstart);
401
$out->strand($newstrand);
388
my ($self,$start,$end,$relative_ori) = @_;
389
my $newstart = $self->start - $start+1;
390
my $newend = $self->end - $start+1;
391
my $newstrand = $relative_ori * $self->strand;
394
if( $newstart < 1 || $newend > ($end-$start+1) ) {
395
$out = Bio::Location::Simple->new();
396
$out->start($self->start);
397
$out->end($self->end);
398
$out->strand($self->strand);
399
$out->seq_id($self->seqid);
402
$out = Bio::Location::Simple->new();
403
$out->start($newstart);
405
$out->strand($newstrand);