From cccfc463865a44b165643409dd4615de206d147b Mon Sep 17 00:00:00 2001 From: Arie Matsliah Date: Mon, 14 Aug 2023 09:49:58 -0400 Subject: [PATCH] update tests --- tests/experimental/test_ol_tagging.py | 39 +++++++++++++++++++++ tests/unit/test_optic_lobe_types_catalog.py | 17 +++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/experimental/test_ol_tagging.py b/tests/experimental/test_ol_tagging.py index 067d543c..e59096bb 100644 --- a/tests/experimental/test_ol_tagging.py +++ b/tests/experimental/test_ol_tagging.py @@ -2315,3 +2315,42 @@ def types(rids): print( f"{subtype}: {cell_count} cells.\n Input types:\n{format_dict_by_largest_value(input_counts)}\n Output types:\n{format_dict_by_largest_value(output_counts)}" ) + + def test_predicates_with_repetition(self): + tps = ["Dm3v", "Dm3p", "Dm3q"] + olr_predicates_generator = OlrPredicatesGenerator( + self.neuron_db, max_set_size=5, up_threshold=0.2, down_threshold=0.2 + ) + for tp in tps: + cell_ids = [ + rid + for rid, nd in self.neuron_db.neuron_data.items() + if extract_at_most_one_marker(nd, "olr_type") == tp + ] + print(f"========== {tp}: {len(cell_ids)} ==============") + print( + f"Looking for best precision subset for {tp} with {len(cell_ids)} cells" + ) + pdata = olr_predicates_generator.find_best_predicate_for_list( + cell_ids, optimization_metric="f_score", min_score=0 + ) + print( + f"Precision: {pdata['precision']}, recall: {pdata['recall']}, f_score: {pdata['f_score']}" + ) + + def test_count_olt_low_threshold_connections(self): + olr_cells = set( + [ + rid + for rid, nd in self.neuron_db.neuron_data.items() + if extract_at_most_one_marker(nd, "olr_type") + ] + ) + + cons_count = defaultdict(int) + for row in self.neuron_db.connections_.all_rows(): + if True or row[0] in olr_cells and row[1] in olr_cells: + key = min(5, row[3]) + cons_count[key] += 1 + + print(format_dict_by_largest_value(cons_count)) diff --git a/tests/unit/test_optic_lobe_types_catalog.py b/tests/unit/test_optic_lobe_types_catalog.py index 354b3bb6..a859dab9 100644 --- a/tests/unit/test_optic_lobe_types_catalog.py +++ b/tests/unit/test_optic_lobe_types_catalog.py @@ -1,8 +1,11 @@ +import gzip +import pickle import string from collections import defaultdict from unittest import TestCase -from src.configuration import TYPE_PREDICATES_METADATA +from src.configuration import TYPE_PREDICATES_METADATA, APP_ROOT_PATH +from src.data.versions import TESTING_DATA_SNAPSHOT_VERSION from src.data.visual_neuron_types import ( VISUAL_NEURON_TYPES, VISUAL_NEURON_MEGA_TYPE_TO_TYPES, @@ -162,13 +165,21 @@ def all_labels(rid): self.assertFalse(failed) def test_predicates_coverage(self): + # load connections with threshold 2 (instead of 5) + # TODO: make this a util, and update predicate computation module accordingly + with gzip.open( + f"{APP_ROOT_PATH}/static/data/{TESTING_DATA_SNAPSHOT_VERSION}/no_threshold_connections.pickle.gz", + "rb", + ) as handle: + self.neuron_db.connections_ = pickle.load(handle) + ins, outs = self.neuron_db.input_output_partner_sets(min_syn_count=2) + def is_ol_neuron(rid): return extract_at_most_one_marker( self.neuron_db.neuron_data[rid], "olr_type" ) # map each neuron to it's upstream/downstream partner types set - ins, outs = self.neuron_db.input_output_partner_sets() ins_type, outs_type = defaultdict(set), defaultdict(set) for k, v in ins.items(): for r in v: @@ -216,7 +227,7 @@ def is_ol_neuron(rid): # check the fraction of OL neurons that have exactly one match (ideally this should reach close to 100%) prct = percentage(ol_rids_with_pred_match_counts[1], num_ol_neurons) print(f"OL one-match percentage: {prct}") - self.assertEqual("75%", prct) + self.assertEqual("79%", prct) def test_excluded_cells(self): excluded_and_olr_rids = []