Skip to content

Commit 0b7408f

Browse files
committed
Merge branch 'dev'
2 parents 1f518d1 + 13ec8ed commit 0b7408f

File tree

13 files changed

+282
-777
lines changed

13 files changed

+282
-777
lines changed

cravat/admin_util.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import signal
2424
import subprocess
2525
from urllib.error import HTTPError
26+
from pathlib import Path
2627

2728
class InstallProgressHandler(object):
2829
def __init__(self, module_name, module_version):
@@ -1334,12 +1335,23 @@ def load_yml_conf(yml_conf_path):
13341335
return conf
13351336

13361337

1337-
def make_example_input(d):
1338-
fn = "example_input"
1339-
ifn = os.path.join(constants.packagedir, fn)
1340-
ofn = os.path.join(d, fn)
1341-
shutil.copyfile(ifn, ofn)
1342-
print(fn + " has been created at " + os.path.abspath(d))
1338+
def make_example_input(out_directory, type='cravat'):
1339+
if type == 'cravat':
1340+
out_fn = 'example_input'
1341+
elif type == 'vcf':
1342+
out_fn = 'example_input.vcf'
1343+
elif type == 'hgvs':
1344+
out_fn = 'example_input.hgvs.txt'
1345+
elif type == 'dbsnp':
1346+
out_fn = 'example_input.rsid.txt'
1347+
else:
1348+
raise ValueError(f'Invalid example input type: {type}')
1349+
out_path = Path(out_directory)/out_fn
1350+
in_path = constants.example_input_paths.get(type)
1351+
if in_path is None:
1352+
raise ValueError(f'Invalid example input type: {type}')
1353+
shutil.copyfile(in_path, out_path)
1354+
return out_path
13431355

13441356

13451357
def module_exists_local(module_name):

cravat/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import platform
77
import yaml
8+
from pathlib import Path
89

910
# Directories
1011
custom_modules_dir = None
@@ -81,6 +82,14 @@
8182
if os.path.exists(main_conf_path) == False:
8283
shutil.copyfile(os.path.join(packagedir, main_conf_fname), main_conf_path)
8384

85+
# Example inputs
86+
example_input_paths = {
87+
'cravat': Path(packagedir)/'websubmit'/'input-examples'/'cravat.hg38.txt',
88+
'vcf': Path(packagedir)/'websubmit'/'input-examples'/'vcf.hg38.txt',
89+
'hgvs': Path(packagedir)/'websubmit'/'input-examples'/'hgvs.hg38.txt',
90+
'dbsnp': Path(packagedir)/'websubmit'/'input-examples'/'dbsnp.hg38.txt',
91+
}
92+
8493
# Base modules
8594
base_modules = [
8695
'cravat-converter',

cravat/cravat_admin.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,12 @@ def send_verify_email (args):
441441
def check_login (args):
442442
au.check_login(args.username, args.password)
443443

444-
def make_example_input (arg):
445-
au.make_example_input(arg.directory)
444+
def make_example_input (args):
445+
if args.type == 'dbsnp' and au.get_local_module_info('dbsnp-converter') is None:
446+
print('Must install dbsnp-converter.')
447+
exit(1)
448+
out_path = au.make_example_input(args.directory, type=args.type)
449+
print(out_path)
446450

447451
def new_annotator (args):
448452
if args.md is not None:
@@ -793,8 +797,15 @@ def show_version (args):
793797
# test input file
794798
parser_make_example_input = subparsers.add_parser('make-example-input',
795799
help='makes a file with example input variants.')
796-
parser_make_example_input.add_argument('directory', default='',
797-
help='Directory to make the example input file in')
800+
parser_make_example_input.add_argument('directory',
801+
default=os.getcwd(),
802+
nargs='?',
803+
help='Directory to make the example input file in')
804+
parser_make_example_input.add_argument('--type','-t',
805+
choices=list(constants.example_input_paths.keys()),
806+
default='cravat',
807+
required=False,
808+
help='Type of example input')
798809
parser_make_example_input.set_defaults(func=make_example_input)
799810

800811
# new-annotator

cravat/cravat_class.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def __init__(self, **kwargs):
345345
self.annotators = {}
346346
self.append_mode = False
347347
self.pipeinput = False
348+
self.samples = set()
348349
try:
349350
self.metricObj = metrics.cravatMetrics()
350351
self.make_args_namespace(kwargs)
@@ -658,6 +659,7 @@ async def main(self):
658659
print("Check {}".format(self.log_path))
659660
self.update_status("Error", force=True)
660661
self.metricObj.set_job_data('success',success)
662+
self.metricObj.set_job_data('sampleCount', len(self.samples))
661663
self.metricObj.do_job_metrics(self)
662664
self.close_logger()
663665
if self.args.do_not_change_status != True:
@@ -1273,6 +1275,7 @@ def run_converter(self):
12731275
converter_class = util.load_class(module.script_path, "MasterCravatConverter")
12741276
converter = converter_class(arg_dict)
12751277
self.numinput, self.converter_format = converter.run()
1278+
self.samples = converter.samples
12761279

12771280
def run_genemapper(self):
12781281
module = au.get_local_module_info(self.cravat_conf["genemapper"])

cravat/cravat_convert.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, *inargs, **inkwargs):
8585
self.crl_writer = None
8686
self.primary_converter = None
8787
self.converters = {}
88+
self.samples = set()
8889
self.possible_formats = []
8990
self.ready_to_convert = False
9091
self.chromdict = {
@@ -457,6 +458,8 @@ def run(self):
457458
)
458459
else:
459460
wdict["sample_id"] = samp_prefix
461+
# keep track of samples
462+
self.samples.add(wdict.get("sample_id", ""))
460463
if "ref_base" not in wdict or wdict["ref_base"] == "":
461464
wdict["ref_base"] = self.wgsreader.get_bases(
462465
chrom, int(wdict["pos"])

0 commit comments

Comments
 (0)