Browse Source

analysis of persistent activity

Paul Pfeiffer 1 year ago
parent
commit
828f9fd07c
2 changed files with 80 additions and 6 deletions
  1. 3 6
      makefile
  2. 77 0
      scripts/analyse_persistent_activity.py

+ 3 - 6
makefile

@@ -1,4 +1,4 @@
-all: prepare_folder_structure extract_stimulations assign_protocols filter analyse_firing_rates
+all: prepare_folder_structure extract_stimulations assign_protocols filter analyse_firing_rates analyse_persistent_activity
 
 prepare_folder_structure:
 	python scripts/check_folder_structure.py
@@ -16,15 +16,12 @@ analyse_firing_rates:
 	python scripts/analyse_firing_rates.py
 
 analyse_persistent_activity:
-	python analyse_persistent_activity.py
-
-plot_firing_rates:
-	python plot_traces.py
+	python scripts/analyse_persistent_activity.py
 
 plot_traces:
 	python plot_traces.py
 
-report: 
+report:
 	python generate_report.py
 
 clean:

+ 77 - 0
scripts/analyse_persistent_activity.py

@@ -0,0 +1,77 @@
+import numpy
+import pandas as pd
+
+from tools.helper import get_filters
+from tools.definitions import OUTPUT_FOLDER, HELPER_TABLE_FOLDER, STIMULATION_METADATA_FILTERED
+
+print "# Analyse persistent activity"
+print "Test whether in the UP protocols frequency was increased/in DOWN protocols frequency was decreased"
+
+pulse_mean_string = "p_{:d}_ISI_mean"
+after_pulse_mean_string = "ap_{:d}_ISI_mean"
+
+path_to_filtered_stimulus_file = OUTPUT_FOLDER+HELPER_TABLE_FOLDER+STIMULATION_METADATA_FILTERED
+
+stimulations = pd.read_csv(path_to_filtered_stimulus_file, index_col="stimulation_id")
+stimulations["was_successful"] = numpy.nan
+
+# get protocols
+type_number_combinations = stimulations[["protocol_type", "pulse_number"]].drop_duplicates().values
+
+
+def analyse_up_protocols(stimulation):
+    after_pulse_firing_columns = [after_pulse_mean_string.format(number) for number in
+                                  range(1, stimulation["pulse_number"] + 1)]
+    after_pulse_firing = stimulation[after_pulse_firing_columns].values.astype(numpy.float)
+    after_pulse_firing = map(lambda firing: numpy.Infinity if numpy.isnan(firing) else firing, after_pulse_firing)
+
+    isi_decreases = numpy.greater_equal(after_pulse_firing[:-1], after_pulse_firing[1:])
+
+    isi_is_decreasing = numpy.all(isi_decreases)
+    isi_is_finite_after_the_last_pulse = after_pulse_firing[-1] <= 10
+    return isi_is_decreasing and isi_is_finite_after_the_last_pulse
+
+
+def analyse_down_protocols(stimulation):
+    during_pulse_firing_columns = [pulse_mean_string.format(number) for number in
+                                   range(1, stimulation["pulse_number"] + 1)]
+    during_pulse_firing = stimulation[during_pulse_firing_columns].values.astype(numpy.float)
+    during_pulse_firing = map(lambda isi: numpy.Infinity if numpy.isnan(isi) else isi,
+                              during_pulse_firing)
+    after_protocol_firing = stimulation["isi_after"]
+
+    firing = list(during_pulse_firing) + [after_protocol_firing]
+
+    isi_is_increasing = True
+    for isi_pre, isi_after in zip(firing[:-1], firing[1:]):
+        isi_pre = numpy.Infinity if numpy.isnan(isi_pre) else isi_pre
+        isi_after = numpy.Infinity if numpy.isnan(isi_after) else isi_after
+        isi_increases = (isi_pre < isi_after) or (isi_pre == numpy.Infinity and isi_pre == numpy.Infinity)
+        isi_is_increasing = isi_is_increasing and isi_increases
+
+    return isi_is_increasing
+
+
+for type_number in type_number_combinations:
+    protocol_type = type_number[0]
+    number = type_number[1]
+
+    # Determine the protocol
+    protocol_id = "{}-{:d}".format(protocol_type, number)
+    path_to_firing_rates_file = OUTPUT_FOLDER+HELPER_TABLE_FOLDER+"{}.csv".format(protocol_id)
+    firing_rates = pd.read_csv(path_to_firing_rates_file, index_col="stimulation_id")
+
+    if protocol_type == "UP":
+        firing_rates["was_successful"] = firing_rates.apply(analyse_up_protocols,
+                                                            axis=1)
+    elif protocol_type == "DOWN":
+        firing_rates["was_successful"] = firing_rates.apply(analyse_down_protocols,
+                                                            axis=1)
+    else:
+        RuntimeWarning("Unknown protocol {}".format(protocol_type))
+
+    stimulations.loc[(stimulations["protocol_type"] == protocol_type) & (stimulations["pulse_number"] == number) & (
+        get_filters(stimulations)),
+                     "was_successful"] = firing_rates["was_successful"].values
+
+stimulations.to_csv(path_or_buf=path_to_filtered_stimulus_file)