Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arie-matsliah committed Aug 14, 2023
1 parent ca27697 commit cccfc46
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
39 changes: 39 additions & 0 deletions tests/experimental/test_ol_tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
17 changes: 14 additions & 3 deletions tests/unit/test_optic_lobe_types_catalog.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit cccfc46

Please sign in to comment.