If you are reading this notebook online, please refer to this quick-start guide for instructions on how to install the required software and run the notebook on your machine.
If it's the first time you are using a Jupyter notebook, please click on Help -> User Interface Tour for a quick tour of the interface.
In this notebook there are "text cells", such as this paragraph, and "code cells", containing the code to be executed. To execute a code cell, select it and press SHIFT+ENTER. To edit a code cell it must be selected and with a green frame around it.
Your can run this notebook using example data files available on figshare. If you use these example files, please unzip them and put them in a folder named "data" (lower case) inside the folder containing this notebook.
Alternatively, you can use your own HT3 files. In this case, you need to paste
the full path of your file in the following cell, instead of the path between
filename = r'data/Pre.ht3'
The next cell will check if the
filename location is correct:
import os try: with open(filename): pass print('Data file found, you can proceed.') except IOError: print('ATTENTION: Data file not found, please check the filename.\n' ' (current value "%s")' % filename)
In case of file not found, please double check that have you put the example
data files in the "data" folder, or that the path you have pasted in
is correct. Please re-execute the last two cells until the file is found.
Here, we specify the additional metadata that will be stored in the Photon-HDF5 file. If you are using the example file you don't need to edit any of these. If are using your own file, please modify these description accordingly.
author = 'Eitan Lerner' author_affiliation = 'UCLA' creator = 'Antonino Ingargiola' creator_affiliation = 'UCLA'
description = 'A demostrative smFRET-nsALEX measurement.' sample_name = 'Doubly-labeled ssDNA partially hybridized to a complementary strand.' dye_names = 'ATTO488, ATTO647N' buffer_name = 'Tris20 mM Ph 7.8'
Please edit the previous cells and execute them (SHIFT+ENTER) to make sure there are no errors. Then proceed to the next section.
%matplotlib inline import matplotlib.pyplot as plt import numpy as np import phconvert as phc print('phconvert version: ' + phc.__version__)
Next, we can load the input file and assign the measurement parameters (measurement_specs), necessary to create a complete Photon-HDF5 file.
If using your own file, please review all the parameters in the next cell.
d, meta = phc.loader.nsalex_ht3(filename, donor = 0, acceptor = 1, alex_period_donor = (150, 1500), alex_period_acceptor = (1540, 3050), excitation_wavelengths = (470e-9, 635e-9), detection_wavelengths = (525e-9, 690e-9), time_reversed = False)
The next cell plots a
nanotimes histogram for the donor and acceptor channel separately.
The shaded areas marks the donor (green) and acceptor (red) excitation periods.
If the histogram looks wrong in some aspects (no photons, wrong detectors assignment, wrong period selection) please go back to the previous cell and tweak the relevant parameters until the histogram looks correct.
fig, ax = plt.subplots(figsize=(10, 4)) phc.plotter.alternation_hist(d, ax=ax)
You may also find useful to see how many different detectors are present and their number of photons. This information is shown in the next cell.
detectors = d['photon_data']['detectors'] print("Detector Counts") print("-------- --------") for det, count in zip(*np.unique(detectors, return_counts=True)): print("%8d %8d" % (det, count))
Once you finished editing the the previous sections you can proceed with the actual conversion. It is suggested to execute the notebook in one step by clicking on the menu Cells -> Run All.
After that, you should find a new
.hdf5 file in the same folder of the input
file. You can check it's content by using HDFView.
The cells below contain the code to convert the input file to Photon-HDF5.
d['description'] = description d['sample'] = dict( sample_name=sample_name, dye_names=dye_names, buffer_name=buffer_name, num_dyes = len(dye_names.split(','))) d['identity'] = dict( author=author, author_affiliation=author_affiliation, creator=creator, creator_affiliation=creator_affiliation)
Before writing to disk, we assure the file structure follows the Photon-HDF5 format:
phc.hdf5.save_photon_hdf5(d, close=False, overwrite=True)
Here we save a custom (user) group where we put all the metadata found in the input .HT3 file. The important metadata from the .HT3 file is already saved in the standard Photon-HDF5 fields.
Here we save the full original metadata in order to make sure that no information is lost during the conversion.
h5file = d['_data_file'] h5file.create_group('/', 'user') pq_group = h5file.create_group('/user', 'picoquant') for key in meta: if np.size(meta[key]) > 0: h5file.create_table(pq_group, key, obj=meta[key])
Finally we print the file content to see what's inside the newly-created Photon-HDF5. Here we print the content of the roor node:
And here we retrieve some information from the user group:
from pprint import pprint
filename = d['_data_file'].filename
h5data = phc.hdf5.load_photon_hdf5(filename)
If the next cell output shows "OK" then the execution is terminated.