Skip to content

Commit

Permalink
Merge pull request #4 from nno/nf/user_duration
Browse files Browse the repository at this point in the history
Nf/user duration
  • Loading branch information
nno authored Sep 21, 2023
2 parents 6b318a8 + caa9cfc commit 638518b
Show file tree
Hide file tree
Showing 17 changed files with 878 additions and 771 deletions.
1 change: 1 addition & 0 deletions doc/source/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
About the authors
=================


+ Nikolaas N. Oosterhof (nikolaas `dot` oosterhof `at` unitn `dot` it) is a postdoctoral fellow at the Center for Mind/Brain Sciences, Trento University, Italy.
+ Chris A. Oosterhof (chris `dot` oosterhof `at` theroyal `dot` ca) is a PhD student at the Institute of Mental Health Research, University of Ottowa, Canada.

Expand Down
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = '0.40'
version = '1,0'
# The full version, including alpha/beta/rc tags.
release = '0.40'
release = '1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions doc/source/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Burstidator analysis
+ usually this involves double-clicking the ``burstiDAtor.jar`` file.

* Optionally: to switch between burst detection for DA (dopamine), 5HT (serotonin), RTN (reticular thalamic nucleus) or GLU (glutamate) neuron burst detection, click ``type: DA`` / ``type: 5HT`` / ``type: RTN`` / ``type: GLU``.
* Optionally: to set your own burst detection parameters, select ``User type`` and set three parameters: maximum inter-spike interval to start a burst, maximum inter-spike. and mininum number of spikes to form a burst.
* Click *Wizard*.
* Browse to the folder containing the ``*.txt`` output files from Spike2 (see above).
* Click *open*. BurstiDAtor will display the number of ``*.txt`` files in that folder.
Expand Down
118 changes: 62 additions & 56 deletions java/burstiDAtor/AutoCorr.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,82 @@

