Skip to content

Commit cf83ff8

Browse files
committed
Moved from hardcoded 5 loci to k-loci. Tested on 4 loci and passes
1 parent e584348 commit cf83ff8

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

grma/match/donors_matching.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __find_genotype_candidates_from_class(
144144
) -> Tuple[np.ndarray, np.ndarray]:
145145
"""Takes an integer subclass.
146146
Returns the genotypes (ids and values) which are connected to it in the graph"""
147-
return self._graph.class_neighbors(clss, Len = len(self.patients[0]))
147+
return self._graph.class_neighbors(clss, Len = len(list(self.patients.values())[0]))
148148

149149
def __find_donor_from_geno(self, geno_id: int) -> Sequence[int]:
150150
"""Gets the LOL ID of a genotype.
@@ -357,14 +357,9 @@ def find_geno_candidates_by_subclasses(self, subclasses):
357357
ALLELES_IN_CLASS_II = len(geno) - ALLELES_IN_CLASS_I
358358
# Checks only the locuses that are not certain to match
359359
if subclass.class_num == 0:
360-
allele_range_to_check = np.array(
361-
[c for c in range(ALLELES_IN_CLASS_I, ALLELES_IN_CLASS_I + ALLELES_IN_CLASS_I - 2, 2)] + [subclass.allele_num],
362-
dtype=np.uint8
363-
)
360+
allele_range_to_check = np.array([x for x in range(0, len(geno)//2 + (len(geno)//2 & 1), 2)], dtype=np.uint8)
364361
else:
365-
allele_range_to_check = np.array(
366-
[c for c in range(0, ALLELES_IN_CLASS_I, 2)] + [subclass.allele_num], dtype=np.uint8
367-
)
362+
allele_range_to_check = np.array([x for x in range(len(geno)//2 + (len(geno)//2 & 1), len(geno), 2)], dtype=np.uint8)
368363

369364
# number of alleles that already match due to match in subclass
370365
matched_alleles: int = (
@@ -388,9 +383,9 @@ def find_geno_candidates_by_classes(self, classes):
388383
desc="finding classes matching candidates",
389384
disable=not self.verbose,
390385
):
391-
if self._graph.in_nodes(clss):
386+
if self._graph.in_nodes(clss[0]):
392387
patient_genos = self._patients_graph.neighbors(
393-
clss
388+
clss[0]
394389
) # The patient's genotypes which might be match
395390
(
396391
genotypes_ids,
@@ -400,12 +395,14 @@ def find_geno_candidates_by_classes(self, classes):
400395
# Checks only the locuses that are not certain to match (the locuses of the other class)
401396
# Class I appearances: 3 locuses = 6 alleles = 23/24 digits
402397
# Class II appearances: 2 locuses = 4 alleles = 15/16 digits
403-
if len(str(clss)) > 20:
404-
allele_range_to_check = np.array([6, 8], dtype=np.uint8)
405-
matched_alleles: int = 6
398+
geno = list(self.patients.values())[0]
399+
if clss[1] == 1:
400+
allele_range_to_check = np.array([x for x in range(len(geno)//2 + (len(geno)//2 & 1), len(geno), 2)], dtype=np.uint8)
401+
matched_alleles: int = len(geno)//2 + (len(geno)//2 & 1)
402+
406403
else:
407-
allele_range_to_check = np.array([0, 2, 4], dtype=np.uint8)
408-
matched_alleles: int = 4
404+
allele_range_to_check = np.array([x for x in range(0, len(geno)//2 + (len(geno)//2 & 1), 2)], dtype=np.uint8)
405+
matched_alleles: int = len(geno)//2 - (len(geno)//2 & 1)
409406

410407
# Compares the candidate to the patient's genotypes, and adds the match geno candidates to the graph.
411408
self.__add_matched_genos_to_graph(
@@ -512,7 +509,7 @@ def score_matches(
512509
].items(): # AMIT ADD
513510
for prob, matches in genotype_matches.values(): # AMIT CHANGE
514511
# match_info = (probability of patient's genotype, number of matches to patient's genotype)
515-
if matches != len(self.patients[1]) - mismatch:
512+
if matches != len(list(self.patients.values())[0]) - mismatch:
516513
continue
517514

518515
# add the probabilities multiplication of the patient and all the donors that has this genotype

grma/match/graph_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_edge_data(
5858
return default if ret == exception_val else ret
5959

6060
def class_neighbors(self, node: NODES_TYPES | int, search_lol_id: bool = False, Len: int = 10):
61-
node_num = self._map_node_to_number[node] if not search_lol_id else node
61+
node_num = self._map_node_to_number[node[0]] if not search_lol_id else node
6262
neighbors_list = self._graph.neighbors_unweighted(node_num)
6363
neighbors_list_values = np.ndarray([len(neighbors_list), Len], dtype=np.uint16)
6464
for i, neighbor in enumerate(neighbors_list):

grma/match/match.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def find_matches(
154154
subclasses_by_patient, classes_by_patient = g_m.create_patients_graph(
155155
imputation_filename
156156
)
157+
for patient_id, class_set in classes_by_patient.items():
158+
classes_by_patient[patient_id] = {
159+
(item, i) for i, item in enumerate(class_set)
160+
}
157161

158162
# wierd_edges = {}
159163
# for patient in g_m.patients:

0 commit comments

Comments
 (0)