OpenSMFS / FRETBursts

Burst analysis software for single and multi-spot single-molecule FRET (smFRET) data.
https://opensmfs.github.io/FRETBursts/
GNU General Public License v2.0
12 stars 9 forks source link

Reading Photon-HDF5 files of 'generic' type including polarization #18

Closed tritemio closed 5 years ago

tritemio commented 5 years ago

Issue migrated from https://github.com/tritemio/FRETBursts/issues/69. Originally reported by @AndersBarth

Hi,

I have data from a PIE-MFD setup (i.e. nsALEX with polarization) that I am trying to read from a Photon-HDF5 file into FRETbursts (file is attached). The file specifies the number of polarizations (/setup/num_polarization_ch = 2) and the polarization assignment (/photon_data/measurement_specs/detectors_specs/polarization_ch1-2), yet I get the following error upon trying to read the file:

Invalid_PhotonHDF5: The field/setup/num_polarization_chindicates more than one polarization. However, somedetectors_specs/polarization_ch*fields are missing.

The file was generated through phforge 0.1.1 using phconvert 0.8.2.

Since all the required fields are present when inspecting the file in HDFView, I'm confused why the error occurs. Thanks for the help!

Best, Anders

Link to File H20.h5

tritemio commented 5 years ago

Issue migrated from https://github.com/tritemio/FRETBursts/issues/69. Originally reported by @AndersBarth

Small update:

I looked into the code and it seems that the logic check in loader.py on line 134:

if any('polarization_ch%i' not in det_specs for i in (1, 2)):

returns True when it shouldn't.

It works if changed to:

if not (('polarization_ch1' in det_specs) and ('polarization_ch2' in det_specs)):

but there is probably a more pythonic way of solving it.

tritemio commented 5 years ago

@AndersBarth, thanks for the report and the fix. The line should have been:

if any('polarization_ch%d' %i not in det_specs for i in (1, 2)):

It would be clearer in python 3.6 (which we cannot use for backward compatibility for now):

if any(f'polarization_ch{i}' not in det_specs for i in (1, 2)):

which is like saying: if any of the polarization fields is not in det_specs then ...

That said, your version is simpler and more explicit so more pythonic. Let me know if you want to send a PR, otherwise I'll fix it by my self.

Is this affecting the workshop? I could push a new release if needed.

AndersBarth commented 5 years ago

Hey Antonino,

thanks for the quick reply! Feel free to do the PR yourself. ;)

It is not affecting the workshop, although we would like FRETbursts to be represented. Since we had generated simulated test datasets, I was just making sure that it could be read by FRETbursts. A new release is not necessary at the moment, since with this fix we can at least show a brief workflow.

One question: If feeding a tuple to the channel selection of donor and acceptor prior to burst search, i.e. det_donor_accept=((0,2),(1,3)), I assume that the routing will combine the two channels (e.g. to break down a polarization resolved measurement into the simpler scheme).

tritemio commented 5 years ago

The det_donor_accept is passed to Data.add before applying the alternation. But if the Photon-HDF5 is well formatted you should not need to pass any parameter, just load then apply the alternation periods.

If I recall correctly, the polarization data is not used by default. Photons are split in Donor and Acceptor (2 detectors each) and then you can do a burst search on any combination of of D-A channels and alternation periods. You have a boolean masks Data.P_em and Data.S_em (well a list with 1 bool array in it, similar to Data.A_em and Data.D_em for donor and acceptor emission) that tell the polarization of each photon, so you can separate photons by polarization after burst search. There is not much built-in support for polarization-related operations, but at least the data is loaded and user-accessible.

tritemio commented 5 years ago

Closed by PR #19.