Skip to content

Commit 928fed8

Browse files
committed
check all gene exp measurements at once for intersection
1 parent 2d97f07 commit 928fed8

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

siibra/livequeries/allen.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import numpy as np
2222

2323
from . import query as _query
24-
from ..core import space as _space, structure
24+
from ..core import structure
2525
from ..features import anchor as _anchor
2626
from ..features.tabular.gene_expression import GeneExpressions
2727
from ..commons import logger, Species
28-
from ..locations import point, pointcloud
28+
from ..locations import pointcloud
2929
from ..retrieval import HttpRequest
3030
from ..vocabularies import GENE_NAMES
3131

@@ -144,27 +144,25 @@ def query(self, concept: structure.BrainStructure) -> List[GeneExpressions]:
144144
'https://github.com/FZJ-INM1-BDA/siibra-python/issues/636.'
145145
)
146146

147-
mnispace = _space.Space.registry().get('mni152')
148-
149147
# Match the microarray probes to the query mask.
150148
# Record matched instances and their locations.
151-
measurements = []
152-
coordinates = []
153-
for measurement in self:
154-
pt = point.Point(measurement['mni_xyz'], space=mnispace, sigma_mm=LOCATION_PRECISION_MM)
155-
if pt in concept:
156-
measurements.append(measurement)
157-
coordinates.append(pt)
158-
159-
if len(coordinates) == 0:
149+
all_mes_points = pointcloud.PointCloud(
150+
[measurement['mni_xyz'] for measurement in self],
151+
space='mni152',
152+
sigma_mm=LOCATION_PRECISION_MM
153+
)
154+
intersecting_points = concept.intersection(all_mes_points)
155+
measurements = [mes for mes in self if mes['mni_xyz'] in intersecting_points.coordinates]
156+
157+
if len(intersecting_points) == 0:
160158
logger.info(f"No probes found that lie within {concept}")
161159
return []
162160

163161
# Build the anatomical anchor and assignment to the query concept.
164162
# It will be attached to the returned feature, with the set of matched
165163
# MNI coordinates as anchor's location.
166164
anchor = _anchor.AnatomicalAnchor(
167-
location=pointcloud.from_points(coordinates),
165+
location=pointcloud.from_points(intersecting_points),
168166
species=self.species
169167
)
170168
explanation = f"MNI coordinates of tissue samples were filtered using {concept}"

0 commit comments

Comments
 (0)