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

Export "Inter-photon delay times" graph to .csv file #17

Open tritemio opened 5 years ago

tritemio commented 5 years ago

Migrated from https://github.com/tritemio/FRETBursts/issues/68

@ncodina wrote:

Hi, I want to export the data of the "Inter-photon delay times" to a .csv file. How would I do it?

figure_1

tritemio commented 5 years ago

Hi @ncodina, there is no explicit support for exporting that graph. You can either compute the histogram by yourself using numpy or you can export the coordinates of the datapoints from the matplotlib figure.

In the first case, you need to get the photon streams with Data.get_ph_times(), use np.diff to get the interphoton times and finally call np.histogram to compute the histogram. That's how hist_interphoton_single is implemented.

I the second case, you iterate through the axis children, selecting using isinstance the one representing the data (if I recall it should be Lines2D). Then, each object representing a curve has a get_data method to get x, y coordinates.

ncodina commented 5 years ago

Hi @tritemio,

Thanks very much for the information. For now, I exported them by introducing this line of code in the hist_interphoton_single function, after defining counts.

line: counts.tofile("/Path/To/counts_{}.csv".format(ph_sel), sep='\n')

introduced here: https://github.com/OpenSMFS/FRETBursts/blob/790526bd0ceaef1955e29124fe03d7ed9c7ce335/fretbursts/burst_plot.py#L1470

tritemio commented 5 years ago

Good hack.

In the future, we can think about a common API to save plot data . For example all the plot functions could accept a export=True/False, to save to disk. Better, they could accept a single argument export_fname that is None by default and saves to disk only when a file name is specified. The format can be a standard CSV with column names so that files can be directly loaded in a pandas.DataFrame. Each plot function would have its own custom logic to save the data (or raise NotImplemented), but the user API and the way to re-load the data would be the same for all plots.

If you are interested to tackle this issue, I would welcome a Pull Request.