| 1 |
from cgelib.applications.command import _ContentArgument, CommandLineBase |
| 2 |
from cgelib.applications.command import _SwitchArgument |
| 3 |
|
| 4 |
|
| 5 |
class _BlastBaseCommandline(CommandLineBase): |
| 6 |
"""Base Commandline object for Blast wrappers (PRIVATE). |
| 7 |
This is provided for subclassing, it deals with shared options |
| 8 |
common to all the blast tools (blastn, etc). |
| 9 |
""" |
| 10 |
|
| 11 |
def __init__(self, cmd=None, path_exec="", **kwargs): |
| 12 |
assert cmd is not None |
| 13 |
extra_parameters = [ |
| 14 |
# Core: |
| 15 |
_SwitchArgument( |
| 16 |
["-h", "help"], |
| 17 |
"Print USAGE, DESCRIPTION description; " |
| 18 |
"ignore other arguments.", |
| 19 |
no_run=True, |
| 20 |
), |
| 21 |
_SwitchArgument( |
| 22 |
["-help", "help_extended"], |
| 23 |
"Print EXTENDED USAGE, DESCRIPTION and ARGUMENTS description; " |
| 24 |
"ignore other arguments.", |
| 25 |
no_run=True, |
| 26 |
), |
| 27 |
_SwitchArgument( |
| 28 |
["-version", "version"], |
| 29 |
"Print version number; " |
| 30 |
"ignore other arguments.", |
| 31 |
no_run=True, |
| 32 |
), |
| 33 |
_ContentArgument( |
| 34 |
["", "custom_args"], |
| 35 |
"Add custom arguments that are not included in the " |
| 36 |
"kma_application.py file." |
| 37 |
), |
| 38 |
] |
| 39 |
try: |
| 40 |
# Insert extra parameters - at the start just in case there |
| 41 |
# are any arguments which must come last: |
| 42 |
self.parameters = extra_parameters + self.parameters |
| 43 |
except AttributeError: |
| 44 |
# Should we raise an error? The subclass should have set this up! |
| 45 |
self.parameters = extra_parameters |
| 46 |
# Do we need a method to add a method for adding arguments in front? |
| 47 |
CommandLineBase.__init__(self, cmd, path_exec, **kwargs) |
| 48 |
|
| 49 |
def _validate_incompatibilities(self, incompatibles): |
| 50 |
"""Validate parameters for incompatibilities (PRIVATE). |
| 51 |
Used by the _validate method. |
| 52 |
""" |
| 53 |
for a in incompatibles: |
| 54 |
if self._get_parameter(a): |
| 55 |
for b in incompatibles[a]: |
| 56 |
if self._get_parameter(b): |
| 57 |
raise ValueError("Options %s and %s are incompatible." |
| 58 |
% (a, b)) |
| 59 |
|
| 60 |
|
| 61 |
class _BlastSearchBaseCommandline(_BlastBaseCommandline): |
| 62 |
"""Base Commandline object for Blast wrappers (PRIVATE). |
| 63 |
This is provided for subclassing, it deals with shared options |
| 64 |
common to all the blast tools (blastn, etc). |
| 65 |
""" |
| 66 |
|
| 67 |
def __init__(self, cmd=None, path_exec="", **kwargs): |
| 68 |
assert cmd is not None |
| 69 |
extra_parameters = [ |
| 70 |
# Core: |
| 71 |
_ContentArgument( |
| 72 |
["-db", "db"], |
| 73 |
"BLAST database name", |
| 74 |
filename=True, |
| 75 |
is_required=True, |
| 76 |
default=None, |
| 77 |
alter_options=["subject", "subject_loc"], |
| 78 |
incompatible=["subject", "subject_loc"], |
| 79 |
), |
| 80 |
_ContentArgument( |
| 81 |
["-query", "query"], |
| 82 |
"Query file name", |
| 83 |
filename=True, |
| 84 |
is_required=True, |
| 85 |
alter_options=["query_loc"], |
| 86 |
default="-", |
| 87 |
), |
| 88 |
_ContentArgument( |
| 89 |
["-query_loc", "query_location"], |
| 90 |
"Location on the query sequence", |
| 91 |
filename=True, |
| 92 |
is_required=True, |
| 93 |
alter_options=["query"], |
| 94 |
default="STDIN", |
| 95 |
), |
| 96 |
_ContentArgument( |
| 97 |
["-out", "output"], |
| 98 |
"Output file name", |
| 99 |
filename=True, |
| 100 |
is_required=True, |
| 101 |
default="STDOUT", |
| 102 |
), |
| 103 |
_ContentArgument( |
| 104 |
["-evalue", "evalue"], |
| 105 |
"Expect value (E) for saving hits", |
| 106 |
filename=True, |
| 107 |
is_required=False, |
| 108 |
default=10.0, |
| 109 |
), |
| 110 |
_ContentArgument( |
| 111 |
["-subject", "subject"], |
| 112 |
"File with subject sequence(s) to search.", |
| 113 |
filename=True, |
| 114 |
incompatible=["db", "gilist", "seqidlist", "negative_gilist", |
| 115 |
"db_soft_mask", "db_hard_mask"], |
| 116 |
is_required=False, |
| 117 |
default=None, |
| 118 |
), |
| 119 |
_ContentArgument( |
| 120 |
["-subject_loc", "subject_location"], |
| 121 |
"Location on the subject sequence (Format: start-stop).", |
| 122 |
filename=True, |
| 123 |
incompatible=["db", "gilist", "seqidlist", "negative_gilist", |
| 124 |
"db_soft_mask", "db_hard_mask"], |
| 125 |
is_required=False, |
| 126 |
default=None, |
| 127 |
), |
| 128 |
_SwitchArgument( |
| 129 |
["-show_gis", "show_GIs"], |
| 130 |
"Show NCBI GIs in report.", |
| 131 |
), |
| 132 |
_ContentArgument( |
| 133 |
["-num_descriptions", "num_descriptions"], |
| 134 |
"Show one-line descriptions for this number of database " |
| 135 |
"sequences.", |
| 136 |
filename=False, |
| 137 |
checker_function=lambda x: x >= 0, |
| 138 |
is_required=False, |
| 139 |
default=500, |
| 140 |
), |
| 141 |
_ContentArgument( |
| 142 |
["-num_alignments", "num_alignments"], |
| 143 |
"Show alignments for this number of database sequences.", |
| 144 |
filename=False, |
| 145 |
checker_function=lambda x: x >= 0, |
| 146 |
is_required=False, |
| 147 |
default=250, |
| 148 |
), |
| 149 |
_ContentArgument( |
| 150 |
["-max_target_seqs", "max_target_seqs"], |
| 151 |
"Number of aligned sequences to keep. Use with report formats " |
| 152 |
"that do not have separate definition line and alignment " |
| 153 |
"sections such as tabular (all outfmt > 4). Not compatible " |
| 154 |
"with num_descriptions or num_alignments. Ties are broken by " |
| 155 |
"order of sequences in the database.", |
| 156 |
filename=False, |
| 157 |
is_required=False, |
| 158 |
checker_function=lambda x: x >= 1, |
| 159 |
incompatible=["num_descriptions", "num_alignments"], |
| 160 |
default=500, |
| 161 |
), |
| 162 |
_ContentArgument( |
| 163 |
["-max_hsps", "max_hsps"], |
| 164 |
"Maximum number of HSPs (alignments) to keep for any single " |
| 165 |
"query-subject pair. The HSPs shown will be the best as judged" |
| 166 |
" by expect value. This number should be an integer that is " |
| 167 |
"one or greater. If this option is not set, BLAST shows all " |
| 168 |
"HSPs meeting the expect value criteria. Setting it to one " |
| 169 |
"will show only the best HSP for every query-subject pair", |
| 170 |
filename=False, |
| 171 |
checker_function=lambda x: x >= 1, |
| 172 |
is_required=False, |
| 173 |
default=None, |
| 174 |
), |
| 175 |
_SwitchArgument( |
| 176 |
["-html", "html"], |
| 177 |
"Produce HTML output", |
| 178 |
), |
| 179 |
_ContentArgument( |
| 180 |
["-seqidlist", "seqidlist"], |
| 181 |
"Restrict search of database to list of SeqId's.", |
| 182 |
filename=False, |
| 183 |
incompatible=["negative_gilist", "gilist", "remote", |
| 184 |
"subject", "subject_loc"], |
| 185 |
is_required=False, |
| 186 |
default=None, |
| 187 |
), |
| 188 |
_ContentArgument( |
| 189 |
["-gilist", "gilist"], |
| 190 |
"Restrict search of database to GI’s listed in this file. " |
| 191 |
"Local searches only.", |
| 192 |
filename=True, |
| 193 |
incompatible=["negative_gilist", "seqidlist", "remote", |
| 194 |
"subject", "subject_loc"], |
| 195 |
is_required=False, |
| 196 |
default=None, |
| 197 |
), |
| 198 |
_ContentArgument( |
| 199 |
["-negative_gilist", "negative_gilist"], |
| 200 |
"Restrict search of database to everything except the GI’s " |
| 201 |
"listed in this file. Local searches only.", |
| 202 |
filename=True, |
| 203 |
is_required=False, |
| 204 |
default=None, |
| 205 |
), |
| 206 |
_ContentArgument( |
| 207 |
["-entrez_query", "entrez_query"], |
| 208 |
"Restrict search with the given Entrez query. Remote searches " |
| 209 |
"only.", |
| 210 |
filename=False, |
| 211 |
required_options=["remote"], |
| 212 |
is_required=False, |
| 213 |
default=None, |
| 214 |
), |
| 215 |
_ContentArgument( |
| 216 |
["-culling_limit", "culling_limit"], |
| 217 |
"Delete a hit that is enveloped by at least this many " |
| 218 |
"higher-scoring hits.", |
| 219 |
filename=False, |
| 220 |
is_required=False, |
| 221 |
incompatible=["best_hit_overhang", "best_hit_score_edge"], |
| 222 |
checker_function=lambda x: x >= 0, |
| 223 |
default=None, |
| 224 |
), |
| 225 |
_ContentArgument( |
| 226 |
["-best_hit_overhang", "best_hit_overhang"], |
| 227 |
"Best Hit algorithm overhang value (recommended value: 0.1)", |
| 228 |
filename=False, |
| 229 |
incompatible=["culling_limit"], |
| 230 |
is_required=False, |
| 231 |
default=None, |
| 232 |
), |
| 233 |
_ContentArgument( |
| 234 |
["-best_hit_score_edge", "best_hit_score_edge"], |
| 235 |
"Best Hit algorithm score edge value (recommended value: 0.1)", |
| 236 |
filename=False, |
| 237 |
is_required=False, |
| 238 |
incompatible=["culling_limit"], |
| 239 |
default=None, |
| 240 |
), |
| 241 |
_ContentArgument( |
| 242 |
["-dbsize", "dbsize"], |
| 243 |
"Effective size of the database", |
| 244 |
filename=False, |
| 245 |
is_required=False, |
| 246 |
default=None, |
| 247 |
), |
| 248 |
_ContentArgument( |
| 249 |
["-searchsp", "searchsp"], |
| 250 |
"Effective length of the search space", |
| 251 |
filename=False, |
| 252 |
checker_function=lambda x: x >= 0, |
| 253 |
is_required=False, |
| 254 |
default=None, |
| 255 |
), |
| 256 |
_ContentArgument( |
| 257 |
["-import_search_strategy", "import_search_strategy"], |
| 258 |
"Search strategy file to read.", |
| 259 |
filename=True, |
| 260 |
incompatible=["export_search_strategy"], |
| 261 |
is_required=False, |
| 262 |
default=None, |
| 263 |
), |
| 264 |
_ContentArgument( |
| 265 |
["-export_search_strategy", "export_search_strategy"], |
| 266 |
"Record search strategy to this file.", |
| 267 |
filename=True, |
| 268 |
incompatible=["import_search_strategy"], |
| 269 |
is_required=False, |
| 270 |
default=None, |
| 271 |
), |
| 272 |
_SwitchArgument( |
| 273 |
["-parse_deflines", "parse_deflines"], |
| 274 |
"Parse query and subject bar delimited sequence identifiers " |
| 275 |
"(e.g., gi|129295).", |
| 276 |
), |
| 277 |
_ContentArgument( |
| 278 |
["-num_threads", "num_threads"], |
| 279 |
"Number of threads (CPUs) to use in blast search.", |
| 280 |
filename=None, |
| 281 |
checker_function=lambda x: x >= 1, |
| 282 |
incompatible=["remote"], |
| 283 |
is_required=False, |
| 284 |
default=1, |
| 285 |
), |
| 286 |
_SwitchArgument( |
| 287 |
["-remote", "remote"], |
| 288 |
"Execute search on NCBI servers?", |
| 289 |
incompatible=["gilist", "seqidlist", "negative_gilist", |
| 290 |
"subject_loc", "num_threads"] |
| 291 |
), |
| 292 |
_ContentArgument( |
| 293 |
["-outfmt", "outfmt"], |
| 294 |
"Number of threads (CPUs) to use in blast search.", |
| 295 |
filename=None, |
| 296 |
is_required=False, |
| 297 |
default=0, |
| 298 |
allow_multiple=True, |
| 299 |
), |
| 300 |
] |
| 301 |
try: |
| 302 |
# Insert extra parameters - at the start just in case there |
| 303 |
# are any arguments which must come last: |
| 304 |
self.parameters = extra_parameters + self.parameters |
| 305 |
except TypeError: |
| 306 |
# Should we raise an error? The subclass should have set this up! |
| 307 |
self.parameters = extra_parameters |
| 308 |
# Do we need a method to add a method for adding arguments in front? |
| 309 |
_BlastBaseCommandline.__init__(self, cmd, path_exec, **kwargs) |
| 310 |
|
| 311 |
|
| 312 |
class BlastNCommandline(_BlastSearchBaseCommandline): |
| 313 |
"""Base Commandline object for Blast wrappers (PRIVATE). |
| 314 |
This is provided for subclassing, it deals with shared options |
| 315 |
common to all the blast tools (blastn, etc). |
| 316 |
""" |
| 317 |
|
| 318 |
def __init__(self, cmd="blastn", path_exec="", **kwargs): |
| 319 |
assert cmd is not None |
| 320 |
self.parameters = [ |
| 321 |
_ContentArgument( |
| 322 |
["-task", "task"], |
| 323 |
"Task to execute", |
| 324 |
filename=None, |
| 325 |
is_required=False, |
| 326 |
checker_function=lambda x: x in ["blastn", "blastn-short", |
| 327 |
"dc-megablast", "megablast", |
| 328 |
"rmblastn"], |
| 329 |
default="Megablast", |
| 330 |
), |
| 331 |
_ContentArgument( |
| 332 |
["-word_size", "word_size"], |
| 333 |
"Word size for wordfinder algorithm (length of best perfect " |
| 334 |
"match)", |
| 335 |
filename=None, |
| 336 |
is_required=False, |
| 337 |
checker_function=lambda x: x >= 4, |
| 338 |
default="Depends on task", |
| 339 |
), |
| 340 |
_ContentArgument( |
| 341 |
["-gapopen", "gapopen"], |
| 342 |
"Cost to open a gap.", |
| 343 |
filename=None, |
| 344 |
is_required=False, |
| 345 |
default="Depends on task", |
| 346 |
), |
| 347 |
_ContentArgument( |
| 348 |
["-gapextend", "gapextend"], |
| 349 |
"Word size for wordfinder algorithm (length of best perfect " |
| 350 |
"match)", |
| 351 |
filename=None, |
| 352 |
is_required=False, |
| 353 |
default="Depends on task", |
| 354 |
), |
| 355 |
_ContentArgument( |
| 356 |
["-reward", "reward"], |
| 357 |
"Reward for a nucleotide match.", |
| 358 |
filename=None, |
| 359 |
is_required=False, |
| 360 |
checker_function=lambda x: x >= 0, |
| 361 |
default="Depends on task", |
| 362 |
), |
| 363 |
_ContentArgument( |
| 364 |
["-penalty", "penalty"], |
| 365 |
"Penalty for a nucleotide mismatch.", |
| 366 |
filename=None, |
| 367 |
is_required=False, |
| 368 |
checker_function=lambda x: x <= 0, |
| 369 |
default="Depends on task", |
| 370 |
), |
| 371 |
_ContentArgument( |
| 372 |
["-strand", "strand"], |
| 373 |
"Query strand(s) to search against database/subject. Choice of" |
| 374 |
"both, minus, or plus.", |
| 375 |
filename=None, |
| 376 |
is_required=False, |
| 377 |
checker_function=lambda x: x in ["both", "minus", "plus"], |
| 378 |
default="both", |
| 379 |
), |
| 380 |
_ContentArgument( |
| 381 |
["-dust", "dust"], |
| 382 |
"Filter query sequence with dust.", |
| 383 |
filename=None, |
| 384 |
is_required=False, |
| 385 |
default="20 64 1", |
| 386 |
), |
| 387 |
_ContentArgument( |
| 388 |
["-filtering_db", "filtering_db"], |
| 389 |
"Mask query using the sequences in this database.", |
| 390 |
filename=None, |
| 391 |
is_required=False, |
| 392 |
default=None, |
| 393 |
), |
| 394 |
_ContentArgument( |
| 395 |
["-window_masker_taxid", "window_masker_taxid"], |
| 396 |
"Enable WindowMasker filtering using a Taxonomic ID.", |
| 397 |
filename=None, |
| 398 |
is_required=False, |
| 399 |
default=None, |
| 400 |
), |
| 401 |
_ContentArgument( |
| 402 |
["-sum_stats", "sum_stats"], |
| 403 |
"Use sum statistics.", |
| 404 |
filename=None, |
| 405 |
is_required=False, |
| 406 |
default=None, |
| 407 |
), |
| 408 |
_ContentArgument( |
| 409 |
["-window_masker_db", "window_masker_db"], |
| 410 |
"Enable WindowMasker filtering using this file.", |
| 411 |
filename=None, |
| 412 |
is_required=False, |
| 413 |
default=None, |
| 414 |
), |
| 415 |
_SwitchArgument( |
| 416 |
["-soft_masking", "soft_masking"], |
| 417 |
"Apply filtering locations as soft masks (i.e., only for " |
| 418 |
"finding initial matches).", |
| 419 |
), |
| 420 |
_SwitchArgument( |
| 421 |
["-lcase_masking", "lcase_masking"], |
| 422 |
"Use lower case filtering in query and subject sequence(s).", |
| 423 |
), |
| 424 |
_ContentArgument( |
| 425 |
["-db_soft_mask", "db_soft_mask"], |
| 426 |
"Filtering algorithm ID to apply to the BLAST database as soft" |
| 427 |
"mask (i.e., only for finding initial matches).", |
| 428 |
filename=None, |
| 429 |
incompatible=["db_hard_mask", "subject", "subject_loc"], |
| 430 |
is_required=False, |
| 431 |
default=True, |
| 432 |
), |
| 433 |
_ContentArgument( |
| 434 |
["-db_hard_mask", "db_hard_mask"], |
| 435 |
"Filtering algorithm ID to apply to the BLAST database as " |
| 436 |
"hard mask (i.e., sequence is masked for all phases of search)" |
| 437 |
".", |
| 438 |
filename=None, |
| 439 |
incompatible=["db_hard_mask", "subject", "subject_loc"], |
| 440 |
is_required=False, |
| 441 |
default=None, |
| 442 |
), |
| 443 |
_ContentArgument( |
| 444 |
["-perc_identity", "perc_identity"], |
| 445 |
"Percent identity cutoff.", |
| 446 |
filename=None, |
| 447 |
is_required=False, |
| 448 |
default=0, |
| 449 |
), |
| 450 |
_ContentArgument( |
| 451 |
["-qcov_hsp_perc", "qcov_hsp_perc"], |
| 452 |
"Percent query coverage per hsp.", |
| 453 |
filename=None, |
| 454 |
is_required=False, |
| 455 |
default=0, |
| 456 |
), |
| 457 |
_ContentArgument( |
| 458 |
["-template_type", "template_type"], |
| 459 |
"Discontiguous MegaBLAST template type. Allowed values are " |
| 460 |
"coding, optimal and coding_and_optimal.", |
| 461 |
filename=None, |
| 462 |
is_required=False, |
| 463 |
checker_function=lambda x: x in ["coding", |
| 464 |
"coding_and_optimal", |
| 465 |
"optimal"], |
| 466 |
required_options=["template_length"], |
| 467 |
default=0, |
| 468 |
), |
| 469 |
_ContentArgument( |
| 470 |
["-template_length", "template_length"], |
| 471 |
"Discontiguous MegaBLAST template length.", |
| 472 |
filename=None, |
| 473 |
required_options=["template_length"], |
| 474 |
is_required=False, |
| 475 |
default=18, |
| 476 |
), |
| 477 |
_ContentArgument( |
| 478 |
["-use_index", "use_index"], |
| 479 |
"Use MegaBLAST database index. Indices may be created with the" |
| 480 |
" makembindex application.", |
| 481 |
filename=None, |
| 482 |
is_required=False, |
| 483 |
default=18, |
| 484 |
), |
| 485 |
_ContentArgument( |
| 486 |
["-index_name", "index_name"], |
| 487 |
"MegaBLAST database index name.", |
| 488 |
filename=None, |
| 489 |
is_required=False, |
| 490 |
default=18, |
| 491 |
), |
| 492 |
_ContentArgument( |
| 493 |
["-xdrop_ungap", "xdrop_ungap"], |
| 494 |
"Heuristic value (in bits) for ungapped extensions.", |
| 495 |
filename=None, |
| 496 |
is_required=False, |
| 497 |
default=20, |
| 498 |
), |
| 499 |
_ContentArgument( |
| 500 |
["-xdrop_gap", "xdrop_gap"], |
| 501 |
"Heuristic value (in bits) for preliminary gapped extensions.", |
| 502 |
filename=None, |
| 503 |
is_required=False, |
| 504 |
default=30, |
| 505 |
), |
| 506 |
_ContentArgument( |
| 507 |
["-xdrop_gap_final", "xdrop_gap_final"], |
| 508 |
"Heuristic value (in bits) for final gapped alignment.", |
| 509 |
filename=None, |
| 510 |
is_required=False, |
| 511 |
default=100, |
| 512 |
), |
| 513 |
_SwitchArgument( |
| 514 |
["-no_greedy", "no_greedy"], |
| 515 |
"Use non-greedy dynamic programming extension.", |
| 516 |
), |
| 517 |
_ContentArgument( |
| 518 |
["-min_raw_gapped_score", "min_raw_gapped_score"], |
| 519 |
"Minimum raw gapped score to keep an alignment in the " |
| 520 |
"preliminary gapped and trace-back stages. Normally set based " |
| 521 |
"upon expect value.", |
| 522 |
filename=None, |
| 523 |
is_required=False, |
| 524 |
default=30, |
| 525 |
), |
| 526 |
_SwitchArgument( |
| 527 |
["-ungapped", "ungapped"], |
| 528 |
"Perform ungapped alignment.", |
| 529 |
), |
| 530 |
_ContentArgument( |
| 531 |
["-window_size", "window_size"], |
| 532 |
"Multiple hits window size, use 0 to specify 1-hit algorithm.", |
| 533 |
filename=None, |
| 534 |
is_required=False, |
| 535 |
default=40, |
| 536 |
checker_function=lambda x: x >= 0, |
| 537 |
), |
| 538 |
_ContentArgument( |
| 539 |
["-off_diagonal_range", "off_diagonal_range"], |
| 540 |
"Number of off-diagonals to search for the 2nd hit, use 0 to " |
| 541 |
"turn off", |
| 542 |
filename=None, |
| 543 |
is_required=False, |
| 544 |
default=40, |
| 545 |
checker_function=lambda x: x >= 0, |
| 546 |
), |
| 547 |
_ContentArgument( |
| 548 |
["-line_length", "line_length"], |
| 549 |
"Line length for formatting alignments. Not applicable for " |
| 550 |
"outfmt > 4", |
| 551 |
filename=None, |
| 552 |
is_required=False, |
| 553 |
default=60, |
| 554 |
checker_function=lambda x: x >= 1, |
| 555 |
), |
| 556 |
] |
| 557 |
_BlastSearchBaseCommandline.__init__(self, cmd, path_exec, **kwargs) |