{
"metadata": {
"name": "",
"signature": "sha256:aa63b645da5646a96dc63e1d9500719692692fb4300d209e655aa108affbbcb8"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#FRETBursts - HOWTO Load a file\n",
"\n",
"*This notebook is part of a [tutorial series](https://github.com/tritemio/FRETBursts_notebooks) for the [FRETBursts](http://tritemio.github.io/FRETBursts/) burst analysis software.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> In this notebook we present two ways to load a file in [FRETBursts](https://github.com/tritemio/FRETBursts/).\n",
"> It all boils down to putting the full file name in a variable. We show one text based and one GUI based example.\n",
"> \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Loading the software"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We start loading the **`FRETBursts`** software:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from fretbursts import *"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" - Optimized (cython) burst search loaded.\n",
" - Optimized (cython) photon counting loaded.\n",
"-------------------------------------------------------------\n",
" You are running FRETBursts (version 0.4rc4-20-g4ea8dd4).\n",
"\n",
" If you use this software in a publication, please cite it as:\n",
"\n",
" FRETBursts - An opensource single-molecule FRET burst analysis toolkit.\n",
" A. Ingargiola 2014. https://github.com/tritemio/FRETBursts\n",
"\n",
"-------------------------------------------------------------\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# This enables the Qt GUI (for the open-file dialog)\n",
"%gui qt"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# This enables inline plots\n",
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The last line tells us which FRETBursts revision is currently in use. This information can be used for long-term reproducibility, a crucial problem in science. Moreover, knowing the revision allows to easily track software regressions."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can select a data-file by pasting its name in a variable or by using a conventional GUI dialog. In either cases we'll end up with the a file-name stored in the variable `full_fname`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Downloading the sample data file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The full list of smFRET measurements used in the [FRETBursts tutorials](https://github.com/tritemio/FRETBursts_notebooks) \n",
"can be found on [Figshare](http://dx.doi.org/10.6084/m9.figshare.1019906).\n",
"\n",
"Here we download the us-ALEX data-file and put it in a folder named `data`, inside the notebook folder. \n",
"For this purpose we use the `download_file` function provided by FRETBursts:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"url = 'http://files.figshare.com/1839121/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"download_file(url, save_dir='./data')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"URL: http://files.figshare.com/1839121/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5\n",
"File: 0023uLRpitc_NTP_20dT_0.5GndCl.hdf5\n",
" \n",
"File already on disk: C:\\Data\\Antonio\\software\\src\\fretbursts_notebooks\\notebooks\\data/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5 \n",
"Delete it to re-download.\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Selecting a data file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Option 1: Use an \"Open File\" dialog"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can select a data file with an \"Open File\" windows like this:\n",
"\n",
"\n",
"\n",
"To launch the dialog run this (note: it may pop-up in the foreground):"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"full_fname = gui_fname('./')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"C:/Data/Antonio/software/src/fretbursts_notebooks/notebooks/data/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now `full_fname` contains the path of the file you just selected. Run again the previous cell to select a new file."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Option 2: Paste the file-name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, we can directly define the file name to be loaded:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# That's an example dataset, download it from (link here)\n",
"file_name = \"0023uLRpitc_NTP_20dT_0.5GndCl.hdf5\""
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Here the folder is the subfolder \"data\" of current notebook folder\n",
"folder_name = './data/'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and concatenate the data folder with the file name:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"full_fname = folder_name + file_name\n",
"full_fname"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"'./data/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5'"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's check that the file exists:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import os\n",
"if os.path.isfile(full_fname):\n",
" print \"Perfect, I found the file!\"\n",
"else:\n",
" print \"Sorry, I can't find the file:\\n\", full_fname"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Perfect, I found the file!\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The \"`--nogui`\" flag\n",
"\n",
"When using the GUI dialog the ipython notebook have to be properly initialialized to handle both an external QT GUI and inline plots. This is automatically done by the `load_fretbursts` script by default. One current drawback is that when this initialization is performed, the notebook can't be run in batch (*Cell* -> *Run All*) anymore. If you don't use the GUI Open-File dialog and want to run the notebook in one single step you can call `load_fretbursts` with the `--nogui` flag. Whit this flag you can still use `%matplotlib qt` to have interctive plots in an external QT window."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load the selected file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once we have the filename in a variable the data can be loaded with:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"d = loader.hdf5(full_fname)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook style"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.core.display import HTML\n",
"HTML(open(\"./styles/custom2.css\", \"r\").read())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
""
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
}
],
"metadata": {}
}
]
}