From f3b0b48b08ce797230fc33b68e3ac1f93c400eee Mon Sep 17 00:00:00 2001 From: "Dadi Zhao (Cancer and Genomic Sciences)" Date: Mon, 20 May 2024 13:58:57 +0100 Subject: [PATCH] Update GUI and python definition --- src/Import/acq/acqread_python.m | 33 +++++++++++++++++++------------- src/pspm_get_acq_python.m | 34 +++++++++++++++++++++++++++++++++ src/pspm_init.m | 14 ++++++++++++++ src/pspm_text.m | 1 + 4 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/pspm_get_acq_python.m diff --git a/src/Import/acq/acqread_python.m b/src/Import/acq/acqread_python.m index f764a336..45d35ff2 100644 --- a/src/Import/acq/acqread_python.m +++ b/src/Import/acq/acqread_python.m @@ -8,34 +8,41 @@ % import: the import struct of importing settings % ● History % Introduced in PsPM 6.1.2 -% Written in May 2024 by Madni Abdul Wahab (Uni Bonn) - +% Written in May 2024 by Madni Abdul Wahab (Uni Bonn) and Teddy + + %% Initialise python + if isempty(options.python_path) + psts = pspm_check_python; + else + psts = pspm_check_python(options.python_path); + end + %% Set the Python environment and the filename py_filename = py.str(filename); acq_data = py.bioread.read(py_filename); % Load the data using Bioread - + num_channels = length(acq_data.channels); % Determine the number of channels data.channels = cell(1, num_channels); - + %% Iterate through each channel for idx = 1:num_channels - channel = acq_data.channels{idx}; - data.channels{idx} = struct(); - + channel = acq_data.channels{idx}; + data.channels{idx} = struct(); + % Convert Python dir() list to MATLAB cell array attrs = cell(py.dir(channel)); - + % Convert all attributes to strings to ensure compatibility with startsWith attrs = cellfun(@char, attrs, 'UniformOutput', false); - + % Manually filter out private attributes (those starting with '_') in MATLAB filtered_attrs = attrs(~startsWith(attrs, '_')); - + % Iterate over attributes and fetch their values for attr_name = filtered_attrs % Python getattr to get attribute value attr_value = py.getattr(channel, attr_name{1}); - + % Try converting Python data types to MATLAB data types try if isa(attr_value, 'py.numpy.ndarray') @@ -55,10 +62,10 @@ catch matlab_value = []; % If conversion fails, set as empty end - + % Assign converted value to the struct data.channels{idx}.(char(attr_name{1})) = matlab_value; end end - + return; diff --git a/src/pspm_get_acq_python.m b/src/pspm_get_acq_python.m new file mode 100644 index 00000000..2f336668 --- /dev/null +++ b/src/pspm_get_acq_python.m @@ -0,0 +1,34 @@ +function [sts, import, sourceinfo] = pspm_get_acq_python(datafile, import) +% ● Description +% pspm_get_acq is the main function for import of biopac/acknowledge files +% ● Format +% [sts, import, sourceinfo] = pspm_get_acq(datafile, import); +% this function uses the conversion routine acqread.m version 2.0 (2007-08-21) +% by Sebastien Authier and Vincent Finnerty at the University of Montreal +% which supports all files created with Windows/PC versions of +% AcqKnowledge (3.9.0 or below), BSL (3.7.0 or below), and BSL PRO +% (3.7.0 or below). +% ● Arguments +% datafile: the acq data file +% import: the struct for importing settings +% .channel: data channels to be imported +% .type: data channel types to be imported +% .sr: sampling frequency +% .data: imported data +% .marker: imported markers +% ● History +% Introduced in PsPM 6.1.2 +% Written in 2024 by Teddy + +%% initialise +global settings +if isempty(settings) + pspm_init; +end +sts = -1; +sourceinfo = []; +addpath(pspm_path('Import','acq')); + +%% load data but suppress output +[sts, data] = evalc('acqread_python(datafile)'); +end diff --git a/src/pspm_init.m b/src/pspm_init.m index 25464a3a..ad1134b0 100644 --- a/src/pspm_init.m +++ b/src/pspm_init.m @@ -373,6 +373,20 @@ 'autosr', 1,... 'help', helptext_import_acq); % +% 4.10 bioread converted Biopac Acqknowledge (any version, with python) +defaults.import.datatypes(end+1) = struct(... + 'short', 'acq_python',... + 'long', 'Biopac Acqknowledge (any version) with python',... + 'ext', 'acq',... + 'funct', @pspm_get_acq_python,... + 'channeltypes', {{defaults.importchanneltypes.type}},... + 'chandescription', 'channel',... + 'multioption', 1,... + 'searchoption', 1,... + 'automarker', 0,... + 'autosr', 1,... + 'help', helptext_import_acq_python); +% % 4.8 exported Biopac Acqknowledge (tested on version 4.2.0) defaults.import.datatypes(end+1) = struct(... 'short', 'acqmat',... diff --git a/src/pspm_text.m b/src/pspm_text.m index 62b095c9..8ffd87f6 100644 --- a/src/pspm_text.m +++ b/src/pspm_text.m @@ -5,6 +5,7 @@ function pspm_text(path) % Introduced in PsPM 6.0 % Written and maintained in 2022 by Teddy Chao (UCL) helptext_import_acq = ''; +helptext_import_acq_python = 'Load acq files directly to PsPM with Python'; helptext_import_acqmat = ''; helptext_import_bioread = 'Loads mat files which have been converted using the bioread tool acq2mat. Bioread can be installed using pip (installed by python) or can be downloaded and installed manually from here https://github.com/njvack/bioread. It requires python and the python libraries numpy and scipy.'; helptext_import_csv = 'Read using comma as a delimiter.';