Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed May 8, 2023
2 parents 46aa9c5 + eee53c5 commit c51ddf8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.10"

python:
version: "3"
install:
- requirements: docs/requirements.txt
- method: pip
Expand Down
4 changes: 2 additions & 2 deletions flowkit/_models/gating_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def _compensate_sample(self, dim_comp_refs, sample):
if comp_ref == 'FCS':
meta = sample.get_metadata()

if 'spill' not in meta or 'spillover' not in meta:
if 'spill' not in meta and 'spillover' not in meta:
# GML 2.0 spec states if 'FCS' is specified but no spill is present, treat as uncompensated
events = sample.get_events(source='raw')
return events.copy()
Expand All @@ -601,7 +601,7 @@ def _compensate_sample(self, dim_comp_refs, sample):

detectors = [sample.pnn_labels[i] for i in sample.fluoro_indices]
fluorochromes = [sample.pns_labels[i] for i in sample.fluoro_indices]
matrix = Matrix('fcs', spill, detectors, fluorochromes, null_channels=sample.null_channels)
matrix = Matrix('tmp_spill', spill, detectors, fluorochromes, null_channels=sample.null_channels)
else:
# lookup specified comp-ref in gating strategy
matrix = self.comp_matrices[comp_ref]
Expand Down
5 changes: 3 additions & 2 deletions flowkit/_models/transforms/_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def __init__(
fluorochromes=None,
null_channels=None
):
if matrix_id == 'uncompensated' or matrix_id == 'fcs':
# Technically, the GML 2.0 spec states 'FCS' (note uppercase) is reserved, but we'll cover that case-insensitive
if matrix_id == 'uncompensated' or matrix_id.lower() == 'fcs':
raise ValueError(
"Matrix IDs 'uncompensated' and 'fcs' are reserved compensation references " +
"Matrix IDs 'uncompensated' and 'FCS' are reserved compensation references " +
"used in Dimension instances to specify that channel data should either be " +
"uncompensated or compensated using the spill value from a Sample's metadata"
)
Expand Down
25 changes: 25 additions & 0 deletions flowkit/tests/gating_strategy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
import numpy as np
import flowkit as fk
from .session_tests import test_samples_8c_full_set_dict


data1_fcs_path = 'data/gate_ref/data1.fcs'
Expand Down Expand Up @@ -46,6 +47,9 @@
)
comp_matrix_01 = fk.Matrix('MySpill', spill01_data, spill01_detectors, spill01_fluoros)

sample_id_with_spill = '101_DEN084Y5_15_E01_008_clean.fcs'
sample_with_spill = test_samples_8c_full_set_dict[sample_id_with_spill]


class GatingStrategyTestCase(unittest.TestCase):
def test_add_gate_non_gate_class(self):
Expand Down Expand Up @@ -92,6 +96,27 @@ def test_add_duplicate_matrix_id(self):

self.assertRaises(KeyError, gs.add_comp_matrix, comp_matrix_01)

def test_fcs_defined_spill(self):
gs = fk.GatingStrategy()

asinh_xform = fk.transforms.AsinhTransform('asinh', param_t=262144, param_m=4.0, param_a=0.0)
gs.add_transform(asinh_xform)

dim_cd3 = fk.Dimension(
'CD3 APC-H7 FLR-A',
range_max=-0.4,
transformation_ref='asinh',
compensation_ref='FCS'
)

cd3_rect_gate = fk.gates.RectangleGate('cd3_low', dimensions=[dim_cd3])
gs.add_gate(cd3_rect_gate, gate_path=('root',))

gating_result = gs.gate_sample(sample_with_spill)
cd3_low_count = gating_result.get_gate_count('cd3_low')

self.assertEqual(cd3_low_count, 71)

def test_get_max_depth(self):
gml_path = 'data/gate_ref/gml/gml_all_gates.xml'
gs = fk.parse_gating_xml(gml_path)
Expand Down

0 comments on commit c51ddf8

Please sign in to comment.