Skip to content

Commit

Permalink
Merge pull request #56 from rki-mf1/fix/v.1
Browse files Browse the repository at this point in the history
July Patch - Bug Fix
  • Loading branch information
stephan-fuchs authored Jul 4, 2022
2 parents 2a3c31b + 5004bd7 commit d4d18c1
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4
1.1.5
2 changes: 1 addition & 1 deletion lib/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4
1.1.5
12 changes: 12 additions & 0 deletions lib/Lineages_UPDATER.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def download_source(tmp_dir):

def process_lineage(alias_key_path, lineages_path, output):
print('Calculate all lineages')
# handle duplicate values
with open(alias_key_path) as f:
# load json objects to dictionaries
data_dict = json.load(f)

for k, v in data_dict.items():
if type(v) is list:
data_dict[k] = list(set(v))
# rewrite the json
with open(alias_key_path ,'w') as nf:
json.dump(data_dict, nf)

aliasor = Aliasor(alias_key_path)
df_lineages = pd.read_csv(lineages_path)
lineages = df_lineages.lineage.unique()
Expand Down
273 changes: 269 additions & 4 deletions lib/lineage.all.tsv

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions lib/sonardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,6 @@ def match(self,
profile_clause[-1] = "(" + " AND ".join(profile_clause[-1]) + ")"
else:
profile_clause[-1] = profile_clause[-1][0]

if len(profile_clause) > 1:
where_clause.append("(" + " OR ".join(profile_clause) + ")")
else:
Expand Down Expand Up @@ -2704,7 +2703,25 @@ def make_profile_explicit(self, profile):
for var in profile:
key = "dna" if self.isdnavar(var) else "aa"
extended_profile[key].extend([v for v in self.pinpoint_mutation(var, self.codedict[key]['code'])])
return extended_profile
return extended_profile

def _fix_X_N_search(self, _profiles):
temp_include_profiles = []
for _list_var in _profiles:
for var in _list_var:
if (var[-1].lower() == 'x') and not self.isdnavar(var):
for v in self.pinpoint_mutation(var, self.codedict["aa"]['code']):
temp_include_profiles.append([v])

elif(var[-1].lower() == 'n') and self.isdnavar(var):
for v in self.pinpoint_mutation(var, self.codedict["dna"]['code']):
temp_include_profiles.append([v])

_profiles.extend(temp_include_profiles)
_profiles = [list(x) for x in set(tuple(x) for x in _profiles)]
#print("After update")
#print(_profiles)
return _profiles


def match(self,
Expand Down Expand Up @@ -2850,13 +2867,14 @@ def match(self,
sys.exit("input error: matching a given software version needs a software defined.")

# adding conditions of profiles to include to where clause
#print(include_profiles)
# print(include_profiles)
if include_profiles:
include_profiles = [ self.make_profile_explicit(x) for x in include_profiles ]
include_profiles = self._fix_X_N_search(include_profiles)
include_profiles = [ self.make_profile_explicit(x) for x in include_profiles ] # Fix here
# adding conditions of profiles to exclude to where clause
if exclude_profiles:
exclude_profiles = self._fix_X_N_search(exclude_profiles)
exclude_profiles = [ self.make_profile_explicit(x) for x in exclude_profiles ]
#print(include_profiles)
# adding accession, lineage, zips, and dates based conditions
include_acc = [x for x in accessions if not x.startswith("^")]
exclude_acc = [x[1:] for x in accessions if x.startswith("^")]
Expand Down Expand Up @@ -2967,6 +2985,8 @@ def match(self,


include_lin = _tmp_include_lin
#print(include_profiles)
#print(include_lin)

########################
rows = dbm.match(
Expand Down
4 changes: 2 additions & 2 deletions sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#author: Stephan Fuchs (Robert Koch Institute, MF1, fuchss@rki.de)

VERSION = "1.1.4"
VERSION = "1.1.5"
import os
from posixpath import split
import sys
Expand Down Expand Up @@ -82,7 +82,7 @@ def parse_args():
parser_match_g2 = parser_match.add_mutually_exclusive_group()
parser_match_g2.add_argument('--only_frameshifts', help="show only genomes containing one or more frameshift mutations", action="store_true")
parser_match_g2.add_argument('--no_frameshifts', help="show only genomes containing no frameshift mutation", action="store_true")
parser_match_g2.add_argument('--tsv', help="use tsv instead of csv output", action="store_true")
parser_match.add_argument('--tsv', help="use tsv instead of csv output", action="store_true")
parser_match.add_argument('--debug', help="show database query for debugging", action="store_true")

#create the parser for the "restore" command
Expand Down

0 comments on commit d4d18c1

Please sign in to comment.