Skip to content

Commit

Permalink
Merge pull request #34 from cov-lineages/dev
Browse files Browse the repository at this point in the history
small bug fixes
  • Loading branch information
rmcolq committed Oct 27, 2021
2 parents e12eb0e + 00a5e56 commit c0db12f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 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.13"
__version__ = "0.3.14"
2 changes: 1 addition & 1 deletion scorpio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def main(sysargs = sys.argv[1:]):
if not args.reference_json:
args.reference_json = reference_json
logging.info("Found reference %s" %args.reference_json)
if not args.constellations and args.command in ['haplotype', 'classify']:
if not args.constellations and args.command in ['haplotype', 'classify', 'list']:
args.constellations = list_constellation_files
logging.info("Found constellations:")
for c in args.constellations:
Expand Down
12 changes: 6 additions & 6 deletions scorpio/scripts/extract_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_group_dict(in_variants, group_column, index_column, subset):
if subset and row[group_column] not in subset:
continue
if row[index_column] in group_dict:
logging.warning("%s is a duplicate in group CSV, keeping first")
logging.warning("%s is a duplicate in group CSV, keeping first" % row[index_column])
else:
group_dict[row[index_column]] = row[group_column]
groups.add(row[group_column])
Expand Down Expand Up @@ -208,17 +208,17 @@ def define_mutations(list_variants, feature_dict, reference_seq, include_protein
current[3] = new[3]
elif current[0] != "":
var = translate_if_possible(current[1], current[0], current[2], feature_dict, reference_seq, include_protein)
if freq:
merged_list.append("%s:%s" % (var, freq))
if current[3]:
merged_list.append("%s:%s" % (var, current[3]))
else:
merged_list.append(var)
current = new
else:
current = new
if current[0] != "":
var = translate_if_possible(current[1], current[0], current[2], feature_dict, reference_seq, include_protein)
if freq:
merged_list.append("%s:%s" % (var, freq))
if current[3]:
merged_list.append("%s:%s" % (var, current[3]))
else:
merged_list.append(var)
return merged_list
Expand All @@ -237,7 +237,7 @@ def subtract_outgroup(common, outgroup_common):

def write_constellation(prefix, group, list_variants, list_intermediates, list_ancestral):
group_dict = {"name": group, "sites": list_variants, "intermediate": list_intermediates,
"rules": {"min_alt": max(len(list_variants) - 3, min(len(list_variants), 3)), "max_ref": 3}}
"rules": {"min_alt": max(len(list_variants) - 8, min(len(list_variants), 3)), "max_ref": 3}}
if list_ancestral:
group_dict["ancestral"] = list_ancestral
with open('%s/%s.json' % (prefix, group), 'w') as outfile:
Expand Down
24 changes: 13 additions & 11 deletions scorpio/scripts/type_constellations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import re
import logging
import copy
import math

if sys.version_info[0] < 3:
Expand Down Expand Up @@ -293,8 +294,8 @@ def parse_json_in(refseq, features_dict, variants_file, constellation_names=None

in_json.close()
sorted_variants = sorted(variant_list, key=lambda x: int(x["ref_start"]))
for var in sorted_variants:
print(var)
#for var in sorted_variants:
# print(var)

return sorted_variants, name, output_name, rules, mrca_lineage, incompatible_lineage_calls, parent_lineage, lineage_name

Expand Down Expand Up @@ -868,7 +869,7 @@ def type_constellations(in_fasta, list_constellation_files, constellation_names,

out_list = [record.id]
for constellation in constellation_dict:
barcode_list, counts, constellation_count_dict, sorted_alt_sites = generate_barcode(record.seq, constellation_dict[constellation], ref_char, constellation_count_dict=constellation_count_dict)
barcode_list, counts, sample_constellation_count_dict, sorted_alt_sites = generate_barcode(record.seq, constellation_dict[constellation], ref_char, constellation_count_dict=copy.deepcopy(constellation_count_dict))
if output_counts or append_genotypes:
columns = [record.id]
if output_counts:
Expand All @@ -878,15 +879,15 @@ def type_constellations(in_fasta, list_constellation_files, constellation_names,
columns.extend(barcode_list)
if combination:
scores = {}
for candidate in constellation_count_dict:
if constellation_count_dict[candidate]["alt"] > 0:
for candidate in sample_constellation_count_dict:
if sample_constellation_count_dict[candidate]["alt"] > 0:
summary = "%s:%i|%i|%i|%i" % (
candidate, constellation_count_dict[candidate]["ref"],
constellation_count_dict[candidate]["alt"],
constellation_count_dict[candidate]["ambig"],
constellation_count_dict[candidate]["oth"])
score = float(constellation_count_dict[candidate]["alt"]) / \
constellation_count_dict[candidate]["total"]
candidate, sample_constellation_count_dict[candidate]["ref"],
sample_constellation_count_dict[candidate]["alt"],
sample_constellation_count_dict[candidate]["ambig"],
sample_constellation_count_dict[candidate]["oth"])
score = float(sample_constellation_count_dict[candidate]["alt"]) / \
sample_constellation_count_dict[candidate]["total"]
scores[score] = summary
sorted_scores = sorted(scores, key=lambda x: float(x), reverse=True)
columns.append("; ".join([scores[score] for score in sorted_scores]))
Expand Down Expand Up @@ -1086,6 +1087,7 @@ def list_constellations(list_constellation_files, constellation_names, reference
list_of_constellations.add(mrca_lineage)
elif len(variants) > 0:
list_of_constellations.add(output_name)
print("\n".join(list_of_constellations))

def parse_args():
parser = argparse.ArgumentParser(description="""Type an alignment at specific sites and classify with a barcode.""",
Expand Down

0 comments on commit c0db12f

Please sign in to comment.