2
## Bioperl Test Harness Script for Modules
3
## $Id: seqwithquality.t,v 1.9 2005/07/11 14:40:49 heikki Exp $
9
# to handle systems with no installed Test module
10
# we include the t dir (where a copy of Test.pm is located)
12
eval { require Test; };
21
my $dumper = new Dumpvalue();
22
my $DEBUG = $ENV{'BIOPERLDEBUG'};
24
# redirect STDERR to STDOUT
25
open (STDERR, ">&STDOUT");
29
print("Checking if the Bio::Seq::SeqWithQuality module could be used...\n") if $DEBUG;
31
use Bio::Seq::SeqWithQuality;
35
use Bio::Seq::PrimaryQual;
37
# create some random sequence object with no id
38
my $seqobj_broken = Bio::PrimarySeq->new( -seq => "ATCGATCGA",
40
# dumpValue($seqobj_broken);
42
my $seqobj = Bio::PrimarySeq->new( -seq => "ATCGATCGA",
43
-id => 'QualityFragment-12',
44
-accession_number => 'X78121',
45
-verbose => $verbosity
50
# create some random quality object with the same number of qualities and the same identifiers
51
my $string_quals = "10 20 30 40 50 40 30 20 10";
52
my $indices = "5 10 15 20 25 30 35 40 45";
55
$qualobj = Bio::Seq::PrimaryQual->new( -qual => $string_quals,
56
-id => 'QualityFragment-12',
57
-accession_number => 'X78121',
58
-verbose => $verbosity
64
# check to see what happens when you construct the SeqWithQuality object
65
my $swq1 = Bio::Seq::SeqWithQuality->new( -seq => $seqobj,
66
-verbose => $verbosity,
71
print("Testing various weird constructors...\n") if $DEBUG;
72
print("\ta) No ids, Sequence object, no quality...\n") if $DEBUG;
76
$wswq1 = Bio::Seq::SeqWithQuality->new( -seq => $seqobj,
77
-verbose => $verbosity,
82
print("\tb) No ids, no sequence, quality object...\n") if $DEBUG;
83
# note that you must provide a alphabet for this one.
84
$wswq1 = Bio::Seq::SeqWithQuality->new( -seq => "",
85
-verbose => $verbosity,
89
print("\tc) Absolutely nothing. (HAHAHAHA)...\n") if $DEBUG;
91
$wswq1 = Bio::Seq::SeqWithQuality->new( -seq => "",
92
-verbose => $verbosity,
98
print("\td) Absolutely nothing but an ID\n") if $DEBUG;
100
$wswq1 = Bio::Seq::SeqWithQuality->new( -seq => "",
101
-verbose => $verbosity,
104
-id => 'an object with no sequence and no quality but with an id'
109
print("\td) No sequence, No quality, No ID...\n") if $DEBUG;
112
$wswq1 = Bio::Seq::SeqWithQuality->new( -seq => "",
113
-verbose => $verbosity,
116
# this should fail without a alphabet
124
print("Testing various methods and behaviors...\n") if $DEBUG;
126
print("1. Testing the seq() method...\n") if $DEBUG;
127
print("\t1a) get\n") if $DEBUG;
128
my $original_seq = $swq1->seq();
129
ok ($original_seq eq "ATCGATCGA");
130
print("\t1b) set\n") if $DEBUG;
131
ok ($swq1->seq("AAAAAAAAAAAA"));
132
print("\t1c) get (again, to make sure the set was done.)\n") if $DEBUG;
133
ok($swq1->seq() eq "AAAAAAAAAAAA");
134
print("\tSetting the sequence back to the original value...\n") if $DEBUG;
135
$swq1->seq($original_seq);
137
print("2. Testing the qual() method...\n") if $DEBUG;
138
print("\t2a) get\n") if $DEBUG;
139
my @qual = @{$swq1->qual()};
140
my $str_qual = join(' ',@qual);
141
ok ($str_qual eq "10 20 30 40 50 40 30 20 10");
142
print("\t2b) set\n") if $DEBUG;
143
ok ($swq1->qual("10 10 10 10 10"));
144
print("\t2c) get (again, to make sure the set was done.)\n") if $DEBUG;
145
my @qual2 = @{$swq1->qual()};
146
my $str_qual2 = join(' ',@qual2);
147
ok($str_qual2 eq "10 10 10 10 10");
148
print("\tSetting the quality back to the original value...\n") if $DEBUG;
149
$swq1->qual($str_qual);
151
print("3. Testing the length() method...\n") if $DEBUG;
152
print("\t3a) When lengths are equal...\n") if $DEBUG;
153
ok($swq1->length() == 9);
154
print("\t3b) When lengths are different\n") if $DEBUG;
155
$swq1->qual("10 10 10 10 10");
156
# why is this test failing?
158
ok($swq1->length() eq "DIFFERENT");
161
print("4. Testing the qual_obj() method...\n") if $DEBUG;
162
print("\t4a) Testing qual_obj()...\n") if $DEBUG;
163
my $retr_qual_obj = $swq1->qual_obj();
164
ok (ref($retr_qual_obj) eq "Bio::Seq::PrimaryQual");
165
print("\t4b) Testing qual_obj(\$ref)...\n") if $DEBUG;
166
$swq1->qual_obj($qualobj);
168
print("5. Testing the seq_obj() method...\n") if $DEBUG;
169
print("\t5a) Testing seq_qual_obj()...\n") if $DEBUG;
170
my $retr_seq_obj = $swq1->seq_obj();
171
ok (ref($retr_seq_obj) eq "Bio::PrimarySeq");
172
print("\t5b) Testing seq_obj(\$ref)...\n") if $DEBUG;
173
$swq1->seq_obj($seqobj);
175
print("6. Testing the subqual() method...\n") if $DEBUG;
176
my $t_subqual = "10 20 30 40 50 60 70 80 90";
177
$swq1->qual($t_subqual);
178
print("\t6d) Testing the subqual at the start (border condition)\n") if $DEBUG;
179
# ok ('1 2 3' eq join(' ',@{$swq1->subqual(1,3)}));
180
print("\t6d) Testing the subqual at the end (border condition)\n") if $DEBUG;
181
# ok ('7 8 9' eq join(' ',@{$swq1->subqual(7,9)}));
182
print("\t6d) Testing the subqual in the middle\n") if $DEBUG;
183
# ok ('4 5 6' eq join(' ',@{$swq1->subqual(4,6)}));
186
print("7. Testing cases where quality is zero...\n") if $DEBUG;
187
$swq1 = Bio::Seq::SeqWithQuality->new(-seq => 'G',
189
-verbose => $verbosity,
191
my $swq2 = Bio::Seq::SeqWithQuality->new(-seq => 'G',
193
-verbose => $verbosity,
195
ok $swq1->length, $swq2->length;
197
$swq1 = Bio::Seq::SeqWithQuality->new(-seq => 'GC',
198
-verbose => $verbosity,
201
$swq2 = Bio::Seq::SeqWithQuality->new(-seq => 'GT',
202
-verbose => $verbosity,
205
ok $swq1->length, $swq2->length;