Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev min dist fix #25

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions genomic_address_service/classes/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self,dist_file,membership_file,threshold_map,linkage_method,address
self.assignments = {}
self.nomenclature_cluster_tracker = {}
self.query_ids = set()

if not linkage_method in self.avail_methods:
self.status = False
self.error_msgs.append(f'Provided {linkage_method} is not one of the accepted {self.avail_methods}')
Expand Down Expand Up @@ -182,14 +181,12 @@ def assign(self, n_records=1000,delim="\t"):
query_addr = [None] * num_ranks
if qid in self.memberships_dict:
continue

for rid in dists[qid]:
if rid == qid or rid not in self.memberships_dict:
continue
pairwise_dist = dists[qid][rid]
thresh_idx = self.get_threshold_idx(pairwise_dist)
thresh_value = self.thresholds[thresh_idx]

#save unnecessary work
if thresh_value >= pairwise_dist:
ref_address = self.memberships_dict[rid].split('.')[0:thresh_idx+1]
Expand All @@ -201,27 +198,26 @@ def assign(self, n_records=1000,delim="\t"):
addr_members = self.memberships_lookup[addr]
addr_dists = []
for id in addr_members:
addr_dists.append(dists[qid][id])
if id in dists[qid]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is still useful to remove the samples with distances below minimum threshold, and use this to avoid the key error?

addr_dists.append(dists[qid][id])
if len(addr_dists) == 0:
continue
summary = self.get_dist_summary(addr_dists)

is_eligible = True
if self.linkage_method == 'complete' and summary['max'] > thresh_value:
is_eligible = False
elif self.linkage_method == 'average' and summary['mean'] > thresh_value:
is_eligible = False

if is_eligible:
for idx,value in enumerate(addr.split('.')):
query_addr[idx] = value
break
thresh_value = self.thresholds[thresh_idx-1]

for idx,value in enumerate(query_addr):
if value is None:
query_addr[idx] = self.nomenclature_cluster_tracker[rank_ids[idx]]
self.nomenclature_cluster_tracker[rank_ids[idx]]+=1

break

self.memberships_dict[qid] = ".".join([str(x) for x in query_addr])
24 changes: 9 additions & 15 deletions genomic_address_service/classes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def guess_file_type(self,f):
return file_type

def guess_dist_type(self, fpath, ftype, delim="\t"):
header = []
num_rows = 0
if ftype == 'text':
header = get_file_header(fpath).split(delim)
num_rows = get_file_length(fpath)
Expand All @@ -53,7 +55,9 @@ def read_pd(self):
continue
qid = line[0]
rid = line[1]

d = float(line[2])
#print(f'{qid} {rid} {d}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this a vestige of testing

if qid not in self.record_ids and len(self.dists) >= self.n_records:
self.sort_distances()
yield self.dists
Expand All @@ -62,15 +66,10 @@ def read_pd(self):
if qid not in self.record_ids:
self.record_ids.add(qid)
self.dists[qid] = {}
if self.filter:
if self.min_dist is not None:
if d < self.min_dist:
continue
if self.max_dist is not None:
if d > self.max_dist:
continue
self.dists[qid][rid] = d
self.sort_distances()

yield self.dists


def sort_distances(self):
Expand All @@ -95,13 +94,6 @@ def read_matrix(self):
for i in range(0,len(values)):
rid = self.header[i]
d = values[i]
if self.filter:
if self.min_dist is not None:
if d < self.min_dist:
continue
if self.max_dist is not None:
if d > self.max_dist:
continue
self.dists[qid][rid] = d
self.sort_distances()

Expand All @@ -115,6 +107,7 @@ def read_data(self):
self.header = next(self.file_handle).split(self.delim)
elif ftype == 'parquet':
self.file_handle = ParquetFile(self.fpath)

if ftype == 'text' and dist_type == 'pd':
for chunk in self.read_pd():
if chunk is not None:
Expand All @@ -127,7 +120,8 @@ def read_data(self):
yield chunk
if chunk is None:
chunk = self.dists
yield chunk

return chunk



Expand Down