File: primaryqual.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (177 lines) | stat: -rw-r--r-- 4,926 bytes parent folder | download
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
# -*-Perl-*-
## Bioperl Test Harness Script for Modules
## $Id: primaryqual.t,v 1.12 2002/12/19 22:10:34 matsallac Exp $
#
# modeled after the t/Allele.t test script

use strict;
use vars qw($DEBUG);
$DEBUG = $ENV{'BIOPERLDEBUG'};
my $verbose = -1 unless $DEBUG;
BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    if( $@ ) {
        use lib 't';
    }
    use Test;
    plan tests => 31;
}

END { 
    unlink qw(batch_write_qual.qual write_qual.qual);
	
}
# redirect STDERR to STDOUT
open (STDERR, ">&STDOUT");
use Bio::Root::IO;
use Bio::SeqIO;
use Bio::Seq::SeqWithQuality;
use Bio::Seq::PrimaryQual;

my $string_quals = "10 20 30 40 50 40 30 20 10";
print("Quals are $string_quals\n") if($DEBUG); 
my $qualobj = Bio::Seq::PrimaryQual->new( '-qual' => $string_quals,
					  '-id'  => 'QualityFragment-12',
					  '-accession_number' => 'X78121',
					  );
ok($qualobj);
ok($qualobj->display_id, 'QualityFragment-12');
ok($qualobj->accession_number, 'X78121');

my @q2 = split/ /,$string_quals;
$qualobj = Bio::Seq::PrimaryQual->new
    ( '-qual'             => \@q2,
      '-primary_id'	  =>	'chads primary_id',			
      '-desc'		  =>	'chads desc',
      '-accession_number' => 'chads accession_number',
      '-id'		  =>	'chads id'
      );

ok($qualobj->primary_id, 'chads primary_id');
my $rqual = $qualobj->qual();
ok(ref($rqual) eq "ARRAY");

my $newqualstring = "50 90 1000 20 12 0 0";

$qualobj->qual($newqualstring);
my $retrieved_quality = $qualobj->qual();
my $retrieved_quality_string = join(' ', @$retrieved_quality);
ok($retrieved_quality_string,$newqualstring);

my @newqualarray = split/ /,$newqualstring;
$qualobj->qual(\@newqualarray);
$retrieved_quality = $qualobj->qual();
$retrieved_quality_string = join(' ',@$retrieved_quality);
ok($retrieved_quality_string,$newqualstring);

eval {
    $qualobj->qual("chad");
};
ok($@ =~ /not look healthy/);

eval { $qualobj->qual(""); };
ok(!$@);

eval { $qualobj->qual(" 4"); };
ok(!$@);

ok($qualobj->length(),2 );
$qualobj->qual("10 20 30 40 50 40 30 20 10");
my @subquals = @{$qualobj->subqual(3,6);};
ok(@subquals, 4);
     # chad, note to self, evaluate border conditions
ok ("30 20 10" eq join(' ',@{$qualobj->subqual(7,9)}));



my @false_comparator = qw(30 40 70 40);
my @true_comparator = qw(30 40 50 40);
ok(!&compare_arrays(\@subquals,\@true_comparator));

eval { $qualobj->subqual(-1,6); };
ok($@ =~ /EX/ );
eval { $qualobj->subqual(1,6); };
ok(!$@);
eval { $qualobj->subqual(1,9); };
ok(!$@);
eval { $qualobj->subqual(9,1); };
ok($@ =~ /EX/ );


ok($qualobj->display_id() eq "chads id");
$qualobj->display_id("chads new display_id");
ok($qualobj->display_id() eq "chads new display_id");

ok($qualobj->accession_number(), "chads accession_number");
$qualobj->accession_number("chads new accession_number");
ok($qualobj->accession_number(), "chads new accession_number");
ok($qualobj->primary_id(), "chads primary_id");
$qualobj->primary_id("chads new primary_id");
ok($qualobj->primary_id(), "chads new primary_id");

ok($qualobj->desc(), "chads desc");
$qualobj->desc("chads new desc");
ok($qualobj->desc(), "chads new desc");
ok($qualobj->display_id(), "chads new display_id");
$qualobj->display_id("chads new id");
ok($qualobj->display_id(), "chads new id"); 

my $in_qual  = Bio::SeqIO->new(-file => "<" . Bio::Root::IO->catfile("t","data","qualfile.qual") , 
			       '-format' => 'qual',
			       '-verbose' => $verbose);
ok($in_qual);
my $pq = $in_qual->next_seq();
ok($pq->qual()->[99], '39'); # spot check boundary
ok($pq->qual()->[100], '39'); # spot check boundary

my $out_qual = Bio::SeqIO->new('-file'    => ">write_qual.qual",
			       '-format'  => 'qual',
			       '-verbose' => $verbose);
$out_qual->write_seq(-source	=>	$pq);

my $swq545 = Bio::Seq::SeqWithQuality->new (	-seq	=>	"ATA",
						-qual	=>	$pq
					);
$out_qual->write_seq(-source	=>	$swq545);



$in_qual = Bio::SeqIO->new('-file' => Bio::Root::IO->catfile("t","data","qualfile.qual") , 
			   '-format' => 'qual',
			   '-verbose' => $verbose);

my $out_qual2 = Bio::SeqIO->new('-file'    => ">batch_write_qual.qual",
				'-format'  => 'qual',
				'-verbose' => $verbose);

while ( my $batch_qual = $in_qual->next_seq() ) {
	$out_qual2->write_seq(-source	=>	$batch_qual);
}

sub display {
    if($DEBUG ) {
 	my @quals;
	print("I saw these in qualfile.qual:\n") ;
	while ( my $qual = $in_qual->next_seq() ) {
	    # ::dumpValue($qual);
	    print($qual->display_id()."\n");
	    @quals = @{$qual->qual()};
	    print("(".scalar(@quals).") quality values.\n");
	}
    }
}

# dumpValue($qualobj);

sub compare_arrays {
    my ($a1,$a2) = @_;
    return 1 if (scalar(@{$a1}) != scalar(@{$a2}));
    my ($v1,$v2,$diff,$curr);
    for ($curr=0;$curr<scalar(@{$a1});$curr++){
	return 1 if ($a1->[$curr] ne $a2->[$curr]);
    }
    return 0;
}