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
|
# -*-Perl-*- Test Harness script for Bioperl
# $Id$
use strict;
BEGIN {
use Bio::Root::Test;
test_begin(-tests => 63);
use_ok ('Bio::Matrix::PSM::IO');
}
my $mmt= "chr04q 170164 170208 strong - 0 Motif 3 occurrance in chr04q
chr04q 215755 215799 strong + 0 Motif 4 occurrance in chr04q
chr04q 532530 532574 strong + 2 Motif 2 occurrance in chr04q
chr04q 539492 539536 strong - 1 Motif 1 occurrance in chr04q
chr04q 586113 586157 strong + 2 Motif 2 occurrance in chr04q
chr04q 698245 698289 strong - 0 Motif 4 occurrance in chr04q
chr04q 804412 804456 strong - 0 Motif 3 occurrance in chr04q
chr04q 858870 858914 strong - 2 Motif 3 occurrance in chr04q
chr04q 861561 861605 strong - 2 Motif 3 occurrance in chr04q
chr04q 916898 916942 strong - 1 Motif 1 occurrance in chr04q
chr04q 1146916 1146960 strong - 0 Motif 1 occurrance in chr04q
chr04q 1315772 1315816 strong + 1 Motif 1 occurrance in chr04q
chr04q 1636119 1636163 strong + 2 Motif 3 occurrance in chr04q
chr04q 1636200 1636244 strong + 2 Motif 1 occurrance in chr04q
chr04q 1636437 1636481 strong + 2 Motif 4 occurrance in chr04q
chr04q 1637361 1637405 strong + 2 Motif 2 occurrance in chr04q
chr04q 1652447 1652491 strong + 1 Motif 4 occurrance in chr04q";
my @mmt=split(/\n/,$mmt);
#Let's try meme here
my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'meme',
-file=>test_input_file('meme.dat'));
ok $psmIO;
my @inputfile=grep(/datafile/i,$psmIO->unstructured);
ok @inputfile;
my $release=$psmIO->release;
ok $release;
my @ids=$psmIO->hid;
is @ids,4;
my %weights=$psmIO->weight;
ok %weights;
my %seq = $psmIO->seq;
is %seq,'0';#Meme doesn't have seq
is $psmIO->version,'3.0';
my $psm = $psmIO->next_psm;
ok $psm;
#Lets try to compress and uncompress the log odds and the frequencies, see if there is no
#considerable loss of data.
my $fA=$psm->get_compressed_freq('A');
my @check=Bio::Matrix::PSM::SiteMatrix::_uncompress_string($fA,1,1);
my @A=$psm->get_array('A');
my ($var,$max) = (0,0);
for (my $i = 0; $i<@check;$i++) {
my $diff=abs(abs($check[$i])-abs($A[$i]));
$var += $diff;
$max=$diff if ($diff>$max);
}
my $avg=$var/@check;
cmp_ok $avg,'<',0.01; #Loss of data under 1 percent
#print $avg,"\n";
is $psm->sequence_match_weight('CAGAAAAATAAAATGGCCACCACCC'),2015;
my $lA=$psm->get_compressed_logs('A');
@check=Bio::Matrix::PSM::SiteMatrix::_uncompress_string($lA,1000,2);
@A=$psm->get_logs_array('A');
($var,$max) = (0,0);
for (my $i = 0;$i<@check;$i++) {
my $diff=abs(abs($check[$i])-abs($A[$i]));
$var += $diff;
$max=$diff if ($diff>$max);
}
$avg=$var/@check;
cmp_ok $avg,'<',10; #Loss of data under 1 percent
my $matrix=$psm->matrix;
ok $matrix;
my $psm2=$psm;
$psm2->matrix($matrix);
is $psm,$psm2;
my %psm_header=$psm->header;
is $psm_header{IC},38.1;
is $psm_header{sites},4;
is $psm_header{width},25;
is $psm_header{e_val},'1.2e-002';
#Quick check if returned object works
my $IUPAC=$psm->IUPAC;
is $IUPAC,'CMKWMAAAKWVAWTYCMCASCHCCM';
is $IUPAC,$psm2->IUPAC;
is $IUPAC,$matrix->IUPAC;
my $instances=$psm->instances;
ok $instances;
foreach my $instance (@{$instances}) {
my $id=$instance->primary_id;
is $instance->strand,1;
last if (ok $id);
}
ok $psm->header('e_val');
#Meme parser should be OK if tests passed
#Now we are going to try transfac
$psmIO = Bio::Matrix::PSM::IO->new(-format=>'transfac',
-file=> test_input_file('transfac.dat'));
ok $psmIO;
my $version=$psmIO->version;
ok !$version;
is $psmIO->release, '6.4--2002-12-02';
$psm = $psmIO->next_psm;
ok $psm;
# Lets try to compress and uncompress the the frequencies, see if
# there is no considerable loss of data.
$fA=$psm->get_compressed_freq('A');
@check=Bio::Matrix::PSM::SiteMatrix::_uncompress_string($fA,1,1);
@A=$psm->get_array('A');
($var,$max) = (0,0);
for (my $i = 0; $i<@check;$i++) {
my $diff=abs(abs($check[$i])-abs($A[$i]));
$var += $diff;
$max=$diff if ($diff>$max);
}
$avg=$var/@check;
cmp_ok $avg,'<',0.01; #Loss of data under 1 percent
%weights = $psmIO->weight;
ok !$weights{''};
%seq = $psmIO->seq;
is scalar keys %seq, 0;
#Quick check if returned object works
$IUPAC = $psm->IUPAC;
is $IUPAC,'VVDCAKSTGBYD';
#Now we are going to try mast
$psmIO = Bio::Matrix::PSM::IO->new(-format=>'mast',
-file=>test_input_file('mast.dat'));
ok $psmIO;
@inputfile = grep(/datafile/i,$psmIO->unstructured);
ok !@inputfile;
is( $psmIO->release, '2002/04/02 0:11:59');
@ids = $psmIO->hid;
is @ids,4;
%weights = $psmIO->weight;
ok !%weights; #Mast doesn't have weights
ok %seq = $psmIO->seq;
foreach my $id ($psmIO->hid) {
ok $seq{$id};
}
ok $psm=$psmIO->next_psm;
my %instances=$psmIO->instances;
ok %instances;
is $psmIO->version, '3.0';
my $mmastIO=Bio::Matrix::PSM::IO->new(-format=>'mast',-file=>test_input_file('mixedmast.dat'));
$psm = $mmastIO->next_psm;
my $lastinstances = $psm->instances();
my $i=0;
foreach my $hit (@$lastinstances) {
$hit -> end ( $hit-> start () + length ($hit->seq) - 1 ) ; # fix an old bug in InstanceSite.pm
my $d=join("\t",$hit->{accession_number},$hit -> start () , $hit-> end (),$hit -> score (),
$hit -> strand == 1 ? '+' : '-' , $hit -> frame, $hit -> desc ( ));
is $d,$mmt[$i];
$i++;
last if ($hit -> start == 1652447);
}
|