whitews/FlowKit

Shared matrices are not loaded in flowkit

Closed this issue · 3 comments

Describe the bug

Hi Scott!
I use flowkit to load compensation matrix from wsp file.
The way I've done it previously is a bit dumb, but was working: traversing the wsp and looking for the first compensation matrix, like this:

import flowkit as fk
flowkit.parse_wsp(wsp_file)

def get_first_compensations_matrix(prefix, x):
    for k, v in x.items():
        p = prefix + [k]
        if k == "compensation":
            if isinstance(v, dict) and 'matrix' in v and isinstance(v['matrix'], flowkit.Matrix):
                return v['matrix'].as_dataframe()
            if isinstance(v, flowkit.Matrix):
                # worked in previous versions
                return v.as_dataframe()
        if isinstance(v, dict):
            output = get_first_compensations_matrix(p, v)
            if output is not None:
                return output

This however did not work for a wsp file I received recently.
It seems that in more recent flowjo versions they don't duplicate matrix, e.g. this one in Workspace/Matrices:

<transforms:spilloverMatrix spectral="0" prefix="Comp-" name="Acquisition-defined" editable="0" color="#c0c0c0" version="FlowJo-10.8.2" status="FINALIZED" transforms:id="b7a855ff-b726-4d50-a5b4-e19fbdbe33bb" suffix=">....</transforms:spilloverMatrix>

Note there is transforms:id that connects these two entities

<Sample>
<DataSet uri="file:/Users/<longpathhere>.fcs" sampleID="1"/>
<transforms:spilloverMatrix spectral="0" prefix="Comp-" name="Acquisition-defined" editable="0" color="#c0c0c0" version="FlowJo-10.8.2" status="FINALIZED" transforms:id="b7a855ff-b726-4d50-a5b4-e19fbdbe33bb" suffix=""></transforms:spilloverMatrix>
<Transformations></Transformations>
<Keywords></Keywords>
<SampleNode name="D10.fcs" annotation="" owningGroup="" expanded="1" sortPriority="10" count="355819" sampleID="1"></SampleNode>
</Sample>

When I load wsp with flowkit compensations are not reflected:

{'groups': {'All Samples': {'gates': [],
   'samples': ['D10.fcs', 'D11.fcs', 'D12.fcs']}},
 'samples': {}}

Please point me in the right direction if there is a better way to get a compensation matrix.

Desktop (please complete the following information):

  • OS: mac os 13.3
  • Python version: Python 3.10.12
  • FlowKit version: 1.0.1

Hi Alex,

Before digging in too far, does the utils function extract_wsp_sample_data work to retrieve the sample transforms?

Thanks!
Scott

does the utils function extract_wsp_sample_data work to retrieve the sample transforms?

Yes, it does! Do you think this is a better way?

It may be. That function was added to retrieve all sample info regardless of whether it is used in a gate. Without revisiting the code my recollection is that parse_wsp may not return all sample related info if it isn't used anywhere.