| 1 |
############################################################################## |
|---|
| 2 |
# |
|---|
| 3 |
# This file is part of the cartwheel-clients source distribution. |
|---|
| 4 |
# |
|---|
| 5 |
# cartwheel-clients is part of the Cartwheel Bioinformatics Toolkit: |
|---|
| 6 |
# http://cartwheel.caltech.edu/. |
|---|
| 7 |
# |
|---|
| 8 |
# Contact author: C. Titus Brown, titus@caltech.edu. |
|---|
| 9 |
# |
|---|
| 10 |
# This program and all associated source code files are Copyright (C) 2001, |
|---|
| 11 |
# 2002 the California Institute of Technology, Pasadena, CA, 91125 USA. |
|---|
| 12 |
# |
|---|
| 13 |
# This library is free software; you can redistribute it and/or |
|---|
| 14 |
# modify it under the terms of the GNU Lesser General Public |
|---|
| 15 |
# License as published by the Free Software Foundation; either |
|---|
| 16 |
# version 2.1 of the License, or (at your option) any later version. |
|---|
| 17 |
# (see doc/LICENSE.txt). |
|---|
| 18 |
# |
|---|
| 19 |
# This library is distributed in the hope that it will be useful, |
|---|
| 20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 22 |
# Lesser General Public License for more details. |
|---|
| 23 |
# |
|---|
| 24 |
# You should have received a copy of the GNU Lesser General Public |
|---|
| 25 |
# License along with this library; if not, write to the Free Software |
|---|
| 26 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 27 |
# |
|---|
| 28 |
############################################################################## |
|---|
| 29 |
|
|---|
| 30 |
""" |
|---|
| 31 |
The set of tests that a client library has to pass in order to meet the |
|---|
| 32 |
minimal canal client spec. |
|---|
| 33 |
""" |
|---|
| 34 |
|
|---|
| 35 |
# |
|---|
| 36 |
# run_tests |
|---|
| 37 |
# |
|---|
| 38 |
|
|---|
| 39 |
def run_tests(api): |
|---|
| 40 |
""" |
|---|
| 41 |
'run_tests' takes a module or object that implements the Cartwheel |
|---|
| 42 |
canal client API and tests it. All API modules should pass these tests. |
|---|
| 43 |
""" |
|---|
| 44 |
|
|---|
| 45 |
# |
|---|
| 46 |
# First test the read-only interface for getting lab/etc information: |
|---|
| 47 |
# |
|---|
| 48 |
|
|---|
| 49 |
assert not api.is_authenticated() |
|---|
| 50 |
|
|---|
| 51 |
# authenticate: user/pass |
|---|
| 52 |
api.authenticate('admin', 'admin') |
|---|
| 53 |
|
|---|
| 54 |
assert api.is_authenticated() |
|---|
| 55 |
|
|---|
| 56 |
# |
|---|
| 57 |
# Print out some info |
|---|
| 58 |
# |
|---|
| 59 |
print 'server:', api.get_server_name(), '/', api.get_server_info() |
|---|
| 60 |
|
|---|
| 61 |
# |
|---|
| 62 |
# Test the ro interface: run through the labs. |
|---|
| 63 |
# |
|---|
| 64 |
|
|---|
| 65 |
labs = api.get_lab_list() |
|---|
| 66 |
|
|---|
| 67 |
if not labs: |
|---|
| 68 |
raise Exception("no available labs to look at! check access perms") |
|---|
| 69 |
|
|---|
| 70 |
lab = api.get_current_lab() |
|---|
| 71 |
api.set_current_lab(lab.id) |
|---|
| 72 |
print 'current lab:', lab.id |
|---|
| 73 |
|
|---|
| 74 |
for (id, name) in labs: |
|---|
| 75 |
lab = api.get_lab(id) |
|---|
| 76 |
print 'lab:', lab.get_name() |
|---|
| 77 |
|
|---|
| 78 |
folders = lab.get_folder_list() |
|---|
| 79 |
if folders: |
|---|
| 80 |
# run through the sub-folders: |
|---|
| 81 |
for (id, name) in folders: |
|---|
| 82 |
folder = lab.get_folder(id) |
|---|
| 83 |
print 'folder:', folder.get_name() |
|---|
| 84 |
|
|---|
| 85 |
# check out the sub-folders, if any: |
|---|
| 86 |
folders2 = folder.get_folder_list() |
|---|
| 87 |
if folders2: |
|---|
| 88 |
id = folders2[0][0] |
|---|
| 89 |
folder2 = folder.get_folder(id) |
|---|
| 90 |
print 'subfolder:', folder.get_name() |
|---|
| 91 |
|
|---|
| 92 |
# check out the sequences, if any: |
|---|
| 93 |
sequences = folder.get_sequence_list() |
|---|
| 94 |
if sequences: |
|---|
| 95 |
id = sequences[0][0] |
|---|
| 96 |
sequence = folder.get_sequence(id) |
|---|
| 97 |
print 'sequence:', sequence.get_name() |
|---|
| 98 |
|
|---|
| 99 |
# check out the analyses, if any: |
|---|
| 100 |
analysis_groups = folder.get_analysis_group_list() |
|---|
| 101 |
if analysis_groups: |
|---|
| 102 |
id = analysis_groups[0][0] |
|---|
| 103 |
group = folder.get_analysis_group(id) |
|---|
| 104 |
group.get_sister_data(1) |
|---|
| 105 |
print 'analysis group:', group.get_name() |
|---|
| 106 |
|
|---|
| 107 |
analyses = group.get_analyses() |
|---|
| 108 |
for analysis in analyses: |
|---|
| 109 |
print 'analysis:', analysis.get_name(), \ |
|---|
| 110 |
analysis.get_type() |
|---|
| 111 |
analysis.get_sister_data() |
|---|
| 112 |
|
|---|
| 113 |
if sequences and analysis_groups: |
|---|
| 114 |
break # keep looping *until* checked both |
|---|
| 115 |
|
|---|
| 116 |
##### |
|---|
| 117 |
|
|---|
| 118 |
# |
|---|
| 119 |
# Now test out the write interface, for creating analysis groups etc. |
|---|
| 120 |
# |
|---|
| 121 |
|
|---|
| 122 |
lab = api.get_current_lab() |
|---|
| 123 |
|
|---|
| 124 |
for db in lab.get_blast_databases(): |
|---|
| 125 |
print "BLAST DB:", db.get_printable_name() |
|---|
| 126 |
|
|---|
| 127 |
# retain db for later use... |
|---|
| 128 |
|
|---|
| 129 |
print 'creating node folder' |
|---|
| 130 |
top_folder = lab.create_node_folder('auto test - NODE') |
|---|
| 131 |
print 'created node folder -- %s (%s)' % (top_folder.get_name(), |
|---|
| 132 |
top_folder.get_type()) |
|---|
| 133 |
|
|---|
| 134 |
leaf_folder = top_folder.create_leaf_folder('auto test - SUB LEAF') |
|---|
| 135 |
print 'created leaf folder 1 -- %s (%s)' % (leaf_folder.get_name(), |
|---|
| 136 |
leaf_folder.get_type()) |
|---|
| 137 |
|
|---|
| 138 |
folder = lab.create_leaf_folder('auto test - TOP LEAF') |
|---|
| 139 |
print 'created leaf folder 2 -- %s (%s)' % (folder.get_name(), |
|---|
| 140 |
folder.get_type()) |
|---|
| 141 |
|
|---|
| 142 |
print 'creating sequences in folder' |
|---|
| 143 |
seq1 = folder.add_sequence("seq1", "ATGCCGGGNAGGAGATGGT", "DNA") |
|---|
| 144 |
seq2 = folder.add_sequence("seq2", "GAGAGNAGAGAGAGATATATAGC", "DNA") |
|---|
| 145 |
seq3 = folder.add_sequence("seq3", "GGGCCAGCCCCGAGAGATATATAGC", "DNA") |
|---|
| 146 |
|
|---|
| 147 |
print 'creating a few analysis groups...' |
|---|
| 148 |
single = folder.add_single_analysis_group("TEST single", seq1) |
|---|
| 149 |
pair = folder.add_pair_analysis_group("TEST pair", seq1, seq2) |
|---|
| 150 |
|
|---|
| 151 |
# test some of the API functions... |
|---|
| 152 |
single.get_sequence() |
|---|
| 153 |
pair.get_top_sequence() |
|---|
| 154 |
pair.get_top_group() |
|---|
| 155 |
pair.get_bot_sequence() |
|---|
| 156 |
pair.get_bot_group() |
|---|
| 157 |
|
|---|
| 158 |
analysis = single.add_blast_against_database("my blast db", 'blastn', db) |
|---|
| 159 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 160 |
|
|---|
| 161 |
analysis = single.add_blast_against_sequence("my seq blast", 'blastn', |
|---|
| 162 |
pair.get_bot_sequence()) |
|---|
| 163 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
analysis = single.add_hmmgene_analysis("my hmmgene anal") |
|---|
| 167 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 168 |
|
|---|
| 169 |
analysis = single.add_genscan_analysis("my genscan anal") |
|---|
| 170 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 171 |
|
|---|
| 172 |
analysis = single.add_geneid_analysis("my geneid anal") |
|---|
| 173 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 174 |
|
|---|
| 175 |
analysis = single.add_deepblast_analysis("my deepblast anal") |
|---|
| 176 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 177 |
|
|---|
| 178 |
analysis = single.add_simple_motif_search("my motif search", |
|---|
| 179 |
"ATG\nAGG\nACG\n", '') |
|---|
| 180 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 181 |
|
|---|
| 182 |
analysis = single.add_simple_features("my features", |
|---|
| 183 |
"10 20 hello there\n") |
|---|
| 184 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 185 |
|
|---|
| 186 |
analysis = single.add_IFF_data("my IFF data", "", "") |
|---|
| 187 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 188 |
|
|---|
| 189 |
analysis = single.add_GFF_data("my GFF data", "", "") |
|---|
| 190 |
print 'added analysis %s (%s)' % (analysis.get_name(), analysis.get_type()) |
|---|
| 191 |
|
|---|
| 192 |
a1 = pair.add_blast_analysis('my pair blast', 'blastn') |
|---|
| 193 |
print 'added analysis %s (%s)' % (a1.get_name(), a1.get_type()) |
|---|
| 194 |
|
|---|
| 195 |
a2 = pair.add_seqcomp_analysis('my seqcomp', 20, .7) |
|---|
| 196 |
print 'added analysis %s (%s)' % (a2.get_name(), a2.get_type()) |
|---|
| 197 |
|
|---|
| 198 |
a3 = pair.add_blastz_analysis('my blastz') |
|---|
| 199 |
|
|---|
| 200 |
a4 = pair.add_lagan_vista_analysis('my laganvista', 100, .6, forward=True) |
|---|
| 201 |
|
|---|
| 202 |
analysis.get_sister_data() |
|---|
| 203 |
a1.get_sister_data() |
|---|
| 204 |
|
|---|
| 205 |
print 'testing three-way analysis.' |
|---|
| 206 |
triple = folder.add_triple_analysis_group("TEST triple", |
|---|
| 207 |
seq1, seq2, seq3, |
|---|
| 208 |
0, -1, 0, -1, 0, -1, |
|---|
| 209 |
20, .7) |
|---|
| 210 |
|
|---|
| 211 |
top = triple.get_top_group() |
|---|
| 212 |
mid = triple.get_mid_group() |
|---|
| 213 |
bot = triple.get_bot_group() |
|---|
| 214 |
|
|---|
| 215 |
threshold = triple.get_threshold() |
|---|
| 216 |
windowsize = triple.get_windowsize() |
|---|
| 217 |
|
|---|
| 218 |
(ab_seqcomp,start_top,end_top,start_bot,end_bot) = triple.get_ab_seqcomp() |
|---|
| 219 |
(bc_seqcomp,start_top,end_top,start_bot,end_bot) = triple.get_bc_seqcomp() |
|---|
| 220 |
(ac_seqcomp,start_top,end_top,start_bot,end_bot) = triple.get_ac_seqcomp() |
|---|
| 221 |
|
|---|
| 222 |
print 'cleaning up...' |
|---|
| 223 |
single.delete_analysis(analysis) |
|---|
| 224 |
pair.delete_analysis(a1) |
|---|
| 225 |
pair.delete_analysis(a2) |
|---|
| 226 |
|
|---|
| 227 |
folder.delete_analysis_group(single) |
|---|
| 228 |
folder.delete_analysis_group(pair) |
|---|
| 229 |
folder.delete_analysis_group(triple) |
|---|
| 230 |
|
|---|
| 231 |
folder.delete_sequence(seq1) |
|---|
| 232 |
folder.delete_sequence(seq2) |
|---|
| 233 |
folder.delete_sequence(seq3) |
|---|
| 234 |
|
|---|
| 235 |
top_folder.delete_folder(leaf_folder) |
|---|
| 236 |
lab.delete_folder(top_folder) |
|---|
| 237 |
lab.delete_folder(folder) |
|---|
| 238 |
|
|---|
| 239 |
print 'logging off' |
|---|
| 240 |
api.logout() |
|---|
| 241 |
assert not api.is_authenticated() |
|---|
| 242 |
|
|---|
| 243 |
print 'All tests PASSED.' |
|---|
| 244 |
|
|---|
| 245 |
return 1 |
|---|