Browse Source

automatic generation of all necessary folders

Paul Pfeiffer 1 year ago
parent
commit
8adb6c8d54

+ 10 - 2
makefile

@@ -1,6 +1,9 @@
 all: extract_stimulations assign_protocols filter analyse_firing_rates analyse_persistent_activity plot_firing_rates plot_traces report
 
-extract_stimulations:
+check_folders:
+	python scripts/check_folder_structure.py
+
+extract_stimulations: check_folders
 	python scripts/extract_stimulations.py
 
 assign_protocols:
@@ -22,4 +25,9 @@ plot_traces:
 	python plot_traces.py
 
 report:
-	python generate_report.py
+	python generate_report.py
+
+clean:
+	rm -r out/
+
+

+ 9 - 0
scripts/check_folder_structure.py

@@ -0,0 +1,9 @@
+import os
+from tools.definitions import *
+
+def generate_folder_structure():
+    os.mkdir(OUTPUT_FOLDER)
+    os.mkdir(OUTPUT_FOLDER+HELPER_TABLE_FOLDER)
+
+if not os.path.exists(OUTPUT_FOLDER):
+    generate_folder_structure()

+ 7 - 6
scripts/extract_stimulations.py

@@ -3,8 +3,8 @@ import re
 import pandas as pd
 
 import tools.pyrelacs as pr
-from tools.helper import stimulation_metadata_raw
-
+from tools.definitions import METADATA_FOLDER, RECORDINGS_FOLDER, OUTPUT_FOLDER, HELPER_TABLE_FOLDER, \
+    STIMULATION_METADATA_RAW
 
 def extract_value_unit(value_unit_string):
     value_unit_pattern = re.compile('(\d+[e][+]\d*|[-+]?\d*\.\d+|\d+)\s*(\w+)')
@@ -18,7 +18,7 @@ def convert_to_sec(time_value, time_unit):
     return time_value
 
 
-overview_of_recordings = "metadata/cells.csv"
+overview_of_recordings = METADATA_FOLDER+"cells.csv"
 test_protocol_for_pa = "SingleStimulus"
 
 print "# Extract stimulation protocols"
@@ -57,7 +57,7 @@ for cell in cells:
     recording_counter = 0
     for _, recording in cell_recordings[cell_recordings["CellId"] == cell].iterrows():
         cell_id = cell
-        recording_dir = "recordings/"+recording["Recording"]
+        recording_dir = RECORDINGS_FOLDER+recording["Recording"]
         for info, key, dat in pr.iload('%s/stimuli.dat' % (recording_dir,)):
             if info[1]['RePro'] != test_protocol_for_pa:
                 continue
@@ -116,7 +116,8 @@ dictionary_of_stimulations = {
 
 dictionary_of_stimulations.update(parameter_dict)
 
-pd.DataFrame(data=dictionary_of_stimulations).set_index("stimulation_id").to_csv(path_or_buf=stimulation_metadata_raw)
+stimulus_table_saving_path = OUTPUT_FOLDER+HELPER_TABLE_FOLDER+STIMULATION_METADATA_RAW
+pd.DataFrame(data=dictionary_of_stimulations).set_index("stimulation_id").to_csv(path_or_buf=stimulus_table_saving_path)
 
-print "Gathered meta data for each stimulation and saved to {}".format(stimulation_metadata_raw)
+print "Gathered meta data for each stimulation and saved to {}".format(stimulus_table_saving_path)
 print ""

+ 8 - 0
scripts/tools/definitions.py

@@ -0,0 +1,8 @@
+RECORDINGS_FOLDER = "recordings/"
+METADATA_FOLDER = "metadata/"
+
+OUTPUT_FOLDER = "out/"
+HELPER_TABLE_FOLDER = "tables/"
+STIMULATION_METADATA_RAW = "stimulations_raw.csv"
+STIMULATION_METADATA_EXTENDED = "stimulations_analysed.csv"
+STIMULATION_METADATA_FILTERED = "stimulations_analysed_and_filtered.csv"

+ 0 - 5
scripts/tools/helper.py

@@ -30,11 +30,6 @@ def get_traces(stimulation):
     return traces
 
 
-stimulation_metadata_raw = "stimulations_raw.csv"
-stimulation_metadata_extended = "stimulations_analysed.csv"
-stimulation_metadata_filtered = "stimulations_analysed_and_filtered.csv"
-
-
 def get_filters(stimulations):
     filter_columnns = filter(lambda key: key.startswith("filter"), stimulations.keys())
     combined_filters = reduce(lambda filtering_status, filtering_column: filtering_status & stimulations[filtering_column] == True, filter_columnns, True)