Debian Codegraph @

testsuite/itest11-search-frags.pl

raw
1 #! /usr/bin/perl
2
3 # Test cmsearch -A with fragments, and cmbuild --fraggiven using that -A output alignment.
4 #
5 # Usage: ./itest11-search-frags.pl <builddir> <srcdir> <tmpfile prefix>
6 # Example: ./itest11-search-frags.pl .. .. tmpfoo
7 #
8 # EPN, Thu Mar 16 13:59:24 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/cmsearch") { die "FAIL: didn't find cmsearch binary in $builddir/src\n"; }
18 if (! -x "$builddir/src/cmbuild") { die "FAIL: didn't find cmbuild binary in $builddir/src\n"; }
19 if (! -r "$srcdir/testsuite/Vault.c.cm") { die "FAIL: didn't find $srcdir/testsuite/Vault.c.cm\n"; }
20
21 # Create our test files
22 if (! open(SEQ1, ">$tmppfx.fa")) { print "FAIL: couldn't open $tmppfx.fa for writing"; exit 1; }
23
24 print SEQ1 <<"EOF";
25 >Vault-cmconsensus
26 GgGccGGCUUUAGCucAGcGGUUACuUCgacuauuauaauuuuauuuuuuuauauuuuuc
27 uuuuggGGUucGAaaCCCgCggGCGCUgUCCggCccUUUU
28 >Vault-cmconsensus-5p
29 GgGccGGCUUUAGCucAGcGGUUACuUCgacuauuauaauuuuauuuuuuuauauuuuuc
30 >Vault-cmconsensus-3p
31 uuuuggGGUucGAaaCCCgCggGCGCUgUCCggCccUUUU
32 >Vault-cmconsensus-5p-and-3p
33 AGcGGUUACuUCgacuauuauaauuuuauuuuuuuauauuuuuc
34 >Vault-cmconsensus-5p-2
35 GGccGGCUUUAGCucAGcGGUUACuUCgacuauuauaauuuuauuuuuuuauauuuuuc
36 >Vault-cmconsensus-3p-2
37 uuuuggGGUucGAaaCCCgCggGCGCUgUCCggCccUUU
38 >Vault-cmconsensus-5pspecial
39 uuuuaaaaaaUUUAGCucAGcGGUUACuUCgacuauuauaauuuuauuuuuuuauauuuuuc
40 >Vault-cmconsensus-3pspecial
41 uuuuggGGUucGAaaCCCgCggGCGCUgUCCggCcaaaaaaaaaaaaaaaaaaa
42 EOF
43
44 close SEQ1;
45
46 # define aligned seqs we expect in -A output
47 my %ali_H = ();
48 $ali_H{"Vault-cmconsensus/1-100"} = "GGGCCGGCUUUAGCUCAGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUCUUUUGGGGUUCGAAACCCGCGGGCGCUGUCCGGCCCUUUU";
49 $ali_H{"Vault-cmconsensus-5p/1-60"} = "GGGCCGGCUUUAGCUCAGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
50 $ali_H{"Vault-cmconsensus-3p/1-40"} = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~UUUUGGGGUUCGAAACCCGCGGGCGCUGUCCGGCCCUUUU";
51 $ali_H{"Vault-cmconsensus-5p-2/1-59"} = "~GGCCGGCUUUAGCUCAGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
52 $ali_H{"Vault-cmconsensus-3p-2/1-39"} = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~UUUUGGGGUUCGAAACCCGCGGGCGCUGUCCGGCCCUUU~";
53 $ali_H{"Vault-cmconsensus-5pspecial/11-62"} = "--------UUUAGCUCAGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
54 $ali_H{"Vault-cmconsensus-3pspecial/1-35"} = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~UUUUGGGGUUCGAAACCCGCGGGCGCUGUCCGGCC-----";
55 $ali_H{"Vault-cmconsensus-5p-and-3p/1-44"} = "~~~~~~~~~~~~~~~~AGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
56
57 # define --tfile lines that start with is_std that we expect
58 my %is_std_H = ();
59 $is_std_H{"Vault-cmconsensus/1-100"} = "TRUE";
60 $is_std_H{"Vault-cmconsensus-5p/1-60"} = "FALSE";
61 $is_std_H{"Vault-cmconsensus-3p/1-40"} = "FALSE";
62 $is_std_H{"Vault-cmconsensus-5p-2/1-59"} = "FALSE";
63 $is_std_H{"Vault-cmconsensus-3p-2/1-39"} = "FALSE";
64 $is_std_H{"Vault-cmconsensus-5pspecial/11-62"} = "FALSE";
65 $is_std_H{"Vault-cmconsensus-3pspecial/1-35"} = "FALSE";
66 $is_std_H{"Vault-cmconsensus-5p-and-3p/1-44"} = "FALSE";
67
68 # define --tfile lines that start with pass_idx that we expect
69 my %pass_idx_H = ();
70 $pass_idx_H{"Vault-cmconsensus/1-100"} = "1";
71 $pass_idx_H{"Vault-cmconsensus-5p/1-60"} = "3";
72 $pass_idx_H{"Vault-cmconsensus-3p/1-40"} = "2";
73 $pass_idx_H{"Vault-cmconsensus-5p-2/1-59"} = "4";
74 $pass_idx_H{"Vault-cmconsensus-3p-2/1-39"} = "4";
75 $pass_idx_H{"Vault-cmconsensus-5pspecial/11-62"} = "3";
76 $pass_idx_H{"Vault-cmconsensus-3pspecial/1-35"} = "2";
77 $pass_idx_H{"Vault-cmconsensus-5p-and-3p/1-44"} = "4";
78 # from infernal.h:
79 #define PLI_PASS_STD_ANY 1 /* only standard alns allowed, no truncated ones, any subseq */
80 #define PLI_PASS_5P_ONLY_FORCE 2 /* only 5' truncated alns allowed, first (i0) residue must be included */
81 #define PLI_PASS_3P_ONLY_FORCE 3 /* only 3' truncated alns allowed, final (j0) residue must be included */
82 #define PLI_PASS_5P_AND_3P_FORCE 4 /* 5' and 3' truncated alns allowed, first & final (i0 & j0) residue must be included */
83
84 # Create the test CM file
85 `cat $srcdir/testsuite/Vault.c.cm > $tmppfx.cm`; if ($?) { die "FAIL: cat\n"; }
86 # remove any old cmpress'd files if they exist
87 if(-e "$tmppfx.cm.i1m") { unlink "$tmppfx.cm.i1m"; }
88 if(-e "$tmppfx.cm.i1p") { unlink "$tmppfx.cm.i1p"; }
89 if(-e "$tmppfx.cm.i1f") { unlink "$tmppfx.cm.i1f"; }
90 if(-e "$tmppfx.cm.i1i") { unlink "$tmppfx.cm.i1i"; }
91 if(-e "$tmppfx.cm.ssi") { unlink "$tmppfx.cm.ssi"; }
92
93 ######################
94 # run cmsearch and make sure the -A output alignment is as expected
95 printf("$builddir/src/cmsearch --incT 10 -A $tmppfx.stk $tmppfx.cm $tmppfx.fa 2>&1\n");
96 `$builddir/src/cmsearch --incT 10 -A $tmppfx.stk $tmppfx.cm $tmppfx.fa 2>&1`; if ($? != 0) { die "FAIL: cmsearch failed\n"; }
97 check_stk("$tmppfx.stk", \%ali_H);
98
99 # run cmbuild using the -A output alignment as input, and make sure the parsetree file is as expected
100 if(-e "$tmppfx.cm2") { unlink "$tmppfx.cm2"; }
101 if(-e "$tmppfx.cm2.i1m") { unlink "$tmppfx.cm2.i1m"; }
102 if(-e "$tmppfx.cm2.i1p") { unlink "$tmppfx.cm2.i1p"; }
103 if(-e "$tmppfx.cm2.i1f") { unlink "$tmppfx.cm2.i1f"; }
104 if(-e "$tmppfx.cm2.i1i") { unlink "$tmppfx.cm2.i1i"; }
105 if(-e "$tmppfx.cm2.ssi") { unlink "$tmppfx.cm2.ssi"; }
106 `$builddir/src/cmbuild -F --fraggiven --tfile $tmppfx.tfile $tmppfx.cm2 $tmppfx.stk 2>&1`; if ($? != 0) { die "FAIL: cmbuild failed\n"; }
107 check_tfile("$tmppfx.tfile", \%is_std_H, \%pass_idx_H);
108
109 print "ok\n";
110 unlink <$tmppfx.cm*>;
111 unlink "$tmppfx.stk";
112 unlink "$tmppfx.fa";
113 unlink "$tmppfx.tfile";
114
115 exit 0;
116
117 #############################
118 sub check_stk
119 {
120 my ($stk_file, $ali_HR) = @_;
121 open(STK, $stk_file) || die "FAIL: unable to open cmsearch output stk file $stk_file";
122 my %passed_H = ();
123 while(my $line = <STK>) {
124 chomp $line;
125 if($line =~ m/^Vault/) {
126 chomp $line;
127 #Vault-cmconsensus/1-100 GGGCCGGCUUUAGCUCAGCGGUUACUUCGACUAUUAUAAUUUUAUUUUUUUAUAUUUUUCUUUUGGGGUUCGAAACCCGCGGGCGCUGUCCGGCCCUUUU
128 my @el_A = split(/\s+/, $line);
129 if(scalar(@el_A) != 2) { die "ERROR unable to parse alignment line in $stk_file: $line"; }
130 my ($seqname, $aseq) = ($el_A[0], $el_A[1]);
131 if(! defined $ali_HR->{$seqname}) { die "ERROR found unexpected sequence $seqname in alignment in $stk_file"; }
132 if($ali_HR->{$seqname} ne $aseq) { die "ERROR alignment of $seqname not as expected in $stk_file"; }
133 $passed_H{$seqname} = 1;
134 }
135 }
136 close(STK);
137 foreach my $seqname (sort keys %{$ali_HR}) {
138 if(! defined $passed_H{$seqname}) {
139 die "ERROR did not find sequence $seqname in alignment in $stk_file";
140 }
141 }
142 return;
143 }
144
145
146 #############################
147 sub check_tfile
148 {
149 my ($tfile_file, $is_std_HR, $pass_idx_HR) = @_;
150 open(TFILE, $tfile_file) || die "FAIL: unable to open cmbuild --tfile output file $tfile_file";
151 my $seqname = undef;
152 my %is_std_passed_H = ();
153 my %pass_idx_passed_H = ();
154 while(my $line = <TFILE>) {
155 chomp $line;
156 if($line =~ /^\>(\S+)/) {
157 #>Vault-cmconsensus/1-100
158 $seqname = $1;
159 }
160 elsif($line =~ /^is_std\s+\=\s+(\S+)/) {
161 #is_std = TRUE (alignment is not truncated)
162 $is_std = $1;
163 if(! defined $seqname) { die "ERROR read is_std line before seqname line in $tfile_file"; }
164 if(! defined $is_std_HR->{$seqname}) { die "ERROR found unexpected sequence $seqname in $tfile_file"; }
165 if($is_std_HR->{$seqname} ne $is_std) { die "ERROR is_std value for $seqname not as expected in $tfile_file"; }
166 $is_std_passed_H{$seqname} = 1;
167 }
168 elsif($line =~ /^pass_idx\s+\=\s+(\S+)/) {
169 #pass_idx = 1
170 $pass_idx = $1;
171 if(! defined $seqname) { die "ERROR read pass_idx line before seqname line in $tfile_file"; }
172 if(! defined $pass_idx_HR->{$seqname}) { die "ERROR found unexpected sequence $seqname $tfile_file"; }
173 if($pass_idx_HR->{$seqname} ne $pass_idx) { die "ERROR pass_idx value for $seqname not as expected in $tfile_file"; }
174 $pass_idx_passed_H{$seqname} = 1;
175 }
176 }
177 close(TFILE);
178
179 foreach $seqname (sort keys %{$is_std_HR}) {
180 if(! defined $is_std_passed_H{$seqname}) {
181 die "ERROR did not find is_std line for $seqname in $tfile_file";
182 }
183 }
184 foreach $seqname (sort keys %{$pass_idx_HR}) {
185 if(! defined $pass_idx_passed_H{$seqname}) {
186 die "ERROR did not find pass_idx line for $seqname in $tfile_file";
187 }
188 }
189 return;
190 }