A test to ensure Bio::PrimarySeqI->trunc() doesn't use clone() for a Bio::Seq::RichSe...
[bioperl-live.git] / Bio / LiveSeq / Range.pm
blobeb1a3fff4152dfa137730047e88b0eb41b962032
2 # bioperl module for Bio::LiveSeq::Range
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Joseph Insana <insana@ebi.ac.uk> <jinsana@gmx.net>
8 # Copyright Joseph Insana
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::LiveSeq::Range - Range abstract class for LiveSeq
18 =head1 SYNOPSIS
20 # documentation needed
22 =head1 DESCRIPTION
24 This is used as parent for exon and intron classes.
26 =head1 AUTHOR - Joseph A.L. Insana
28 Email: Insana@ebi.ac.uk, jinsana@gmx.net
30 =head1 APPENDIX
32 The rest of the documentation details each of the object
33 methods. Internal methods are usually preceded with a _
35 =cut
37 # Let the code begin...
39 package Bio::LiveSeq::Range;
40 use strict;
41 use base qw(Bio::LiveSeq::SeqI);
43 =head2 new
45 Title : new
46 Usage : $range1 = Bio::LiveSeq::Range->new(-seq => $obj_ref,
47 -start => $beginlabel,
48 -end => $endlabel, -strand => 1);
50 Function: generates a new Bio::LiveSeq::Range
51 Returns : reference to a new object of class Range
52 Errorcode -1
53 Args : two labels, an obj_ref and an integer
54 strand 1=forward strand, strand -1=reverse strand
55 if strand not specified, it defaults to 1
56 the -seq argument must point to the underlying DNA LiveSeq object
58 =cut
60 sub new {
61 my ($thing, %args) = @_;
62 my $class = ref($thing) || $thing;
63 my ($obj,%range);
65 my ($seq,$start,$end,$strand)=($args{-seq},$args{-start},$args{-end},$args{-strand});
67 $obj = \%range;
68 $obj = bless $obj, $class;
70 unless ($seq->valid($start)) {
71 $obj->warn("$class not initialised because start label not valid");
72 return (-1);
74 unless ($seq->valid($end)) {
75 $obj->warn("$class not initialised because end label not valid");
76 return (-1);
78 unless (defined $strand) {
79 $strand = 1;
81 if (($strand != 1)&&($strand != -1)) {
82 $obj->warn("$class not initialised because strand identifier not valid. Use 1 (forward strand) or -1 (reverse strand).");
83 return (-1);
85 if ($start eq $end) {
86 $obj->warn("$class reports: start and end label are the same....");
87 } else {
88 unless ($seq->follows($start,$end,$strand)==1) {
89 $obj->warn("Fatal: end label $end doesn't follow start label $start for strand $strand!");
90 return (-1);
93 #if ($strand == 1) {
94 # unless ($seq->is_downstream($start,$end)==1) {
95 # croak "Fatal: end label not downstream of start label for forward strand!";
96 # }
97 #} else {
98 # unless ($seq->is_upstream($start,$end)==1) {
99 # croak "Fatal: end label not upstream of start label for reverse strand!";
102 $obj->{'seq'}=$seq;
103 $obj->{'start'}=$start;
104 $obj->{'end'}=$end;
105 $obj->{'strand'}=$strand;
106 return $obj;
109 =head2 valid
111 Title : valid
112 Usage : $boolean = $obj->valid($label)
113 Function: tests if a label exists AND is part of the object
114 Returns : boolean
115 Args : label
117 =cut