Skip to content

Commit

Permalink
Merge pull request #24 from cov-lineages/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rmcolq authored Aug 3, 2021
2 parents dcbade4 + 12b9e60 commit d4e505d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion scorpio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
_program = "scorpio"
__version__ = "0.3.8"
__version__ = "0.3.9"
1 change: 1 addition & 0 deletions scorpio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def main(sysargs = sys.argv[1:]):
help="Specify where you want the temporary stuff to go Default: $TMPDIR")
misc_group.add_argument("--no-temp", action="store_true", help="Output all intermediate files")
misc_group.add_argument("--verbose", action="store_true", help="Print lots of stuff to screen")
misc_group.add_argument("--dry-run", dest="dry_run", action="store_true", help="Quit after checking constellations and variants are AOK")
misc_group.add_argument('-t', '--threads', action='store', dest="threads", type=int, help="Number of threads")

# _______________________________ classify __________________________________#
Expand Down
22 changes: 18 additions & 4 deletions scorpio/scripts/type_constellations.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,19 @@ def parse_mutations(refseq, features_dict, mutations_list):
one dict per variant. format of subdict varies by variant type
"""
variant_list = []
problematic = []

for mutation in mutations_list:
record = variant_to_variant_record(mutation, refseq, features_dict)
if record != {}:
variant_list.append(record)
else:
problematic.append(mutation)

if len(problematic) > 0:
sys.stderr.write("The following mutations were not provided in an acceptable format: %s\n\n"
% ",".join(problematic))
sys.exit(1)
return variant_list


Expand Down Expand Up @@ -588,12 +595,12 @@ def generate_barcode(record_seq, variant_list, ref_char=None, ins_char="?", oth_


def type_constellations(in_fasta, list_constellation_files, constellation_names, out_csv, reference_json, ref_char=None,
output_counts=False, label=None, append_genotypes=False, mutations_list=None):
output_counts=False, label=None, append_genotypes=False, mutations_list=None, dry_run=False):
reference_seq, features_dict = load_feature_coordinates(reference_json)

constellation_dict = {}
for constellation_file in list_constellation_files:
constellation, variants, ignore, mrca_lineage, incompatible_lineage_calls = parse_variants_in(reference_seq, features_dict, constellation_file, label=label)
constellation, variants, ignore, mrca_lineage, incompatible_lineage_calls = parse_variants_in(reference_seq, features_dict, constellation_file, constellation_names, label=label)
if not constellation:
continue
if constellation_names and constellation not in constellation_names:
Expand All @@ -612,6 +619,7 @@ def type_constellations(in_fasta, list_constellation_files, constellation_names,
else:
new_mutations_list.append(entry)
mutations_list = new_mutations_list
print("Typing provided mutations %s" % ",".join(mutations_list))
mutation_variants = parse_mutations(reference_seq, features_dict, mutations_list)
if len(constellation_dict) == 1 and "mutations" not in constellation_dict:
constellation = list(constellation_dict)[0]
Expand All @@ -622,8 +630,11 @@ def type_constellations(in_fasta, list_constellation_files, constellation_names,
else:
constellation_dict["mutations"] = mutation_variants

if dry_run:
return

variants_out = None
if len(constellation_dict) > 1 or not output_counts:
if len(constellation_dict) > 1 or not (output_counts or append_genotypes):
variants_out = open(out_csv, "w")
variants_out.write("query,%s\n" % ",".join(list(constellation_dict.keys())))

Expand Down Expand Up @@ -672,7 +683,7 @@ def type_constellations(in_fasta, list_constellation_files, constellation_names,


def classify_constellations(in_fasta, list_constellation_files, constellation_names, out_csv, reference_json,
output_counts=False, call_all=False, long=False, label=None, list_incompatible=False, mutations_list=None):
output_counts=False, call_all=False, long=False, label=None, list_incompatible=False, mutations_list=None, dry_run=False):

reference_seq, features_dict = load_feature_coordinates(reference_json)

Expand Down Expand Up @@ -710,6 +721,9 @@ def classify_constellations(in_fasta, list_constellation_files, constellation_na
mutations_list = new_mutations_list
mutation_variants = parse_mutations(reference_seq, features_dict, mutations_list)

if dry_run:
return

variants_out = open(out_csv, "w")
columns = ["query","constellations","mrca_lineage"]
if list_incompatible:
Expand Down
21 changes: 11 additions & 10 deletions scorpio/subcommands/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

def run(options):
classify_constellations(options.input,
options.constellations,
options.names,
options.output,
options.reference_json,
options.output_counts,
options.call_all,
options.long,
options.label,
options.list_incompatible,
options.mutations)
options.constellations,
options.names,
options.output,
options.reference_json,
options.output_counts,
options.call_all,
options.long,
options.label,
options.list_incompatible,
options.mutations,
options.dry_run)
3 changes: 2 additions & 1 deletion scorpio/subcommands/haplotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def run(options):
options.output_counts,
options.label,
options.append_genotypes,
options.mutations)
options.mutations,
options.dry_run)

0 comments on commit d4e505d

Please sign in to comment.