Skip to content

Commit 17fc926

Browse files
committed
Now passed tests for 4 and 5loci.
1 parent b116414 commit 17fc926

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

grma/match/donors_matching.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ def __classes_and_subclasses_from_genotype(self, genotype: HashableArray):
214214
subclasses = []
215215
ALLELES_IN_CLASS_I = -2*int(-len(genotype)/4-0.5)
216216
ALLELES_IN_CLASS_II = len(genotype) - ALLELES_IN_CLASS_I
217-
classes = [genotype[:ALLELES_IN_CLASS_I], genotype[ALLELES_IN_CLASS_I:]]
217+
classes = [(genotype[:ALLELES_IN_CLASS_I], 0), (genotype[ALLELES_IN_CLASS_I:], 1)]
218218
num_of_alleles_in_class = [ALLELES_IN_CLASS_I, ALLELES_IN_CLASS_II]
219219

220-
int_classes = [tuple_geno_to_int(tuple(clss)) for clss in classes]
220+
int_classes = [(tuple_geno_to_int(tuple(clss[0])), clss[1]) for clss in classes]
221221
for clss in int_classes:
222-
self._patients_graph.add_edge(clss, genotype)
222+
self._patients_graph.add_edge(clss[0], genotype)
223223

224224
# class one is considered as 0.
225225
# class two is considered as 1.
@@ -229,14 +229,14 @@ def __classes_and_subclasses_from_genotype(self, genotype: HashableArray):
229229
# set the missing allele to always be the second allele in the locus
230230
if k % 2 == 0:
231231
sub = tuple_geno_to_int(
232-
classes[class_num][0:k] + ZEROS + classes[class_num][k + 1 :]
232+
classes[class_num][0][0:k] + ZEROS + classes[class_num][0][k + 1 :]
233233
)
234234
else:
235235
sub = tuple_geno_to_int(
236-
classes[class_num][0 : k - 1]
236+
classes[class_num][0][0 : k - 1]
237237
+ ZEROS
238-
+ classes[class_num][k - 1 : k]
239-
+ classes[class_num][k + 1 :]
238+
+ classes[class_num][0][k - 1 : k]
239+
+ classes[class_num][0][k + 1 :]
240240
)
241241

242242
# missing allele number is the index of the first allele of the locus the missing allele belongs to.
@@ -357,9 +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([x for x in range(0, len(geno)//2 + (len(geno)//2 & 1), 2)], dtype=np.uint8)
360+
allele_range_to_check = np.array([x for x in range(len(geno)//2 + (len(geno)//2 & 1), len(geno), 2)] + [subclass.allele_num], dtype=np.uint8)
361361
else:
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)
362+
allele_range_to_check = np.array([x for x in range(0, len(geno)//2 + (len(geno)//2 & 1), 2)] + [subclass.allele_num], dtype=np.uint8)
363363

364364
# number of alleles that already match due to match in subclass
365365
matched_alleles: int = (
@@ -396,7 +396,7 @@ def find_geno_candidates_by_classes(self, classes):
396396
# Class I appearances: 3 locuses = 6 alleles = 23/24 digits
397397
# Class II appearances: 2 locuses = 4 alleles = 15/16 digits
398398
geno = list(self.patients.values())[0]
399-
if clss[1] == 1:
399+
if clss[1] == 0:
400400
allele_range_to_check = np.array([x for x in range(len(geno)//2 + (len(geno)//2 & 1), len(geno), 2)], dtype=np.uint8)
401401
matched_alleles: int = len(geno)//2 + (len(geno)//2 & 1)
402402

grma/match/match.py

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

163159
# wierd_edges = {}
164160
# for patient in g_m.patients:

0 commit comments

Comments
 (0)