public class AutoCorr extends Histogram {
public AutoCorr(Spikes spikes) {
super();
int n_spikes = spikes.length();

Settings settings = Settings.getInstance();
SpikeDelta min_isi = SpikeDelta.fromString(settings.getS("autocorr_min"));
SpikeDelta max_isi = SpikeDelta.fromString(settings.getS("autocorr_max"));
SpikeDelta binwidth = SpikeDelta.fromString(settings.getS("autocorr_binwidth"));

int n_bins = max_isi.subtract(min_isi).divideCeil(binwidth);

for (int i = 0; i <= n_bins; i++) {
bins.add((double) i);
if (i<n_bins) {
counts.add(0);
}
}

if (n_spikes<2) {
return;
}

for (int i = 0; i < n_spikes; i++) {
for (int j = i + 1; j < spikes.length(); j++) {
SpikeDelta delta = new SpikeDelta(spikes.get(i), spikes.get(j));
int bin = getBin(min_isi, binwidth, delta);
boolean too_small = bin < 0;
boolean too_large = bin >= n_bins;
boolean keep = !(too_small || too_large);
if (keep) {
counts.set(bin, 1 + counts.get(bin));
}
if (too_large) {
break;
}
}
}
super();
int n_spikes = spikes.length();

Settings settings = Settings.getInstance();
SpikeDelta min_isi = SpikeDelta
.fromString(settings.getS("autocorr_min"));
SpikeDelta max_isi = SpikeDelta
.fromString(settings.getS("autocorr_max"));
SpikeDelta binwidth = SpikeDelta
.fromString(settings.getS("autocorr_binwidth"));

int n_bins = max_isi.subtract(min_isi).divideCeil(binwidth);

for (int i = 0; i <= n_bins; i++) {
bins.add((double) i);
if (i < n_bins) {
counts.add(0);
}
}

if (n_spikes < 2) {
return;
}

for (int i = 0; i < n_spikes; i++) {
for (int j = i + 1; j < spikes.length(); j++) {
SpikeDelta delta = new SpikeDelta(spikes.get(i),
spikes.get(j));
int bin = getBin(min_isi, binwidth, delta);
boolean too_small = bin < 0;
boolean too_large = bin >= n_bins;
boolean keep = !(too_small || too_large);
if (keep) {
counts.set(bin, 1 + counts.get(bin));
}
if (too_large) {
break;
}
}
}
}

public static int getBin(SpikeDelta t_onset, SpikeDelta binwidth, SpikeDelta t) {
int bin = t.subtract(t_onset).divideFloor(binwidth);
return bin;
public static int getBin(SpikeDelta t_onset, SpikeDelta binwidth,
SpikeDelta t) {
int bin = t.subtract(t_onset).divideFloor(binwidth);
return bin;
}

public BufferedImage getPlot() {
return super.getPlot("time (ms)");
return super.getPlot("time (ms)");
}


public static void main(String... unused) throws Exception {
String d = "/Users/nick/tmp/";
String d = "/Users/nick/tmp/";

String[] fns = { "neuron 1 651542.txt", "neuron 2 653286.txt", "Neuron 3 653284.txt" };
String[] fns = { "neuron 1 651542.txt", "neuron 2 653286.txt",
"Neuron 3 653284.txt" };

for (int i = 0; i < fns.length; i++) {
for (int i = 0; i < fns.length; i++) {

String fn = "/Users/nick/tmp/" + fns[i];
File f = new File(fn);
Spikes spikes = new Spikes(f);
AutoCorr ac = new AutoCorr(spikes);
String fn = "/Users/nick/tmp/" + fns[i];
File f = new File(fn);
Spikes spikes = new Spikes(f);
AutoCorr ac = new AutoCorr(spikes);

BufferedImage img = ac.getPlot();
BufferedImage img = ac.getPlot();

try {
// Save as PNG
File file = new File("/Users/nick/tmp/neuron" + (i + 1) + ".png");
ImageIO.write(img, "png", file);
try {
// Save as PNG
File file = new File(
"/Users/nick/tmp/neuron" + (i + 1) + ".png");
ImageIO.write(img, "png", file);

} catch (IOException e) {
}
} catch (IOException e) {
}

}
}
}
}
26 changes: 12 additions & 14 deletions java/burstiDAtor/Burst.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public Burst() {
/**
* add a spike to the burst
*
* @param onset
* time of the spike
* @param onset time of the spike
*/
public void add(double onset) {
onsets.add(onset);
Expand All @@ -31,16 +30,14 @@ public void add(double onset) {
/**
* Compute statistics for this burst
*
* @param fs
* Optional list of property keys to return. If null or empty
* then all keys are returned.
* @return Props instance containing properties of this burst, with a subset
* of the following keys (or all if fs is null or empty): "nSp"
* (number of spikes), "firstSp" (onset of first spike), "lastSp"
* (onset of last spike), "center" (average of first and last
* spike), "BuDur" (duration of the burst), "SpFreq" (spike
* frequency in the burst), and "interSp" (interspike interval in
* the burst).
* @param fs Optional list of property keys to return. If null or empty then all
* keys are returned.
* @return Props instance containing properties of this burst, with a subset of
* the following keys (or all if fs is null or empty): "nSp" (number of
* spikes), "firstSp" (onset of first spike), "lastSp" (onset of last
* spike), "center" (average of first and last spike), "BuDur" (duration
* of the burst), "SpFreq" (spike frequency in the burst), and "interSp"
* (interspike interval in the burst).
*/
public Props getStats(String... fs) {
Props s = new Props();
Expand All @@ -61,8 +58,9 @@ public Props getStats(String... fs) {
s.put("SpFreq", freq);
s.put("interSp", dur / (double) (n - 1));

Props r = (fs == null || fs.length == 0 || (fs.length == 1 && fs[0] == null)) ? s
: s.filter(fs);
Props r = (fs == null || fs.length == 0
|| (fs.length == 1 && fs[0] == null)) ? s
: s.filter(fs);
return r;
}

Expand Down
Loading

0 comments on commit 638518b

Please sign in to comment.