Skip to content

Commit 75a69b5

Browse files
authored
Merge pull request #11 from int-brain-lab/develop
Develop
2 parents 87b7b64 + e4b068e commit 75a69b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+208385
-193
lines changed

.flake8

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[flake8]
2+
max-line-length = 99
3+
ignore = W504
4+
exclude =
5+
.git,
6+
__pycache__,
7+
__init__.py,
8+
data_expoloration_gui/
9+
dlc/
10+
launch_phy/
11+
histology/
12+
13+
tutorial_script.py,
14+
venv,
15+
test_imports.py,
16+
build,
17+
dist
18+
brainbox/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ dmypy.json
129129
.pyre/
130130

131131
# VSCode
132-
.vscode/
132+
.vscode/
133+
134+
scratch/

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: python
2+
python:
3+
- "3.7"
4+
# command to install dependencies
5+
install:
6+
- pip install -r requirements.txt
7+
- pip install -e .
8+
# install develop branch of ibllib
9+
- pip install git+https://github.com/int-brain-lab/ibllib.git@develop
10+
11+
# command to run tests
12+
script:
13+
- bash ./run_tests
14+
- flake8 .
15+
16+
# only build master and develop (PRs are built for all branches)
17+
branches:
18+
only:
19+
- master
20+
- develop

README.md

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,2 @@
11
# iblapps
2-
pyqt5 dependent applications for IBL sessions
3-
4-
## Ephys QC Viewer
5-
This will download the sync pulses and behaviour raw data and plot the results alongside
6-
an interactive table.
7-
The UUID is the session id.
8-
9-
### Setup
10-
Needs ibllib and ONE installed properly. Follow this guide for setup: https://readthedocs.org/projects/ibllib/downloads/pdf/latest/
11-
12-
If on the server PC, activate the environment by typing:
13-
```
14-
iblscripts
15-
```
16-
Otherwise, activate the iblenv as described in the guide above.
17-
18-
Go into the iblapps directory that you cloned:
19-
```
20-
cd /home/olivier/Documents/PYTHON/iblapps
21-
```
22-
Launch the Viewer by typing `ipython choiceworld_ephys_qc.py session_UUID` , example:
23-
```
24-
ipython choiceworld_ephys_qc.py c9fec76e-7a20-4da4-93ad-04510a89473b
25-
```
26-
27-
If you encouter the error `ModuleNotFoundError: No module named 'PyQt5'`, write in (conda) terminal (with iblenv activated):
28-
```
29-
pip install pyqt5
30-
```
31-
32-
### Plots
33-
1) Synch pulse display :
34-
- TTL synch pulses (as recorded on the ephys recording system, FPGA or PXI) for some key apparatus (e.g. frame2TTL, audio signal). TTL pulse trains are displayed in black (time on x-axis, voltage on y-axis), offset by an increment of 1 each time (e.g. audio signal is on line 3, cf legend).
35-
- event types, vertical lines (marked in different colours)
36-
37-
2) Interactive table:
38-
Each row is a trial entry.
39-
Column-wise, the table has two parts:
40-
- the left-hand rows indicate the values of timestamps at which TTL pulses are detected.
41-
- the right-hand rows indicate the result of tests (indicated by either integer values, or TRUE/FALSE output).
42-
43-
When double-clicking on any field of that table, the Synch pulse display time (x-) axis is adjusted so as to visualise the corresponding trial selected.
44-
45-
### What to look for
46-
Tests are defined here : https://github.com/int-brain-lab/ibllib/blob/90163a40eb970cf0282b651667dd8ba341ff2044/ibllib/ephys/ephysqc.py#L419
47-
48-
You can search in this code for a specific test name (e.g. `stimOff_delay_valve` - which is a column in the GUI table) to find the corresponding explanation and implementation (e.g. `# stimOff 1 sec after valve, with 0.1 as acceptable jitter`).
49-
50-
Generally speaking, look for FALSE output. More precisely:
51-
52-
If test containin the wording `_nan` is FALSE (e.g. `goCue_times_nan`), it means the corresponding TTL pulse is not detected within the trial.
53-
54-
If test containing the wording `_before_` or `_delay_` (e.g. `stim_freeze_before_feedback`) is FALSE, it means order / delay between events is not respected.
55-
56-
Some tests check for the number of output detected, in which case the output is not TRUE/FALSE but an integer. E.g. `n_feedback` should always be = 1 given our implementation.
57-
58-
### Exit
59-
Close the GUI window containing the interactive table to exit.
60-
61-
62-
63-
2+
IBL related applications that rely on unsupported libraries such as pyqt5. See package README files for more details.

