cellmaps-utils 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cellmaps_utils/__init__.py +9 -0
- cellmaps_utils/apms_readme.txt +85 -0
- cellmaps_utils/apms_zmadex_saint_readme.txt +165 -0
- cellmaps_utils/apmstool.py +945 -0
- cellmaps_utils/basecmdtool.py +108 -0
- cellmaps_utils/cellmaps_utilscmd.py +133 -0
- cellmaps_utils/challenge.py +1000 -0
- cellmaps_utils/constants.py +392 -0
- cellmaps_utils/crispr_readme.txt +19 -0
- cellmaps_utils/crisprtool.py +369 -0
- cellmaps_utils/ddotconverter.py +285 -0
- cellmaps_utils/exceptions.py +15 -0
- cellmaps_utils/hcx_utils.py +198 -0
- cellmaps_utils/hidefconverter.py +245 -0
- cellmaps_utils/hierdiff.py +142 -0
- cellmaps_utils/ifimage_readme.txt +31 -0
- cellmaps_utils/iftool.py +657 -0
- cellmaps_utils/logutils.py +214 -0
- cellmaps_utils/music_utils.py +246 -0
- cellmaps_utils/ndexupload.py +193 -0
- cellmaps_utils/provenance.py +890 -0
- cellmaps_utils/secms_readme.txt +81 -0
- cellmaps_utils/secmstool.py +262 -0
- cellmaps_utils/statsgenerator.py +237 -0
- cellmaps_utils/tabletool.py +399 -0
- cellmaps_utils-0.10.0.data/scripts/cellmaps_utilscmd.py +133 -0
- cellmaps_utils-0.10.0.dist-info/AUTHORS.rst +20 -0
- cellmaps_utils-0.10.0.dist-info/LICENSE +22 -0
- cellmaps_utils-0.10.0.dist-info/METADATA +275 -0
- cellmaps_utils-0.10.0.dist-info/RECORD +32 -0
- cellmaps_utils-0.10.0.dist-info/WHEEL +5 -0
- cellmaps_utils-0.10.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import argparse
|
|
6
|
+
import logging
|
|
7
|
+
import cellmaps_utils
|
|
8
|
+
from cellmaps_utils import constants
|
|
9
|
+
from cellmaps_utils.exceptions import CellMapsError
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BaseCommandLineTool(object):
|
|
15
|
+
"""
|
|
16
|
+
Base class for all command line tools.
|
|
17
|
+
Command line tools MUST subclass this
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
COMMAND = 'BaseCommandLineTool'
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
"""
|
|
24
|
+
Constructor
|
|
25
|
+
"""
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
def save_dataset_info_to_json(self, outdir, info_dict, file_name):
|
|
29
|
+
"""
|
|
30
|
+
Saves project information to a JSON file.
|
|
31
|
+
|
|
32
|
+
:param outdir: Output directory where the file will be saved
|
|
33
|
+
:param info_dict: Dictionary with dataset information
|
|
34
|
+
:param file_name: Name of the file to save the information.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
json_str = json.dumps(info_dict, indent=4)
|
|
38
|
+
|
|
39
|
+
json_file_path = os.path.join(outdir, file_name)
|
|
40
|
+
|
|
41
|
+
with open(json_file_path, 'w') as json_file:
|
|
42
|
+
json_file.write(json_str)
|
|
43
|
+
|
|
44
|
+
def run(self):
|
|
45
|
+
"""
|
|
46
|
+
Should contain logic that will be run by command line tool.
|
|
47
|
+
This must be implemented by sub classes and will always raise
|
|
48
|
+
an error
|
|
49
|
+
|
|
50
|
+
:raises CellMapsError: will always raise this
|
|
51
|
+
:return:
|
|
52
|
+
"""
|
|
53
|
+
raise CellMapsError('Must be implemented by subclass')
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def add_subparser(subparsers):
|
|
57
|
+
"""
|
|
58
|
+
Should add any argparse commandline arguments to **subparsers** passed in
|
|
59
|
+
This must be implemented by sub classes and will always raise
|
|
60
|
+
an error
|
|
61
|
+
|
|
62
|
+
:param subparsers:
|
|
63
|
+
:type subparsers: argparse
|
|
64
|
+
:return:
|
|
65
|
+
"""
|
|
66
|
+
raise CellMapsError('Must be implemented by subclass')
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class HelloWorldCommand(BaseCommandLineTool):
|
|
70
|
+
"""
|
|
71
|
+
Simply prints Hello World and returns 0 always
|
|
72
|
+
"""
|
|
73
|
+
COMMAND = 'helloworld'
|
|
74
|
+
|
|
75
|
+
def __init__(self, theargs):
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
:param theargs:
|
|
79
|
+
"""
|
|
80
|
+
super().__init__()
|
|
81
|
+
|
|
82
|
+
def run(self):
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
:return:
|
|
86
|
+
"""
|
|
87
|
+
sys.stdout.write('Hello world\n')
|
|
88
|
+
return 0
|
|
89
|
+
|
|
90
|
+
def add_subparser(subparsers):
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
:return:
|
|
94
|
+
"""
|
|
95
|
+
desc = """
|
|
96
|
+
|
|
97
|
+
Version {version}
|
|
98
|
+
|
|
99
|
+
{cmd} prints Hello world and exits
|
|
100
|
+
""".format(version=cellmaps_utils.__version__,
|
|
101
|
+
cmd=HelloWorldCommand.COMMAND)
|
|
102
|
+
|
|
103
|
+
parser = subparsers.add_parser(HelloWorldCommand.COMMAND,
|
|
104
|
+
help='Prints Hello world and exits',
|
|
105
|
+
description=desc,
|
|
106
|
+
formatter_class=constants.ArgParseFormatter)
|
|
107
|
+
|
|
108
|
+
return parser
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#! /usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
import logging
|
|
6
|
+
import logging.config
|
|
7
|
+
import traceback
|
|
8
|
+
import json
|
|
9
|
+
import warnings
|
|
10
|
+
|
|
11
|
+
import cellmaps_utils
|
|
12
|
+
from cellmaps_utils import logutils
|
|
13
|
+
from cellmaps_utils import constants
|
|
14
|
+
from cellmaps_utils.exceptions import CellMapsError
|
|
15
|
+
from cellmaps_utils.basecmdtool import HelloWorldCommand
|
|
16
|
+
from cellmaps_utils.apmstool import APMSDataLoader
|
|
17
|
+
from cellmaps_utils.iftool import IFImageDataConverter
|
|
18
|
+
from cellmaps_utils.crisprtool import CRISPRDataLoader
|
|
19
|
+
from cellmaps_utils.tabletool import TableFromROCrates
|
|
20
|
+
from cellmaps_utils.challenge import TwoReplCoelutionChallengeGenerator
|
|
21
|
+
from cellmaps_utils.challenge import SolutionGenerator
|
|
22
|
+
from cellmaps_utils.secmstool import SECMSDataConverter
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _parse_arguments(desc, args):
|
|
29
|
+
"""
|
|
30
|
+
Parses command line arguments
|
|
31
|
+
|
|
32
|
+
:param desc: description to display on command line
|
|
33
|
+
:type desc: str
|
|
34
|
+
:param args: command line arguments usually :py:func:`sys.argv[1:]`
|
|
35
|
+
:type args: list
|
|
36
|
+
:return: arguments parsed by :py:mod:`argparse`
|
|
37
|
+
:rtype: :py:class:`argparse.Namespace`
|
|
38
|
+
"""
|
|
39
|
+
parser = argparse.ArgumentParser(description=desc,
|
|
40
|
+
formatter_class=constants.ArgParseFormatter)
|
|
41
|
+
|
|
42
|
+
subparsers = parser.add_subparsers(dest='command',
|
|
43
|
+
help='Command to run. '
|
|
44
|
+
'Type <command> -h for '
|
|
45
|
+
'more help')
|
|
46
|
+
subparsers.required = True
|
|
47
|
+
|
|
48
|
+
HelloWorldCommand.add_subparser(subparsers)
|
|
49
|
+
APMSDataLoader.add_subparser(subparsers)
|
|
50
|
+
IFImageDataConverter.add_subparser(subparsers)
|
|
51
|
+
CRISPRDataLoader.add_subparser(subparsers)
|
|
52
|
+
TableFromROCrates.add_subparser(subparsers)
|
|
53
|
+
TwoReplCoelutionChallengeGenerator.add_subparser(subparsers)
|
|
54
|
+
SolutionGenerator.add_subparser(subparsers)
|
|
55
|
+
SECMSDataConverter.add_subparser(subparsers)
|
|
56
|
+
|
|
57
|
+
parser.add_argument('--logconf', default=None,
|
|
58
|
+
help='Path to python logging configuration file in '
|
|
59
|
+
'this format: https://docs.python.org/3/library/'
|
|
60
|
+
'logging.config.html#logging-config-fileformat '
|
|
61
|
+
'Setting this overrides -v parameter which uses '
|
|
62
|
+
' default logger. (default None)')
|
|
63
|
+
parser.add_argument('--verbose', '-v', action='count', default=1,
|
|
64
|
+
help='Increases verbosity of logger to standard '
|
|
65
|
+
'error for log messages in this module. Messages are '
|
|
66
|
+
'output at these python logging levels '
|
|
67
|
+
'-v = WARNING, -vv = INFO, '
|
|
68
|
+
'-vvv = DEBUG, -vvvv = NOTSET (default ERROR '
|
|
69
|
+
'logging)')
|
|
70
|
+
parser.add_argument('--version', action='version',
|
|
71
|
+
version=('%(prog)s ' +
|
|
72
|
+
cellmaps_utils.__version__))
|
|
73
|
+
|
|
74
|
+
return parser.parse_args(args)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main(args):
|
|
78
|
+
"""
|
|
79
|
+
Main entry point for program
|
|
80
|
+
|
|
81
|
+
:param args: arguments passed to command line usually :py:func:`sys.argv[1:]`
|
|
82
|
+
:type args: list
|
|
83
|
+
|
|
84
|
+
:return: return value of :py:meth:`cellmaps_imagedownloader.runner.CellmapsImageDownloader.run`
|
|
85
|
+
or ``2`` if an exception is raised
|
|
86
|
+
:rtype: int
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
desc = """
|
|
90
|
+
Version {version}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
""".format(version=cellmaps_utils.__version__)
|
|
96
|
+
theargs = _parse_arguments(desc, args[1:])
|
|
97
|
+
theargs.program = args[0]
|
|
98
|
+
theargs.version = cellmaps_utils.__version__
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
logutils.setup_cmd_logging(theargs)
|
|
102
|
+
logger.debug('Command is: ' + str(theargs.command))
|
|
103
|
+
if theargs.command == HelloWorldCommand.COMMAND:
|
|
104
|
+
cmd = HelloWorldCommand(theargs)
|
|
105
|
+
elif theargs.command == APMSDataLoader.COMMAND:
|
|
106
|
+
cmd = APMSDataLoader(theargs)
|
|
107
|
+
elif theargs.command == IFImageDataConverter.COMMAND:
|
|
108
|
+
cmd = IFImageDataConverter(theargs)
|
|
109
|
+
elif theargs.command == CRISPRDataLoader.COMMAND:
|
|
110
|
+
cmd = CRISPRDataLoader(theargs)
|
|
111
|
+
elif theargs.command == TableFromROCrates.COMMAND:
|
|
112
|
+
cmd = TableFromROCrates(theargs)
|
|
113
|
+
elif theargs.command == TwoReplCoelutionChallengeGenerator.COMMAND:
|
|
114
|
+
cmd = TwoReplCoelutionChallengeGenerator(theargs)
|
|
115
|
+
elif theargs.command == SolutionGenerator.COMMAND:
|
|
116
|
+
cmd = SolutionGenerator(theargs)
|
|
117
|
+
elif theargs.command == SECMSDataConverter.COMMAND:
|
|
118
|
+
cmd = SECMSDataConverter(theargs)
|
|
119
|
+
else:
|
|
120
|
+
raise CellMapsError('Invalid command: ' + str(theargs.command))
|
|
121
|
+
return cmd.run()
|
|
122
|
+
|
|
123
|
+
except Exception as e:
|
|
124
|
+
logger.exception('Caught exception: ' + str(e))
|
|
125
|
+
sys.stderr.write('\n\nCaught Exception ' + str(e))
|
|
126
|
+
traceback.print_exc()
|
|
127
|
+
return 2
|
|
128
|
+
finally:
|
|
129
|
+
logging.shutdown()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == '__main__': # pragma: no cover
|
|
133
|
+
sys.exit(main(sys.argv))
|