Debian Codegraph @

testsuite/itest10-build-frags.pl

raw
1 #! /usr/bin/perl
2
3 # Test the fragment definition options of cmbuild
4 #
5 # Usage: ./itest10-build-frags.pl <builddir> <srcdir> <tmpfile prefix>
6 # Example: ./itest10-build-frags.pl .. .. tmpfoo
7 #
8 # EPN, Thu Mar 9 12:53:25 2023
9
10 BEGIN {
11 $builddir = shift;
12 $srcdir = shift;
13 $tmppfx = shift;
14 }
15
16 # Verify that we have all the executables we need for the test.
17 if (! -x "$builddir/src/cmbuild") { die "FAIL: didn't find cmbuild binary in $builddir/src\n"; }
18 if (! -x "$builddir/src/cmstat") { die "FAIL: didn't find cmstat binary in $builddir/src\n"; }
19
20 # Create our test files
21 if (! open(ALI1, ">$tmppfx.1.sto")) { print "FAIL: couldn't open $tmppfx.1.sto for write"; exit 1; }
22 if (! open(ALI2, ">$tmppfx.2.sto")) { print "FAIL: couldn't open $tmppfx.2.sto for write"; exit 1; }
23
24 print ALI1 <<"EOF";
25 # STOCKHOLM 1.0
26
27 seq1 ACGUACGUAC
28 seq2 .CGUACGUA.
29 seq3 ..GUACGU..
30 seq4 ...UACGU..
31 seq5 ....ACGU..
32 #=GC SS_cons :::<__>:::
33 #=GC RF xxxxxxxxxx
34 //
35 EOF
36
37 print ALI2 <<"EOF";
38 # STOCKHOLM 1.0
39
40 seq1 ACGUACGUAC
41 seq2 ~CGUACGUA~
42 seq3 ..GUACGU..
43 seq4 ~~~UACGU~~
44 seq5 ....ACGU..
45 #=GC SS_cons :::<__>:::
46 #=GC RF xxxxxxxxxx
47 //
48 EOF
49
50 close ALI1;
51 close ALI2;
52
53 if(-e "$tmppfx.cm") { unlink "$tmppfx.cm"; }
54 if(-e "$tmppfx.cm.i1m") { unlink "$tmppfx.cm.i1m"; }
55 if(-e "$tmppfx.cm.i1p") { unlink "$tmppfx.cm.i1p"; }
56 if(-e "$tmppfx.cm.i1f") { unlink "$tmppfx.cm.i1f"; }
57 if(-e "$tmppfx.cm.i1i") { unlink "$tmppfx.cm.i1i"; }
58 if(-e "$tmppfx.cm.ssi") { unlink "$tmppfx.cm.ssi"; }
59
60 # span:
61 # seq1: 1.0
62 # seq2: 0.8
63 # seq3: 0.6
64 # seq4: 0.5
65 # seq5: 0.4
66
67 # These tests only check consensus length of resulting model. We don't check that the correct seqs get set as fragments or not.
68
69 my $clen;
70 ######################
71 # --fragthresh testing
72 # fragthresh 1, seq3, seq4, seq5 frags, clen 10
73 `$builddir/src/cmbuild --wnone -F --fragthresh 1 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
74 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.1.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
75 $clen = get_clen("$tmppfx.1.cmstat"); if($clen != 10) { die "cmbuild --fragthresh 1 failed"; }
76
77 # fragthresh 0.75, seq3, seq4, seq5 frags, clen 10
78 `$builddir/src/cmbuild --wnone -F --fragthresh 0.75 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
79 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.2.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
80 $clen = get_clen("$tmppfx.2.cmstat"); if($clen != 10) { die "cmbuild --fragthresh 0.75 failed"; }
81
82 # fragthresh 0.55, seq4, seq5 frags, clen 8
83 `$builddir/src/cmbuild --wnone -F --fragthresh 0.55 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
84 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.3.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
85 $clen = get_clen("$tmppfx.3.cmstat"); if($clen != 8) { die "cmbuild --fragthresh 0.55 failed"; }
86
87 # fragthresh 0.35, no frags, clen 6
88 `$builddir/src/cmbuild --wnone -F --fragthresh 0.35 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
89 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.4.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
90 $clen = get_clen("$tmppfx.4.cmstat"); if($clen != 6) { die "cmbuild --fragthresh 0.35 failed"; }
91
92 # fragthresh 0, no frags, clen 6
93 `$builddir/src/cmbuild --wnone -F --fragthresh 0 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
94 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.5.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
95 $clen = get_clen("$tmppfx.5.cmstat"); if($clen != 6) { die "cmbuild --fragthresh 0 failed"; }
96
97 ######################
98 # --fragnrfpos testing
99 # fragnrfpos 0, seq2, seq3, seq4, seq5 frags, clen 10 (--hand)
100 `$builddir/src/cmbuild --wnone -F --hand --fragnrfpos 0 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
101 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.6.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
102 $clen = get_clen("$tmppfx.6.cmstat"); if($clen != 10) { die "cmbuild --fragnrfpos 0 failed"; }
103
104 # fragnrfpos 4, no frags, clen 10 (--hand)
105 `$builddir/src/cmbuild --wnone -F --hand --fragnrfpos 4 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
106 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.7.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
107 $clen = get_clen("$tmppfx.7.cmstat"); if($clen != 10) { die "cmbuild --fragnrfpos 4 failed"; }
108
109 # fragnrfpos 10, no frags, clen 10 (--hand)
110 `$builddir/src/cmbuild --wnone -F --hand --fragnrfpos 10 $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
111 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.8.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
112 $clen = get_clen("$tmppfx.8.cmstat"); if($clen != 10) { die "cmbuild --fragnrfpos 10 failed"; }
113
114 ######################
115 # --fraggiven testing
116 # $tmppfx.1.sto (ALI1) no frags, clen 6
117 `$builddir/src/cmbuild --wnone -F --fraggiven $tmppfx.cm $tmppfx.1.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
118 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.9.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
119 $clen = get_clen("$tmppfx.9.cmstat"); if($clen != 6) { die "cmbuild --fraggiven (1) failed"; }
120
121 # $tmppfx.1.sto (ALI1) seq2 and seq 4 frags, clen 8
122 `$builddir/src/cmbuild --wnone -F --fraggiven $tmppfx.cm $tmppfx.2.sto 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
123 `$builddir/src/cmstat $tmppfx.cm > $tmppfx.10.cmstat 2>&1`; if ($? != 0) { die "FAIL: cmstat failed\n"; }
124 $clen = get_clen("$tmppfx.10.cmstat"); if($clen != 8) { die "cmbuild --fraggiven (2) failed"; }
125
126 print "ok\n";
127 unlink "$tmppfx.cm";
128 unlink "$tmppfx.1.sto";
129 unlink "$tmppfx.2.sto";
130 unlink "$tmppfx.1.cmstat";
131 unlink "$tmppfx.2.cmstat";
132 unlink "$tmppfx.3.cmstat";
133 unlink "$tmppfx.4.cmstat";
134 unlink "$tmppfx.5.cmstat";
135 unlink "$tmppfx.6.cmstat";
136 unlink "$tmppfx.7.cmstat";
137 unlink "$tmppfx.8.cmstat";
138 unlink "$tmppfx.9.cmstat";
139 unlink "$tmppfx.10.cmstat";
140 exit 0;
141
142 sub get_clen
143 {
144 my ($cmstat_file) = @_;
145 open(CMSTAT, $cmstat_file) || die "FAIL: unable to open cmstat output file $cmstat_file";
146 while(my $line = <CMSTAT>) {
147 chomp $line;
148 if($line !~ m/^\#/) {
149 $line =~ s/^\s+//;
150 $line =~ s/\s+$//;
151 my @el_A = split(/\s+/, $line);
152 ## rel entropy
153 ## ------------
154 ## idx name accession nseq eff_nseq clen W bps bifs model cm hmm
155 ## ---- -------------------- --------- -------- -------- ----- ----- ---- ---- ----- ----- -----
156 # 1 tmp1 - 3 3.00 9 22 1 0 cm 1.126 1.086
157 $clen = $el_A[5];
158 }
159 }
160 close(CMSTAT);
161 return $clen;
162 }