__init__.py

Whitespace-only changes.

atlaselectrophysiology/ColorBar.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from PyQt5 import QtCore, QtGui
2+
import pyqtgraph as pg
3+
import matplotlib
4+
import numpy as np
5+
6+
7+
class ColorBar(pg.GraphicsWidget):
8+
9+
def __init__(self, cmap_name, cbin=256, parent=None):
10+
pg.GraphicsWidget.__init__(self)
11+
12+
# Create colour map from matplotlib colourmap name
13+
self.cmap_name = cmap_name
14+
cmap = matplotlib.cm.get_cmap(self.cmap_name)
15+
if type(cmap) == matplotlib.colors.LinearSegmentedColormap:
16+
cbins = np.linspace(0.0, 1.0, cbin)
17+
colors = (cmap(cbins)[np.newaxis, :, :3][0]).tolist()
18+
else:
19+
colors = cmap.colors
20+
colors = [c + [1.] for c in colors]
21+
positions = np.linspace(0, 1, len(colors))
22+
self.map = pg.ColorMap(positions, colors)
23+
self.lut = self.map.getLookupTable()
24+
self.grad = self.map.getGradient()
25+
26+
def getColourMap(self):
27+
return self.lut
28+
29+
def makeColourBar(self, width, height, fig, min=0, max=1, label='', lim=False):
30+
self.cbar = HorizontalBar(width, height, self.grad)
31+
ax = fig.getAxis('top')
32+
ax.setPen('k')
33+
ax.setStyle(stopAxisAtTick=((True, True)))
34+
# labelStyle = {'font-size': '8pt'}
35+
ax.setLabel(label)
36+
ax.setHeight(30)
37+
if lim:
38+
ax.setTicks([[(0, str(np.around(min, 2))), (width, str(np.around(max, 2)))]])
39+
else:
40+
ax.setTicks([[(0, str(np.around(min, 2))), (width / 2,
41+
str(np.around(min + (max - min) / 2, 2))),
42+
(width, str(np.around(max, 2)))],
43+
[(width / 4, str(np.around(min + (max - min) / 4, 2))),
44+
(3 * width / 4, str(np.around(min + (3 * (max - min) / 4), 2)))]])
45+
fig.setXRange(0, width)
46+
fig.setYRange(0, height)
47+
48+
return self.cbar
49+
50+
51+
class HorizontalBar(pg.GraphicsWidget):
52+
def __init__(self, width, height, grad):
53+
pg.GraphicsWidget.__init__(self)
54+
self.width = width
55+
self.height = height
56+
self.grad = grad
57+
QtGui.QPainter()
58+
59+
def paint(self, p, *args):
60+
p.setPen(QtCore.Qt.NoPen)
61+
self.grad.setStart(0, self.height / 2)
62+
self.grad.setFinalStop(self.width, self.height / 2)
63+
p.setBrush(pg.QtGui.QBrush(self.grad))
64+
p.drawRect(QtCore.QRectF(0, 0, self.width, self.height))
65+
66+
67+
class VerticalBar(pg.GraphicsWidget):
68+
def __init__(self, width, height, grad):
69+
pg.GraphicsWidget.__init__(self)
70+
self.width = width
71+
self.height = height
72+
self.grad = grad
73+
QtGui.QPainter()
74+
75+
def paint(self, p, *args):
76+
p.setPen(QtCore.Qt.NoPen)
77+
self.grad.setStart(self.width / 2, self.height)
78+
self.grad.setFinalStop(self.width / 2, 0)
79+
p.setBrush(pg.QtGui.QBrush(self.grad))
80+
p.drawRect(QtCore.QRectF(0, 0, self.width, self.height))

