Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoad committed Sep 26, 2024
2 parents 1f518d1 + 13ec8ed commit 0b7408f
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 777 deletions.
24 changes: 18 additions & 6 deletions cravat/admin_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import signal
import subprocess
from urllib.error import HTTPError
from pathlib import Path

class InstallProgressHandler(object):
def __init__(self, module_name, module_version):
Expand Down Expand Up @@ -1334,12 +1335,23 @@ def load_yml_conf(yml_conf_path):
return conf


def make_example_input(d):
fn = "example_input"
ifn = os.path.join(constants.packagedir, fn)
ofn = os.path.join(d, fn)
shutil.copyfile(ifn, ofn)
print(fn + " has been created at " + os.path.abspath(d))
def make_example_input(out_directory, type='cravat'):
if type == 'cravat':
out_fn = 'example_input'
elif type == 'vcf':
out_fn = 'example_input.vcf'
elif type == 'hgvs':
out_fn = 'example_input.hgvs.txt'
elif type == 'dbsnp':
out_fn = 'example_input.rsid.txt'
else:
raise ValueError(f'Invalid example input type: {type}')
out_path = Path(out_directory)/out_fn
in_path = constants.example_input_paths.get(type)
if in_path is None:
raise ValueError(f'Invalid example input type: {type}')
shutil.copyfile(in_path, out_path)
return out_path


def module_exists_local(module_name):
Expand Down
9 changes: 9 additions & 0 deletions cravat/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import platform
import yaml
from pathlib import Path

# Directories
custom_modules_dir = None
Expand Down Expand Up @@ -81,6 +82,14 @@
if os.path.exists(main_conf_path) == False:
shutil.copyfile(os.path.join(packagedir, main_conf_fname), main_conf_path)

# Example inputs
example_input_paths = {
'cravat': Path(packagedir)/'websubmit'/'input-examples'/'cravat.hg38.txt',
'vcf': Path(packagedir)/'websubmit'/'input-examples'/'vcf.hg38.txt',
'hgvs': Path(packagedir)/'websubmit'/'input-examples'/'hgvs.hg38.txt',
'dbsnp': Path(packagedir)/'websubmit'/'input-examples'/'dbsnp.hg38.txt',
}

# Base modules
base_modules = [
'cravat-converter',
Expand Down
19 changes: 15 additions & 4 deletions cravat/cravat_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,12 @@ def send_verify_email (args):
def check_login (args):
au.check_login(args.username, args.password)

def make_example_input (arg):
au.make_example_input(arg.directory)
def make_example_input (args):
if args.type == 'dbsnp' and au.get_local_module_info('dbsnp-converter') is None:
print('Must install dbsnp-converter.')
exit(1)
out_path = au.make_example_input(args.directory, type=args.type)
print(out_path)

def new_annotator (args):
if args.md is not None:
Expand Down Expand Up @@ -793,8 +797,15 @@ def show_version (args):
# test input file
parser_make_example_input = subparsers.add_parser('make-example-input',
help='makes a file with example input variants.')
parser_make_example_input.add_argument('directory', default='',
help='Directory to make the example input file in')
parser_make_example_input.add_argument('directory',
default=os.getcwd(),
nargs='?',
help='Directory to make the example input file in')
parser_make_example_input.add_argument('--type','-t',
choices=list(constants.example_input_paths.keys()),
default='cravat',
required=False,
help='Type of example input')
parser_make_example_input.set_defaults(func=make_example_input)

# new-annotator
Expand Down
3 changes: 3 additions & 0 deletions cravat/cravat_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def __init__(self, **kwargs):
self.annotators = {}
self.append_mode = False
self.pipeinput = False
self.samples = set()
try:
self.metricObj = metrics.cravatMetrics()
self.make_args_namespace(kwargs)
Expand Down Expand Up @@ -658,6 +659,7 @@ async def main(self):
print("Check {}".format(self.log_path))
self.update_status("Error", force=True)
self.metricObj.set_job_data('success',success)
self.metricObj.set_job_data('sampleCount', len(self.samples))
self.metricObj.do_job_metrics(self)
self.close_logger()
if self.args.do_not_change_status != True:
Expand Down Expand Up @@ -1273,6 +1275,7 @@ def run_converter(self):
converter_class = util.load_class(module.script_path, "MasterCravatConverter")
converter = converter_class(arg_dict)
self.numinput, self.converter_format = converter.run()
self.samples = converter.samples

def run_genemapper(self):
module = au.get_local_module_info(self.cravat_conf["genemapper"])
Expand Down
3 changes: 3 additions & 0 deletions cravat/cravat_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self, *inargs, **inkwargs):
self.crl_writer = None
self.primary_converter = None
self.converters = {}
self.samples = set()
self.possible_formats = []
self.ready_to_convert = False
self.chromdict = {
Expand Down Expand Up @@ -457,6 +458,8 @@ def run(self):
)
else:
wdict["sample_id"] = samp_prefix
# keep track of samples
self.samples.add(wdict.get("sample_id", ""))
if "ref_base" not in wdict or wdict["ref_base"] == "":
wdict["ref_base"] = self.wgsreader.get_bases(
chrom, int(wdict["pos"])
Expand Down
Loading

0 comments on commit 0b7408f

Please sign in to comment.