| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
# -------------------------------- WebLogo -------------------------------- |
| 4 |
|
| 5 |
# Copyright (c) 2003-2004 The Regents of the University of California. |
| 6 |
# Copyright (c) 2005 Gavin E. Crooks |
| 7 |
# Copyright (c) 2006-2011, The Regents of the University of California, through |
| 8 |
# Lawrence Berkeley National Laboratory (subject to receipt of any required |
| 9 |
# approvals from the U.S. Dept. of Energy). All rights reserved. |
| 10 |
|
| 11 |
# This software is distributed under the new BSD Open Source License. |
| 12 |
# <http://www.opensource.org/licenses/bsd-license.html> |
| 13 |
# |
| 14 |
# Redistribution and use in source and binary forms, with or without |
| 15 |
# modification, are permitted provided that the following conditions are met: |
| 16 |
# |
| 17 |
# (1) Redistributions of source code must retain the above copyright notice, |
| 18 |
# this list of conditions and the following disclaimer. |
| 19 |
# |
| 20 |
# (2) Redistributions in binary form must reproduce the above copyright |
| 21 |
# notice, this list of conditions and the following disclaimer in the |
| 22 |
# documentation and or other materials provided with the distribution. |
| 23 |
# |
| 24 |
# (3) Neither the name of the University of California, Lawrence Berkeley |
| 25 |
# National Laboratory, U.S. Dept. of Energy nor the names of its contributors |
| 26 |
# may be used to endorse or promote products derived from this software |
| 27 |
# without specific prior written permission. |
| 28 |
# |
| 29 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 30 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 31 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 32 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 33 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 34 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 35 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 36 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 37 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 38 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 39 |
# POSSIBILITY OF SUCH DAMAGE. |
| 40 |
|
| 41 |
# WebLogo Command Line Interfaceg |
| 42 |
|
| 43 |
|
| 44 |
import atexit |
| 45 |
import os |
| 46 |
import sys |
| 47 |
from contextlib import ExitStack |
| 48 |
from io import StringIO |
| 49 |
from optparse import OptionGroup |
| 50 |
from os import PathLike |
| 51 |
from typing import Any, Union |
| 52 |
|
| •53 |
import importlib.resources as importlib_resources |
| 54 |
|
| 55 |
from . import ( |
| 56 |
LogoData, |
| 57 |
LogoFormat, |
| 58 |
LogoOptions, |
| 59 |
default_formatter, |
| 60 |
description, |
| 61 |
formatters, |
| 62 |
parse_prior, |
| 63 |
read_seq_data, |
| 64 |
release_description, |
| 65 |
seq_io, |
| 66 |
std_alphabets, |
| 67 |
std_color_schemes, |
| 68 |
std_sizes, |
| 69 |
std_units, |
| 70 |
) |
| 71 |
from .colorscheme import ColorScheme, SymbolColor |
| 72 |
from .logo import _seq_formats, _seq_names |
| 73 |
from .seq import Seq, SeqList, nucleic_alphabet |
| 74 |
from .utils.deoptparse import DeOptionParser |
| 75 |
|
| 76 |
|
| 77 |
# ====================== Main: Parse Command line ============================= |
| 78 |
def main() -> None: |
| 79 |
"""WebLogo command line interface""" |
| 80 |
|
| 81 |
# ------ Parse Command line ------ |
| 82 |
parser = _build_option_parser() |
| 83 |
(opts, args) = parser.parse_args(sys.argv[1:]) |
| 84 |
if args: |
| 85 |
parser.error("Unparsable arguments: %s " % args) |
| 86 |
|
| 87 |
if opts.serve: |
| 88 |
httpd_serve_forever(opts.port) # Never returns? # pragma: no cover |
| 89 |
sys.exit(0) # pragma: no cover |
| 90 |
|
| 91 |
# ------ Create Logo ------ |
| 92 |
try: |
| 93 |
data = _build_logodata(opts) |
| 94 |
format = _build_logoformat(data, opts) |
| 95 |
|
| 96 |
formatter = opts.formatter |
| 97 |
logo = formatter(data, format) |
| 98 |
# logo = logo.encode() |
| 99 |
|
| 100 |
opts.fout.buffer.write(logo) |
| 101 |
|
| 102 |
except ValueError as err: |
| 103 |
print("Error:", err, file=sys.stderr) |
| 104 |
sys.exit(2) |
| 105 |
except KeyboardInterrupt: # pragma: no cover |
| 106 |
sys.exit(0) |
| 107 |
|
| 108 |
|
| 109 |
# End main() |
| 110 |
|
| 111 |
|
| 112 |
def httpd_serve_forever(port: int = 8080) -> None: |
| 113 |
"""Start a webserver on a local port.""" |
| 114 |
|
| 115 |
import http.server as server |
| 116 |
import http.server as cgiserver |
| 117 |
|
| 118 |
class __HTTPRequestHandler(cgiserver.CGIHTTPRequestHandler): |
| 119 |
# Modify CGIHTTPRequestHandler so that it will run the cgi script directly, |
| 120 |
# instead of exec'ing |
| 121 |
# This bypasses the need for the cgi script to have execute permissions set, |
| 122 |
# since distutils install does not preserve permissions. |
| 123 |
def is_cgi(self) -> bool: |
| 124 |
self.have_fork = False # Prevent CGIHTTPRequestHandler from using fork |
| 125 |
if self.path == "/create.cgi": |
| 126 |
self.cgi_info = "", "create.cgi" |
| 127 |
return True |
| 128 |
return False |
| 129 |
|
| 130 |
def is_python( |
| 131 |
self, path: Union[str, PathLike] |
| 132 |
) -> bool: # Let CGIHTTPRequestHandler know that cgi script is python |
| 133 |
return True |
| 134 |
|
| 135 |
# Add current directory to PYTHONPATH. This is |
| 136 |
# so that we can run the standalone server |
| 137 |
# without having to run the install script. |
| 138 |
pythonpath = os.getenv("PYTHONPATH", "") |
| 139 |
pythonpath += os.pathsep + os.path.abspath(sys.path[0]) # .split()[0] |
| 140 |
os.environ["PYTHONPATH"] = pythonpath |
| 141 |
|
| 142 |
file_manager = ExitStack() |
| 143 |
atexit.register(file_manager.close) |
| 144 |
ref = importlib_resources.files("weblogo") / "htdocs" |
| 145 |
path = file_manager.enter_context(importlib_resources.as_file(ref)) |
| 146 |
|
| 147 |
os.chdir(path) |
| 148 |
|
| 149 |
HandlerClass = __HTTPRequestHandler |
| 150 |
ServerClass = server.HTTPServer |
| 151 |
httpd = ServerClass(("", port), HandlerClass) |
| 152 |
print("WebLogo server running at http://localhost:%d/" % port) |
| 153 |
|
| 154 |
try: |
| 155 |
httpd.serve_forever() |
| 156 |
except KeyboardInterrupt: |
| 157 |
sys.exit(0) |
| 158 |
|
| 159 |
|
| 160 |
# end httpd_serve_forever() |
| 161 |
|
| 162 |
|
| 163 |
def _build_logodata(options: Any) -> LogoData: |
| 164 |
motif_flag = False |
| 165 |
|
| 166 |
fin = options.fin |
| 167 |
|
| 168 |
if options.upload is None: |
| 169 |
if fin is None: |
| 170 |
fin = StringIO(sys.stdin.read()) |
| 171 |
else: |
| 172 |
if fin is None: |
| 173 |
from .logo import _from_URL_fileopen |
| 174 |
|
| 175 |
fin = _from_URL_fileopen(options.upload) |
| 176 |
else: |
| 177 |
raise ValueError("error: options --fin and --upload are incompatible") |
| 178 |
|
| 179 |
try: |
| 180 |
# Try reading data in transfac format first. |
| 181 |
from .matrix import Motif |
| 182 |
|
| 183 |
motif = Motif.read_transfac(fin, alphabet=options.alphabet) |
| 184 |
motif_flag = True |
| 185 |
except ValueError as motif_err: |
| 186 |
# Failed reading Motif, try reading as multiple sequence data. |
| 187 |
if options.input_parser == "transfac": |
| 188 |
raise motif_err # Adding transfac as str insted of parser is a bit of a ugly kludge |
| 189 |
seqs = read_seq_data( |
| 190 |
fin, |
| 191 |
options.input_parser.read, |
| 192 |
alphabet=options.alphabet, |
| 193 |
ignore_lower_case=options.ignore_lower_case, |
| 194 |
) |
| 195 |
|
| 196 |
if motif_flag: |
| 197 |
if options.ignore_lower_case: |
| 198 |
raise ValueError( |
| 199 |
"error: option --ignore-lower-case incompatible with matrix input" |
| 200 |
) |
| 201 |
if options.reverse or options.revcomp: |
| 202 |
motif.reverse() |
| 203 |
if options.complement or options.revcomp: |
| 204 |
motif.complement() |
| 205 |
|
| 206 |
prior = parse_prior(options.composition, motif.alphabet, options.weight) |
| 207 |
data = LogoData.from_counts(motif.alphabet, motif.array, prior) |
| 208 |
else: |
| 209 |
if options.reverse or options.revcomp: |
| 210 |
seqs = SeqList([s.reverse() for s in seqs], seqs.alphabet) |
| 211 |
|
| 212 |
if options.complement or options.revcomp: |
| 213 |
if not nucleic_alphabet.alphabetic(str(seqs.alphabet)): |
| 214 |
raise ValueError( |
| 215 |
"non-nucleic sequence cannot be complemented" |
| 216 |
) # pragam: no cover |
| 217 |
aaa = seqs.alphabet |
| 218 |
seqs.alphabet = nucleic_alphabet |
| 219 |
seqs = SeqList( |
| 220 |
[Seq(s, seqs.alphabet).complement() for s in seqs], seqs.alphabet |
| 221 |
) |
| 222 |
seqs.alphabet = aaa |
| 223 |
|
| 224 |
a = seqs.alphabet |
| 225 |
assert a is not None |
| 226 |
prior = parse_prior(options.composition, a, options.weight) |
| 227 |
data = LogoData.from_seqs(seqs, prior) |
| 228 |
|
| 229 |
return data |
| 230 |
|
| 231 |
|
| 232 |
def _build_logoformat(logodata: LogoData, opts: Any) -> LogoFormat: |
| 233 |
"""Extract and process relevant option values and return a |
| 234 |
LogoFormat object.""" |
| 235 |
|
| 236 |
args = {} |
| 237 |
direct_from_opts = [ |
| 238 |
# Logo Data Options. |
| 239 |
"alphabet", |
| 240 |
"unit_name", |
| 241 |
"first_index", |
| 242 |
"logo_start", |
| 243 |
"logo_end", |
| 244 |
# Logo Format Options. |
| 245 |
"stack_width", |
| 246 |
"stacks_per_line", |
| 247 |
"logo_title", |
| 248 |
"logo_label", |
| 249 |
"show_xaxis", |
| 250 |
"xaxis_label", |
| 251 |
"annotate", |
| 252 |
"rotate_numbers", |
| 253 |
"number_interval", |
| 254 |
"yaxis_scale", |
| 255 |
"show_yaxis", |
| 256 |
"yaxis_label", |
| 257 |
"show_ends", |
| 258 |
"fineprint", |
| 259 |
"yaxis_tic_interval", |
| 260 |
"show_errorbars", |
| 261 |
"reverse_stacks", |
| 262 |
# Color Options. |
| 263 |
"color_scheme", |
| 264 |
"default_color", |
| 265 |
# Font Format Options. |
| 266 |
"fontsize", |
| 267 |
"title_fontsize", |
| 268 |
"small_fontsize", |
| 269 |
"number_fontsize", |
| 270 |
"text_font", |
| 271 |
"logo_font", |
| 272 |
"title_font", |
| 273 |
# Advanced Format Options. |
| 274 |
"stack_aspect_ratio", |
| 275 |
"show_boxes", |
| 276 |
"resolution", |
| 277 |
"scale_width", |
| 278 |
"debug", |
| 279 |
"errorbar_fraction", |
| 280 |
"errorbar_width_fraction", |
| 281 |
"errorbar_gray", |
| 282 |
] |
| 283 |
|
| 284 |
for k in direct_from_opts: |
| 285 |
args[k] = opts.__dict__[k] |
| 286 |
|
| 287 |
# logo_size = copy.copy(opts.__dict__['logo_size']) |
| 288 |
# size_from_opts = ["stack_width", "stack_height"] |
| 289 |
# for k in size_from_opts : |
| 290 |
# length = getattr(opts, k) |
| 291 |
# if length : |
| 292 |
# setattr( logo_size, k, length ) |
| 293 |
# args["size"] = logo_size |
| 294 |
|
| 295 |
if opts.colors: |
| 296 |
color_scheme = ColorScheme() |
| 297 |
for color, symbols, desc in opts.colors: |
| 298 |
try: |
| 299 |
# c = Color.from_string(color) |
| 300 |
color_scheme.rules.append(SymbolColor(symbols, color, desc)) |
| 301 |
except ValueError: |
| 302 |
raise ValueError("error: option --color: invalid value: '%s'" % color) |
| 303 |
|
| 304 |
args["color_scheme"] = color_scheme |
| 305 |
|
| 306 |
if opts.annotate: |
| 307 |
args["annotate"] = opts.annotate.split(",") |
| 308 |
|
| 309 |
logooptions = LogoOptions() |
| 310 |
for a, v in args.items(): |
| 311 |
setattr(logooptions, a, v) |
| 312 |
|
| 313 |
theformat = LogoFormat(logodata, logooptions) |
| 314 |
return theformat |
| 315 |
|
| 316 |
|
| 317 |
# ========================== OPTIONS ========================== |
| 318 |
def _build_option_parser() -> DeOptionParser: |
| 319 |
defaults = LogoOptions() |
| 320 |
parser = DeOptionParser( |
| 321 |
usage="%prog [options] < sequence_data.fa > sequence_logo.eps", |
| 322 |
description=description, |
| 323 |
version=release_description, |
| 324 |
add_verbose_options=False, |
| 325 |
) |
| 326 |
|
| 327 |
io_grp = OptionGroup( |
| 328 |
parser, |
| 329 |
"Input/Output Options", |
| 330 |
) |
| 331 |
data_grp = OptionGroup( |
| 332 |
parser, |
| 333 |
"Logo Data Options", |
| 334 |
) |
| 335 |
trans_grp = OptionGroup( |
| 336 |
parser, "Transformations", "Optional transformations of the sequence data." |
| 337 |
) |
| 338 |
|
| 339 |
format_grp = OptionGroup( |
| 340 |
parser, |
| 341 |
"Logo Format Options", |
| 342 |
"These options control the format and display of the logo.", |
| 343 |
) |
| 344 |
color_grp = OptionGroup( |
| 345 |
parser, |
| 346 |
"Color Options", |
| 347 |
"Colors can be specified using CSS2 syntax. e.g. 'red', '#FF0000', etc", |
| 348 |
) |
| 349 |
font_grp = OptionGroup( |
| 350 |
parser, |
| 351 |
"Font Format Options", |
| 352 |
"These options provide control over the font sizes and types.", |
| 353 |
) |
| 354 |
advanced_grp = OptionGroup( |
| 355 |
parser, |
| 356 |
"Advanced Format Options", |
| 357 |
"These options provide fine control over the display of the logo.", |
| 358 |
) |
| 359 |
server_grp = OptionGroup( |
| 360 |
parser, "WebLogo Server", "Run a standalone webserver on a local port." |
| 361 |
) |
| 362 |
|
| 363 |
parser.add_option_group(io_grp) |
| 364 |
parser.add_option_group(data_grp) |
| 365 |
parser.add_option_group(trans_grp) |
| 366 |
parser.add_option_group(format_grp) |
| 367 |
parser.add_option_group(color_grp) |
| 368 |
parser.add_option_group(font_grp) |
| 369 |
parser.add_option_group(advanced_grp) |
| 370 |
parser.add_option_group(server_grp) |
| 371 |
|
| 372 |
# ========================== IO OPTIONS ========================== |
| 373 |
|
| 374 |
io_grp.add_option( |
| 375 |
"-f", |
| 376 |
"--fin", |
| 377 |
dest="fin", |
| 378 |
action="store", |
| 379 |
type="file_in", |
| 380 |
default=None, |
| 381 |
help="Sequence input file (default: stdin)", |
| 382 |
metavar="FILENAME", |
| 383 |
) |
| 384 |
|
| 385 |
io_grp.add_option( |
| 386 |
"", |
| 387 |
"--upload", |
| 388 |
dest="upload", |
| 389 |
action="store", |
| 390 |
default=None, |
| 391 |
help="Upload input file from URL", |
| 392 |
metavar="URL", |
| 393 |
) |
| 394 |
|
| 395 |
io_grp.add_option( |
| 396 |
"-D", |
| 397 |
"--datatype", |
| 398 |
dest="input_parser", |
| 399 |
action="store", |
| 400 |
type="dict", |
| 401 |
default=seq_io, |
| 402 |
choices=_seq_formats(), |
| 403 |
help="Type of multiple sequence alignment or position" |
| 404 |
" weight matrix file: (%s)" % ", ".join(_seq_names()), |
| 405 |
metavar="FORMAT", |
| 406 |
) |
| 407 |
|
| 408 |
io_grp.add_option( |
| 409 |
"-o", |
| 410 |
"--fout", |
| 411 |
dest="fout", |
| 412 |
type="file_out", |
| 413 |
default=sys.stdout, |
| 414 |
help="Output file (default: stdout)", |
| 415 |
metavar="FILENAME", |
| 416 |
) |
| 417 |
|
| 418 |
io_grp.add_option( |
| 419 |
"-F", |
| 420 |
"--format", |
| 421 |
dest="formatter", |
| 422 |
action="store", |
| 423 |
type="dict", |
| 424 |
choices=formatters, |
| 425 |
metavar="FORMAT", |
| 426 |
help="Format of output: eps (default), png, png_print, pdf, jpeg, svg, " |
| 427 |
"logodata, csv", |
| 428 |
default=default_formatter, |
| 429 |
) |
| 430 |
|
| 431 |
# ========================== Data OPTIONS ========================== |
| 432 |
|
| 433 |
data_grp.add_option( |
| 434 |
"-A", |
| 435 |
"--sequence-type", |
| 436 |
dest="alphabet", |
| 437 |
action="store", |
| 438 |
type="dict", |
| 439 |
choices=std_alphabets, |
| 440 |
help="The type of sequence data: 'protein', 'rna' or 'dna'.", |
| 441 |
metavar="TYPE", |
| 442 |
) |
| 443 |
|
| 444 |
data_grp.add_option( |
| 445 |
"-a", |
| 446 |
"--alphabet", |
| 447 |
dest="alphabet", |
| 448 |
action="store", |
| 449 |
help="The set of symbols to count, e.g. 'AGTC'. " |
| 450 |
"All characters not in the alphabet are ignored. " |
| 451 |
"If neither the alphabet nor sequence-type are specified then weblogo " |
| 452 |
"will examine the input data and make an educated guess. " |
| 453 |
"See also --sequence-type, --ignore-lower-case", |
| 454 |
) |
| 455 |
|
| 456 |
data_grp.add_option( |
| 457 |
"-U", |
| 458 |
"--units", |
| 459 |
dest="unit_name", |
| 460 |
action="store", |
| 461 |
choices=list(std_units.keys()), |
| 462 |
type="choice", |
| 463 |
default=defaults.unit_name, |
| 464 |
help="A unit of entropy ('bits' (default), 'nats', 'digits'), or a unit of" |
| 465 |
"free energy ('kT', 'kJ/mol', 'kcal/mol'), or 'probability' for" |
| 466 |
" probabilities", |
| 467 |
metavar="UNIT", |
| 468 |
) |
| 469 |
|
| 470 |
data_grp.add_option( |
| 471 |
"", |
| 472 |
"--composition", |
| 473 |
dest="composition", |
| 474 |
action="store", |
| 475 |
type="string", |
| 476 |
default="auto", |
| 477 |
help="The expected composition of the sequences: 'auto' (default), " |
| 478 |
"'equiprobable', 'none' (do not perform any compositional " |
| 479 |
"adjustment), a CG percentage, a species name (e.g. 'E. coli', " |
| 480 |
"'H. sapiens'), or an explicit distribution (e.g. \"{'A':10, 'C':40," |
| 481 |
" 'G':40, 'T':10}\"). The automatic option uses a typical " |
| 482 |
"distribution for proteins and equiprobable distribution for " |
| 483 |
"everything else. ", |
| 484 |
metavar="COMP.", |
| 485 |
) |
| 486 |
|
| 487 |
data_grp.add_option( |
| 488 |
"", |
| 489 |
"--weight", |
| 490 |
dest="weight", |
| 491 |
action="store", |
| 492 |
type="float", |
| 493 |
default=None, |
| 494 |
help="The weight of prior data. Default depends on alphabet length", |
| 495 |
metavar="NUMBER", |
| 496 |
) |
| 497 |
|
| 498 |
data_grp.add_option( |
| 499 |
"-i", |
| 500 |
"--first-index", |
| 501 |
dest="first_index", |
| 502 |
action="store", |
| 503 |
type="int", |
| 504 |
default=1, |
| 505 |
help="Index of first position in sequence data (default: 1)", |
| 506 |
metavar="INDEX", |
| 507 |
) |
| 508 |
|
| 509 |
data_grp.add_option( |
| 510 |
"-l", |
| 511 |
"--lower", |
| 512 |
dest="logo_start", |
| 513 |
action="store", |
| 514 |
type="int", |
| 515 |
help="Lower bound of sequence to display", |
| 516 |
metavar="INDEX", |
| 517 |
) |
| 518 |
|
| 519 |
data_grp.add_option( |
| 520 |
"-u", |
| 521 |
"--upper", |
| 522 |
dest="logo_end", |
| 523 |
action="store", |
| 524 |
type="int", |
| 525 |
help="Upper bound of sequence to display", |
| 526 |
metavar="INDEX", |
| 527 |
) |
| 528 |
|
| 529 |
# ========================== Transformation OPTIONS ========================== |
| 530 |
|
| 531 |
# FIXME Add test? |
| 532 |
trans_grp.add_option( |
| 533 |
"", |
| 534 |
"--ignore-lower-case", |
| 535 |
dest="ignore_lower_case", |
| 536 |
action="store_true", |
| 537 |
default=False, |
| 538 |
help="Disregard lower case letters and only count upper case letters" |
| 539 |
" in sequences.", |
| 540 |
) |
| 541 |
|
| 542 |
trans_grp.add_option( |
| 543 |
"", |
| 544 |
"--reverse", |
| 545 |
dest="reverse", |
| 546 |
action="store_true", |
| 547 |
default=False, |
| 548 |
help="reverse sequences", |
| 549 |
) |
| 550 |
|
| 551 |
trans_grp.add_option( |
| 552 |
"", |
| 553 |
"--complement", |
| 554 |
dest="complement", |
| 555 |
action="store_true", |
| 556 |
default=False, |
| 557 |
help="complement nucleic sequences", |
| 558 |
) |
| 559 |
|
| 560 |
trans_grp.add_option( |
| 561 |
"", |
| 562 |
"--revcomp", |
| 563 |
dest="revcomp", |
| 564 |
action="store_true", |
| 565 |
default=False, |
| 566 |
help="reverse complement nucleic sequences", |
| 567 |
) |
| 568 |
|
| 569 |
# ========================== FORMAT OPTIONS ========================== |
| 570 |
|
| 571 |
format_grp.add_option( |
| 572 |
"-s", |
| 573 |
"--size", |
| 574 |
dest="stack_width", |
| 575 |
action="store", |
| 576 |
type="dict", |
| 577 |
choices=std_sizes, |
| 578 |
metavar="LOGOSIZE", |
| 579 |
default=defaults.stack_width, |
| 580 |
help="Specify a standard logo size (small, medium (default), large)", |
| 581 |
) |
| 582 |
|
| 583 |
format_grp.add_option( |
| 584 |
"-n", |
| 585 |
"--stacks-per-line", |
| 586 |
dest="stacks_per_line", |
| 587 |
action="store", |
| 588 |
type="int", |
| 589 |
help="Maximum number of logo stacks per logo line. (default: %default)", |
| 590 |
default=defaults.stacks_per_line, |
| 591 |
metavar="COUNT", |
| 592 |
) |
| 593 |
|
| 594 |
format_grp.add_option( |
| 595 |
"-t", |
| 596 |
"--title", |
| 597 |
dest="logo_title", |
| 598 |
action="store", |
| 599 |
type="string", |
| 600 |
help="Logo title text.", |
| 601 |
default=defaults.logo_title, |
| 602 |
metavar="TEXT", |
| 603 |
) |
| 604 |
|
| 605 |
format_grp.add_option( |
| 606 |
"", |
| 607 |
"--label", |
| 608 |
dest="logo_label", |
| 609 |
action="store", |
| 610 |
type="string", |
| 611 |
help="A figure label, e.g. '2a'", |
| 612 |
default=defaults.logo_label, |
| 613 |
metavar="TEXT", |
| 614 |
) |
| 615 |
|
| 616 |
format_grp.add_option( |
| 617 |
"-X", |
| 618 |
"--show-xaxis", |
| 619 |
action="store", |
| 620 |
type="boolean", |
| 621 |
default=defaults.show_xaxis, |
| 622 |
metavar="YES/NO", |
| 623 |
help="Display sequence numbers along x-axis? (default: %default)", |
| 624 |
) |
| 625 |
|
| 626 |
format_grp.add_option( |
| 627 |
"-x", |
| 628 |
"--xlabel", |
| 629 |
dest="xaxis_label", |
| 630 |
action="store", |
| 631 |
type="string", |
| 632 |
default=defaults.xaxis_label, |
| 633 |
help="X-axis label", |
| 634 |
metavar="TEXT", |
| 635 |
) |
| 636 |
|
| 637 |
format_grp.add_option( |
| 638 |
"", |
| 639 |
"--annotate", |
| 640 |
dest="annotate", |
| 641 |
action="store", |
| 642 |
type="string", |
| 643 |
default=None, |
| 644 |
help="A comma separated list of custom stack annotations, " |
| 645 |
"e.g. '1,3,4,5,6,7'. Annotation list must be same length as " |
| 646 |
"sequences.", |
| 647 |
metavar="TEXT", |
| 648 |
) |
| 649 |
|
| 650 |
format_grp.add_option( |
| 651 |
"", |
| 652 |
"--rotate-numbers", |
| 653 |
dest="rotate_numbers", |
| 654 |
action="store", |
| 655 |
type="boolean", |
| 656 |
default=defaults.rotate_numbers, |
| 657 |
help="Draw X-axis numbers with vertical orientation (default: %default).", |
| 658 |
metavar="YES/NO", |
| 659 |
) |
| 660 |
|
| 661 |
format_grp.add_option( |
| 662 |
"", |
| 663 |
"--number-interval", |
| 664 |
dest="number_interval", |
| 665 |
action="store", |
| 666 |
type="float", |
| 667 |
default=defaults.number_interval, |
| 668 |
help="Distance between numbers on X-axis (default: %s)" |
| 669 |
% defaults.number_interval, |
| 670 |
metavar="NUMBER", |
| 671 |
) |
| 672 |
|
| 673 |
format_grp.add_option( |
| 674 |
"-S", |
| 675 |
"--yaxis", |
| 676 |
dest="yaxis_scale", |
| 677 |
action="store", |
| 678 |
type="float", |
| 679 |
help="Height of yaxis in units. (Default: Maximum value with " |
| 680 |
"uninformative prior.)", |
| 681 |
metavar="NUMBER", |
| 682 |
) |
| 683 |
|
| 684 |
format_grp.add_option( |
| 685 |
"-Y", |
| 686 |
"--show-yaxis", |
| 687 |
action="store", |
| 688 |
type="boolean", |
| 689 |
dest="show_yaxis", |
| 690 |
default=defaults.show_yaxis, |
| 691 |
metavar="YES/NO", |
| 692 |
help="Display entropy scale along y-axis? (default: %default)", |
| 693 |
) |
| 694 |
|
| 695 |
format_grp.add_option( |
| 696 |
"-y", |
| 697 |
"--ylabel", |
| 698 |
dest="yaxis_label", |
| 699 |
action="store", |
| 700 |
type="string", |
| 701 |
help="Y-axis label (default depends on plot type and units)", |
| 702 |
metavar="TEXT", |
| 703 |
) |
| 704 |
|
| 705 |
format_grp.add_option( |
| 706 |
"-E", |
| 707 |
"--show-ends", |
| 708 |
action="store", |
| 709 |
type="boolean", |
| 710 |
default=defaults.show_ends, |
| 711 |
metavar="YES/NO", |
| 712 |
help="Label the ends of the sequence? (default: %default)", |
| 713 |
) |
| 714 |
|
| 715 |
format_grp.add_option( |
| 716 |
"-P", |
| 717 |
"--fineprint", |
| 718 |
dest="fineprint", |
| 719 |
action="store", |
| 720 |
type="string", |
| 721 |
default=defaults.fineprint, |
| 722 |
help="The fine print (default: weblogo version)", |
| 723 |
metavar="TEXT", |
| 724 |
) |
| 725 |
|
| 726 |
format_grp.add_option( |
| 727 |
"", |
| 728 |
"--ticmarks", |
| 729 |
dest="yaxis_tic_interval", |
| 730 |
action="store", |
| 731 |
type="float", |
| 732 |
default=defaults.yaxis_tic_interval, |
| 733 |
help="Distance between ticmarks (default: %default)", |
| 734 |
metavar="NUMBER", |
| 735 |
) |
| 736 |
|
| 737 |
format_grp.add_option( |
| 738 |
"", |
| 739 |
"--errorbars", |
| 740 |
dest="show_errorbars", |
| 741 |
action="store", |
| 742 |
type="boolean", |
| 743 |
default=defaults.show_errorbars, |
| 744 |
metavar="YES/NO", |
| 745 |
help="Display error bars? (default: %default)", |
| 746 |
) |
| 747 |
|
| 748 |
format_grp.add_option( |
| 749 |
"", |
| 750 |
"--reverse-stacks", |
| 751 |
dest="reverse_stacks", |
| 752 |
action="store", |
| 753 |
type="boolean", |
| 754 |
default=defaults.show_errorbars, |
| 755 |
metavar="YES/NO", |
| 756 |
help="Draw stacks with largest letters on top? (default: %default)", |
| 757 |
) |
| 758 |
|
| 759 |
# ========================== Color OPTIONS ========================== |
| 760 |
# TODO: Future Feature |
| 761 |
# color_grp.add_option( "-K", "--color-key", |
| 762 |
# dest= "show_color_key", |
| 763 |
# action="store", |
| 764 |
# type = "boolean", |
| 765 |
# default= defaults.show_color_key, |
| 766 |
# metavar = "YES/NO", |
| 767 |
# help="Display a color key (default: %default)") |
| 768 |
|
| 769 |
color_scheme_choices = list(std_color_schemes.keys()) |
| 770 |
color_scheme_choices.sort() |
| 771 |
color_grp.add_option( |
| 772 |
"-c", |
| 773 |
"--color-scheme", |
| 774 |
dest="color_scheme", |
| 775 |
action="store", |
| 776 |
type="dict", |
| 777 |
choices=std_color_schemes, |
| 778 |
metavar="SCHEME", |
| 779 |
default=None, # Auto |
| 780 |
help="Specify a standard color scheme (%s)" % ", ".join(color_scheme_choices), |
| 781 |
) |
| 782 |
|
| 783 |
color_grp.add_option( |
| 784 |
"-C", |
| 785 |
"--color", |
| 786 |
dest="colors", |
| 787 |
action="append", |
| 788 |
metavar="COLOR SYMBOLS DESCRIPTION ", |
| 789 |
nargs=3, |
| 790 |
default=[], |
| 791 |
help="Specify symbol colors, e.g. --color black AG 'Purine' " |
| 792 |
"--color red TC 'Pyrimidine' ", |
| 793 |
) |
| 794 |
|
| 795 |
color_grp.add_option( |
| 796 |
"", |
| 797 |
"--default-color", |
| 798 |
dest="default_color", |
| 799 |
action="store", |
| 800 |
metavar="COLOR", |
| 801 |
default=defaults.default_color, |
| 802 |
help="Symbol color if not otherwise specified.", |
| 803 |
) |
| 804 |
|
| 805 |
# ========================== Font options ========================= |
| 806 |
|
| 807 |
font_grp.add_option( |
| 808 |
"", |
| 809 |
"--fontsize", |
| 810 |
dest="fontsize", |
| 811 |
action="store", |
| 812 |
type="float", |
| 813 |
default=defaults.fontsize, |
| 814 |
help="Regular text font size in points (default: %s)" % defaults.fontsize, |
| 815 |
metavar="POINTS", |
| 816 |
) |
| 817 |
|
| 818 |
font_grp.add_option( |
| 819 |
"", |
| 820 |
"--title-fontsize", |
| 821 |
dest="title_fontsize", |
| 822 |
action="store", |
| 823 |
type="float", |
| 824 |
default=defaults.title_fontsize, |
| 825 |
help="Title text font size in points (default: %s)" % defaults.title_fontsize, |
| 826 |
metavar="POINTS", |
| 827 |
) |
| 828 |
|
| 829 |
font_grp.add_option( |
| 830 |
"", |
| 831 |
"--small-fontsize", |
| 832 |
dest="small_fontsize", |
| 833 |
action="store", |
| 834 |
type="float", |
| 835 |
default=defaults.small_fontsize, |
| 836 |
help="Small text font size in points (default: %s)" % defaults.small_fontsize, |
| 837 |
metavar="POINTS", |
| 838 |
) |
| 839 |
|
| 840 |
font_grp.add_option( |
| 841 |
"", |
| 842 |
"--number-fontsize", |
| 843 |
dest="number_fontsize", |
| 844 |
action="store", |
| 845 |
type="float", |
| 846 |
default=defaults.number_fontsize, |
| 847 |
help="Axis numbers font size in points (default: %s)" |
| 848 |
% defaults.number_fontsize, |
| 849 |
metavar="POINTS", |
| 850 |
) |
| 851 |
|
| 852 |
font_grp.add_option( |
| 853 |
"", |
| 854 |
"--text-font", |
| 855 |
dest="text_font", |
| 856 |
action="store", |
| 857 |
type="string", |
| 858 |
default=defaults.text_font, |
| 859 |
help="Specify font for labels (default: %s)" % defaults.text_font, |
| 860 |
metavar="FONT", |
| 861 |
) |
| 862 |
|
| 863 |
font_grp.add_option( |
| 864 |
"", |
| 865 |
"--logo-font", |
| 866 |
dest="logo_font", |
| 867 |
action="store", |
| 868 |
type="string", |
| 869 |
default=defaults.text_font, |
| 870 |
help="Specify font for logo (default: %s)" % defaults.logo_font, |
| 871 |
metavar="FONT", |
| 872 |
) |
| 873 |
|
| 874 |
font_grp.add_option( |
| 875 |
"", |
| 876 |
"--title-font", |
| 877 |
dest="title_font", |
| 878 |
action="store", |
| 879 |
type="string", |
| 880 |
default=defaults.title_font, |
| 881 |
help="Specify font for title (default: %s)" % defaults.title_font, |
| 882 |
metavar="FONT", |
| 883 |
) |
| 884 |
|
| 885 |
# ========================== Advanced options ========================= |
| 886 |
|
| 887 |
advanced_grp.add_option( |
| 888 |
"-W", |
| 889 |
"--stack-width", |
| 890 |
dest="stack_width", |
| 891 |
action="store", |
| 892 |
type="float", |
| 893 |
default=defaults.stack_width, |
| 894 |
help="Width of a logo stack (default: %s)" % defaults.stack_width, |
| 895 |
metavar="POINTS", |
| 896 |
) |
| 897 |
|
| 898 |
advanced_grp.add_option( |
| 899 |
"", |
| 900 |
"--aspect-ratio", |
| 901 |
dest="stack_aspect_ratio", |
| 902 |
action="store", |
| 903 |
type="float", |
| 904 |
default=defaults.stack_aspect_ratio, |
| 905 |
help="Ratio of stack height to width (default: %s)" |
| 906 |
% defaults.stack_aspect_ratio, |
| 907 |
metavar="POINTS", |
| 908 |
) |
| 909 |
|
| 910 |
advanced_grp.add_option( |
| 911 |
"", |
| 912 |
"--box", |
| 913 |
dest="show_boxes", |
| 914 |
action="store", |
| 915 |
type="boolean", |
| 916 |
default=False, |
| 917 |
metavar="YES/NO", |
| 918 |
help="Draw boxes around symbols? (default: no)", |
| 919 |
) |
| 920 |
|
| 921 |
advanced_grp.add_option( |
| 922 |
"", |
| 923 |
"--resolution", |
| 924 |
dest="resolution", |
| 925 |
action="store", |
| 926 |
type="float", |
| 927 |
default=96, |
| 928 |
help="Bitmap resolution in dots per inch (DPI). (Default: 96 DPI," |
| 929 |
" except png_print, 600 DPI) Low resolution bitmaps (DPI<300)" |
| 930 |
" are antialiased.", |
| 931 |
metavar="DPI", |
| 932 |
) |
| 933 |
|
| 934 |
advanced_grp.add_option( |
| 935 |
"", |
| 936 |
"--scale-width", |
| 937 |
dest="scale_width", |
| 938 |
action="store", |
| 939 |
type="boolean", |
| 940 |
default=True, |
| 941 |
metavar="YES/NO", |
| 942 |
help="Scale the visible stack width by the fraction of symbols in the" |
| 943 |
" column? (I.e. columns with many gaps of unknowns are narrow.) " |
| 944 |
"(Default: yes)", |
| 945 |
) |
| 946 |
|
| 947 |
advanced_grp.add_option( |
| 948 |
"", |
| 949 |
"--debug", |
| 950 |
action="store", |
| 951 |
type="boolean", |
| 952 |
default=defaults.debug, |
| 953 |
metavar="YES/NO", |
| 954 |
help="Output additional diagnostic information. (Default: %default)", |
| 955 |
) |
| 956 |
|
| 957 |
advanced_grp.add_option( |
| 958 |
"", |
| 959 |
"--errorbar-fraction", |
| 960 |
dest="errorbar_fraction", |
| 961 |
action="store", |
| 962 |
type="float", |
| 963 |
default=defaults.errorbar_fraction, |
| 964 |
help="Sets error bars display proportion (default: %s)" |
| 965 |
% defaults.errorbar_fraction, |
| 966 |
metavar="NUMBER", |
| 967 |
) |
| 968 |
|
| 969 |
advanced_grp.add_option( |
| 970 |
"", |
| 971 |
"--errorbar-width-fraction", |
| 972 |
dest="errorbar_width_fraction", |
| 973 |
action="store", |
| 974 |
type="float", |
| 975 |
default=defaults.errorbar_width_fraction, |
| 976 |
help="Sets error bars width display proportion (default: %s)" |
| 977 |
% defaults.errorbar_width_fraction, |
| 978 |
metavar="NUMBER", |
| 979 |
) |
| 980 |
|
| 981 |
advanced_grp.add_option( |
| 982 |
"", |
| 983 |
"--errorbar-gray", |
| 984 |
dest="errorbar_gray", |
| 985 |
action="store", |
| 986 |
type="float", |
| 987 |
default=defaults.errorbar_gray, |
| 988 |
help="Sets error bars' gray scale percentage (default: %s)" |
| 989 |
% defaults.errorbar_gray, |
| 990 |
metavar="NUMBER", |
| 991 |
) |
| 992 |
|
| 993 |
# ========================== Server options ========================= |
| 994 |
server_grp.add_option( |
| 995 |
"", |
| 996 |
"--serve", |
| 997 |
dest="serve", |
| 998 |
action="store_true", |
| 999 |
default=False, |
| 1000 |
help="Start a standalone WebLogo server for creating sequence logos.", |
| 1001 |
) |
| 1002 |
|
| 1003 |
server_grp.add_option( |
| 1004 |
"", |
| 1005 |
"--port", |
| 1006 |
dest="port", |
| 1007 |
action="store", |
| 1008 |
type="int", |
| 1009 |
default=8080, |
| 1010 |
help="Listen to this local port. (Default: %default)", |
| 1011 |
metavar="PORT", |
| 1012 |
) |
| 1013 |
|
| 1014 |
return parser |
| 1015 |
|
| 1016 |
# END _build_option_parser |
| 1017 |
|
| 1018 |
|
| 1019 |
############################################################## |