#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pauvre - just a pore plotting package
# Copyright (c) 2016-2017 Darrin T. Schultz. All rights reserved.
#
# This file is part of pauvre.
#
# pauvre is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pauvre is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pauvre. If not, see .
# I modeled this code on https://github.com/arq5x/poretools/. Check it out. - DTS
import sys
import os.path
import argparse
# pauvre imports
import pauvre.version
# This class is used in argparse to expand the ~. This avoids errors caused on
# some systems.
class FullPaths(argparse.Action):
"""Expand user- and relative-paths"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest,
os.path.abspath(os.path.expanduser(values)))
class FullPathsList(argparse.Action):
"""Expand user- and relative-paths when a list of paths is passed to the
program"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest,
[os.path.abspath(os.path.expanduser(value)) for value in values])
def run_subtool(parser, args):
if args.command == 'browser':
import pauvre.browser as submodule
elif args.command == 'custommargin':
import pauvre.custommargin as submodule
elif args.command == 'marginplot':
import pauvre.marginplot as submodule
elif args.command == 'redwood':
import pauvre.redwood as submodule
elif args.command == 'stats':
import pauvre.stats as submodule
elif args.command == 'synplot':
import pauvre.synplot as submodule
# run the chosen submodule.
submodule.run(args)
class ArgumentParserWithDefaults(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
super(ArgumentParserWithDefaults, self).__init__(*args, **kwargs)
self.add_argument("-q", "--quiet", help="Do not output warnings to stderr",
action="store_true",
dest="QUIET")
def main():
#########################################
# create the top-level parser
#########################################
parser = argparse.ArgumentParser(
prog='pauvre', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-v", "--version", help="Installed pauvre version",
action="version",
version="%(prog)s " + str(pauvre.version.__version__))
subparsers = parser.add_subparsers(
title='[sub-commands]', dest='command', parser_class=ArgumentParserWithDefaults)
#########################################
# create the individual tool parsers
#########################################
#############
# browser
#############
parser_browser = subparsers.add_parser('browser',
help="""an adaptable genome
browser with various track types""")
parser_browser.add_argument('-c', '--chromosomeid',
metavar = "Chr",
dest = 'CHR',
type = str,
help = """The fasta sequence to observe.
Use the header name of the fasta file
without the '>' character""")
parser_browser.add_argument('--dpi',
metavar='dpi',
default=600,
type=int,
help="""Change the dpi from the default 600
if you need it higher""")
parser_browser.add_argument('--fileform',
dest='fileform',
metavar='STRING',
choices=['png', 'pdf', 'eps', 'jpeg', 'jpg',
'pdf', 'pgf', 'ps', 'raw', 'rgba',
'svg', 'svgz', 'tif', 'tiff'],
default=['png'],
nargs='+',
help='Which output format would you like? Def.=png')
parser_browser.add_argument("--no_timestamp",
action = 'store_true',
help="""Turn off time stamps in the filename
output.""")
parser_browser.add_argument('-o', '--output-base-name',
dest='BASENAME',
help="""Specify a base name for the output file(
s). The input file base name is the
default.""")
parser_browser.add_argument('--path',
type=str,
help="""Set an explicit filepath for the output.
Only do this if you have selected one output type.""")
parser_browser.add_argument('-p', '--plot_commands',
dest='CMD',
nargs = '+',
help="""Write strings here to select what
to plot. The format for each track is:
::