atlaselectrophysiology/README.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Ephys Atlas GUI
2+
3+
GUI to allow user to align electrophysiology data with histology data
4+
5+
## Setup
6+
7+
Install the iblenv environment using the following instructions:
8+
https://github.com/int-brain-lab/iblenv
9+
10+
If you have previously installed the environment, an additional package that is required is SimpleITK. This can be
11+
installed in the environment using,
12+
13+
```
14+
conda activate iblenv
15+
pip install SimpleITK
16+
```
17+
18+
To launch the GUI run the following commands from a terminal
19+
```
20+
conda activate iblenv
21+
python <path to ephys_atlas_gui.py>
22+
```
23+
e.g
24+
```
25+
python int-brain-lab\iblapps\atlaselectrophysiology\ephys_atlas_gui.py
26+
```
27+
28+
## Usage
29+
### Getting Data
30+
Upon launching, the GUI automatically finds subjects that have probe tracks traced. To select a subject
31+
click on the subject drop down list (see figure below). A list of sessions for the chosen subject and
32+
previous alignments associated with each session will then be loaded in the second and third drop down menus respectively.
33+
If this is the first time an alignment is being conducted for a session the only alignment option will be 'original'. If,
34+
however, the session has been previously aligned, it is possible to initiate the GUI from the previous alignment. Once the
35+
drop down options have been chosen, click on the **Get Data** button to download the data. The gui will automatically
36+
download all data necessary
37+
38+
In the case that some data is not available on FlatIron, plots associated with this data will not be displayed and a
39+
warning message is printed in the terminal.
40+
41+
If you find that the histology image is not being found, please refer to the [histology image troubleshooting](#Histology-Image-Troubleshooting) section
42+
43+
44+
### Layout
45+
The GUI comprises four main figure areas.
46+
47+
![ephys_gui](ephys_atlas_image.png)
48+
49+
#### Figure 1 - Ephys Figure
50+
The first figure contains three panels which display electrophysiology data in the form of:
51+
52+
* Image Plots (2D representation of data in image or scatter plots)
53+
* Line Plots (1D representation of data in a line plot)
54+
* Probe Plots (2D representation of data as a heatmap overlaid on the Neuropixel 3B geometry)
55+
56+
Different types of data can be viewed in each of the panels and the available options can be seen by clicking on the **Image Plots**,
57+
**Line Plots** and **Probe Plots** menu bar. The display in each panel can be changed by clicking through the options in each menu bar or
58+
by using the shortcut Alt+ 1, Alt + 2, Alt + 3, for the image, line and probe plots respectively.
59+
60+
The order of the panels can also be rearranged by changing the view (under the **Display Options** menu bar) or by
61+
pressing, Shift + 1, Shift + 2 or Shift + 3.
62+
63+
#### Figure 2 - Histology Figure
64+
The second figure displays the brain regions through which the traced probe track passes (the trajectory). It is split into
65+
three panels, which display, from left to right,
66+
* Scaled brain regions
67+
* Scale factor applied to brain regions - represented as heatmap
68+
* Original (unscaled) brain regions - for reference
69+
70+
The black dotted lines on the left and right panels indicated the location along the trajectory of the first and last
71+
electrode. The labels overlaid on the brain regions can be toggled on and off using Shift + L
72+
73+
The actual scale factor value is displayed in the title of the colorbar (top of figure) when hovering over a region on
74+
the scale factor plot.
75+
76+
#### Figure 3 - Slice Figure
77+
The third figure displays a tilted slice through the brain. The tilt of the slice displayed is determined by the line
78+
of best fit through the traced points. Overlaid on the slice is a black line linking the traced points (the trajectory)
79+
and the location of the electrodes on the Neuropixel probe along this trajectory (red points). When reference lines are added
80+
to the Ephys and Histology figures, they are displayed as black dotted lines perpendicular to the local trajectory.
81+
The collection of lines and points overlaid on the slice figure can be toggled on and off using Shift + C.
82+
83+
There are three options for the tilted slice displayed (changed using Alt+ 4):
84+
* Slice taken from red channel of histology image
85+
* Slice taken from allen brain atlas
86+
* Slice taken from allen brain atlas annotation
87+
88+
The intensity of the slice images can be changed using the intensity scale bar located on the right hand side of the figure.
89+
90+
#### Figure 4 - Fit Figure
91+
The fourth figure provides a 2D representation of the scaling applied along the depth of the trajectory. Coordinates
92+
are relative to the location of the most ventral electrode. Three lines are displayed in this figure
93+
* Reference line (black dotted line) - reference for when no fit/scaling is applied
94+
* Fit line (blue solid line) - piecewise fit along depth of trajectory
95+
* Linear fit line (red dotted line) - linear fit along depth of trajectory (only present when two or more reference lines
96+
are implemented)
97+
98+
### Alignment
99+
Reference line pairs are used to align features on the Ephys and Histology figures. A pair can be added to the GUI by
100+
double clicking at any point on either the Ephys or Histology figure and the line on each figure moves independently.
101+
Once the two lines of a reference pair line have been moved to the feature/landmark that needs to be aligned, the fit
102+
can be applied by pressing the **Fit** button or by pressing Enter key.
103+
104+
Different types of fit are applied depending on the number of reference lines implemented.
105+
106+
#### One reference line
107+
A fit applied with a single reference line pair will result in an offset.
108+
109+
Two other methods (independent of reference lines) for applying an offset are available
110+
* Drag the black dotted lines (indicate location of first and last electrode) on the left panel of the histology figure
111+
to the desired position and press the **Offset** button or the 'o' key
112+
* Pressing Shift + Up arrow or Shift + Down arrow will apply a +- 50 um offset
113+
114+
#### Two reference lines
115+
A fit applied with two reference line pairs will result in an offset and scaling of regions between the two reference line pairs.
116+
The remaining regions, located beyond the reference lines, will be offset, however, will remain unscaled.
117+
118+
#### Three or more reference lines
119+
A fit applied with three or more reference line pairs will result in an offset and piecewise scaling of regions between each
120+
of the reference lines. By default the remaining regions will be scaled according to a linear fit through all the reference lines
121+
(red dotted line in fit figure). If instead, one wants to keep the regions beyond the reference lines unscaled, the default can be
122+
turned off by un-ticking the linear fit checkbox located in the fit figure.
123+
124+
When a fit is applied the location of the electrodes on the slice figure will update.
125+
126+
A reference line can be deleted by hovering over the line and pressing Shift + D. N.B. Any fits anchored on a reference line will
127+
be lost once the line is deleted. The reference lines can be hidden/ redisplayed using Shift + H.
128+
129+
### Uploading data
130+
Once the alignment is complete, the new locations of the electrode locations can be uploaded to Alyx by pressing the **Upload**
131+
button or Shift + U.
132+
133+
### Additional Features
134+
#### Session Notes
135+
If any notes associated with a session have been uploaded to Alyx, these can be displayed as a popup by clicking on
136+
**Session Information** on the menu bar and selecting **Session Notes**
137+
138+
#### Region Information
139+
Information about brain regions that has been entered in Alyx can be displayed by hovering over a brain region in the
140+
histology figure and pressing Shift + I. This will bring up a popup with the brain regions organised according to the allen
141+
atlas structure tree.
142+
143+
#### Cluster Popup
144+
When displaying the cluster plots on the 2D image plats, the cluster autocorrelogram and template waveform can be viewed in
145+
a popup by clicking on a scatter point. It is possible to display many popups for different clusters. To collectively
146+
minimise/ show the cluster popup windows press Alt + M (make sure your cursor is located on the main gui window, not a popup window).
147+
To close the cluster popup windows press Alt + X
148+
149+
#### Filter Units
150+
By default, the plots in the Ephys figure are shown for all units that have been classified as 'Good' and 'Mua' following
151+
spike sorting. The **Filter Unit** option in the menu bar can be used to restrict the type of unit displayed.
152+
153+
#### Previous Fits
154+
A total of 10 previous fits are stored in memory. One can move to previous fits by using the **Previous** and **Next** buttons or by using
155+
the Left and Right arrow keys.
156+
157+
#### Reset
158+
To reset the GUI to the original state, i.e. no alignments, press the **Reset** button or Shift + R.
159+
160+
#### Rescaling
161+
It is possible to zoom in on some plots in the Ephys and Histology figures. To reset the axis press Shift + A.
162+
163+
## Histology Image Troubleshooting
164+
The naming convention used for subjects in the histology folder on FlatIron (http://ibl.flatironinstitute.org/histology/)
165+
is not always consistent with the subject names stored in Alyx. While the code attempts to account for differences in
166+
capitalisation or underscores, sometimes the naming in the histology is just too quirky. In these cases, it will be
167+
necessary to manually download the histology image required for the GUI.
168+
169+
The image file required is located in the *downsampledStacks_25/sample2ARA/* folder of the subject on FlatIron, and has
170+
the extension **.....RD.tif** file. This file should be downloaded and placed in a folder called *histology* in the
171+
associated subject folder on your local computer
172+
173+
e.g. Download **STD_dsIBL_WITTEN_13_200109_121739_25_25_RD.tif** from
174+
http://ibl.flatironinstitute.org/histology/wittenlab/IBL_Witten_13/downsampledStacks_25/sample2ARA/
175+
176+
and place this file in
177+
178+
C:\Users\Mayo\Downloads\FlatIron\wittenlab\Subjects\ibl_witten_13\histology

atlaselectrophysiology/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)