ElectroPhysiology.Epoch
— TypeThis object contains information about the stimulus Epoch coming from the Cmd
To initialize an Epoch use this function: julia> Epoch() Epochs will have a type associated {T} with the type of numerical data being T. For Julia this can be Float64, but for older files this may be Float32.
Epoch is a struct that contains:
1) 'epochLetter::String' -> The alphabetical label of the Epoch
2) 'epochType::String' -> The type of epoch. Comes in terms of Step, Pulse, Ramp, Triangle, Saw.
3) 'dacNum::T' -> The Digital to Analog channel that contains the stimulus.
4) 'epochNumber::T' -> The number ID related to the Epoch
5) 'level::T' -> The holding level of the Epoch. The value related to the command is found in the "dacUnits"
6) 'levelDelta::T' -> The change in level for each trial.
7) 'duration::T' -> How long the DAC will be held at a certai level
8) 'durationDelta::T' -> From trial to trial the change in the duration
9) 'digitalPattern::Vector'{T} -> If a digital channel is used, a digital bit pattern will be used (8 bits)
10) 'pulsePeriod::T' -> The periodicity of the pulse (Sine Wave)
11) 'pulseWidth::T' -> The width of the pulse (Sine Wave)
ElectroPhysiology.Experiment
— TypeExperiment{FORMAT, T}
A mutable struct representing a physiological experiment.
Fields
HeaderDict
: A dictionary containing header information for the experiment.dt
: AReal
value representing the time step between data points.t
: A vector containing the time points of the experiment.data_array
: A 3-dimensional array containing the experimental data.chNames
: A vector of strings representing the names of the channels.chUnits
: A vector of strings representing the units of the channels.chGains
: A vector ofReal
values representing the Gains values of the channels.stimulus_protocol
: AStimulusProtocol{T}
object containing the stimulus protocol information.
Constructors
Experiment(data_array::AbstractArray; data_idx = 2)
: Create anExperiment
object from an input data array with an optional data index.Experiment(time::Vector, data_array::Array{T, 3}) where T <: Real
: Create anExperiment
object from an input time vector and data array.
NOTE stimulus protocols are now going into the HeaderDict Object
ElectroPhysiology.Flash
— TypeFlash <: Stimulus
A Flash
is a subtype of Stimulus
representing a flash stimulus in a physiological experiment.
Fields
intensity
: AReal
value indicating the intensity of the flash.
Constructors
Flash()
: Creates a defaultFlash
object with an intensity of 0.0.Flash(intensity::Real)
: Creates aFlash
object with the specifiedintensity
.
ElectroPhysiology.Stimulus
— TypeStimulus
An abstract type representing a stimulus in a physiological experiment.
Subtypes of Stimulus
should implement specific stimulus types and their corresponding parameters.
ElectroPhysiology.StimulusProtocol
— TypeStimulusProtocol{T, S} where {T <: Real, S <: Stimulus}
A mutable struct representing a stimulus protocol for physiological data.
Fields
type
: AStimulus
object describing the type of stimulus applied during the experiment.channelName
: AUnion{String, Int64}
representing the name or number of the channel where the stimulus is applied.timestamps
: AVector{Tuple{T, T}}
storing the start and end timestamps of the stimulus events.
Constructors
StimulusProtocol()
: Creates a defaultStimulusProtocol
object withFlash()
stimulus, "Nothing" channel, and a single (0.0, 0.0) timestamp.StimulusProtocol(stimulus_channel::String)
: Creates aStimulusProtocol
object withFlash()
stimulus, the providedstimulus_channel
, and a single (0.0, 0.0) timestamp.StimulusProtocol(swp::Int64)
: Creates aStimulusProtocol
object withFlash()
stimulus, "Nothing" channel, andswp
number of (0.0, 0.0) timestamps.StimulusProtocol(stimulus_channel::String, swp::Int64)
: Creates aStimulusProtocol
object withFlash()
stimulus, the providedstimulus_channel
, andswp
number of (0.0, 0.0) timestamps.
Examples
stim1 = StimululsProtocol()
stim_channel = StimulusProtocol("IN 3")
stim_sweep = StimulusProtocol(3)
stim_sweep_channel = StimululsProtocol(3, "IN 3")
stim_tstamp = StimululsProtocol((0.0, 0.01))
stim_type_time_channel = StimulusProtocol(Flash(), "IN 3", (0.00, 0.01))
Base.chop
— Methodchop(trace::Experiment, n_chop::Int64; position::Symbol=:post)
chop!(trace::Experiment, n_chop::Int64; position::Symbol=:post)
Chop a specified number of elements from the data in a given Experiment
object, either from the beginning or the end. This function returns a new Experiment
object with the modified data.
Arguments
trace
: AnExperiment
object containing the experimental data.n_chop
: The number of elements to remove.position
: (Optional) A symbol specifying where to remove the elements. Can be:pre
(from the beginning) or:post
(from the end). Default is:post
.
Example
exp = Experiment(data_array)
chopped_exp = chop(exp, 100, position=:pre)
ElectroPhysiology.average_trials
— Methodaverage_trials(trace::Experiment)
average_trials!(trace::Experiment)
Return a new Experiment
object with the average of all trials of the input Experiment
object.
Arguments
trace
: AnExperiment
object containing the experimental data.
Example
exp = Experiment(data_array)
averaged_exp = average_trials(exp)
exp = Experiment(data_array)
average_trials!(exp)
ElectroPhysiology.baseline_adjust
— Methodbaseline_adjust(trace::Experiment{F,T}; kwargs...) where {T<:Real}
baseline_adjust!(trace::Experiment{F,T}; kwargs...) where {T<:Real}
Return a new Experiment
object with the baseline adjusted according to the specified mode and region.
Arguments
trace
: AnExperiment
object containing the experimental data.
Keyword Arguments
mode
: Baseline adjustment mode, either:mean
or:slope
(default::slope
).polyN
: Polynomial order for the baseline fit (default: 1).region
: Range for baseline adjustment, either:prestim
,:whole
, a tuple of time values or a tuple of indices.
Example
exp = Experiment(data_array)
baseline_adjusted_exp = baseline_adjust(exp, mode=:mean, region=:prestim)
exp = Experiment(data_array)
baseline_adjust!(exp, mode=:mean, region=:prestim)
ElectroPhysiology.downsample
— Methoddownsample(trace::Experiment, sample_rate::T) where {T<:Real}
Return a new Experiment
object with the data downsampled to the specified sample_rate
.
Arguments
trace
: AnExperiment
object containing the experimental data.sample_rate
: The desired new sample rate.
Example
exp = Experiment(data_array)
downsampled_exp = downsample(exp, 1000.0)
julia exp = Experiment(data_array) downsample!(exp, 1000.0)
julia exp = Experiment(data_array) downsample!(exp, 1000.0) ```
ElectroPhysiology.drop!
— Methoddrop!(data, dim = 3)
Removes a channel or trial
ElectroPhysiology.dyadic_downsample!
— Methoddyadic_downsample(trace::Experiment{F,T}) where {T<:Real}
dyadic_downsample!(trace::Experiment{F,T}) where {T<:Real}
Return a new Experiment
object with the data downsampled to the nearest dyadic length.
Arguments
trace
: AnExperiment
object containing the experimental data.
Example
exp = Experiment(data_array)
dyadic_downsampled_exp = dyadic_downsample(exp)
exp = Experiment(data_array)
dyadic_downsample!(exp)
ElectroPhysiology.eachchannel
— Methodeachchannel(trace::Experiment; verbose=false)
Return an iterator that iterates over each channel of the input trace
as an Experiment
object.
Arguments
trace
: AnExperiment
object containing the experimental data.
Returns
- An iterator that yields an
Experiment
object for each channel in the inputtrace
.
Example
channel_iter = eachchannel(trace)
for channel in channel_iter
# Process each channel
end
ElectroPhysiology.eachtrial
— Methodeachtrial(trace::Experiment)
Return an iterator that iterates over each trial of the input trace
as an Experiment
object.
Arguments
trace
: AnExperiment
object containing the experimental data.
Returns
- An iterator that yields an
Experiment
object for each trial in the inputtrace
.
Example
trial_iter = eachtrial(trace)
for trial in trial_iter
# Process each trial
end
ElectroPhysiology.extractStimulus
— MethodextractStimulus(abfInfo::Dict{String, Any}; stimulus_name::String="IN 7", stimulus_threshold::Float64=2.5)
extractStimulus(abf_path::String; kwargs...)
Extract the stimulus information from the given abfInfo
dictionary and returns a StimulusProtocol
object containing stimulus timestamps.
Arguments
abfInfo
: A dictionary containing information about the physiological data.stimulus_name
: (Optional) The name of the stimulus channel. Default is "IN 7".stimulus_threshold
: (Optional) The threshold for detecting stimulus events in the waveform. Default is 2.5.
Returns
- A
StimulusProtocol
object containing the stimulus timestamps for each trial.
Examples
abfInfo = loadABF("path/to/abf/file")
stimuli = extractStimulus(abfInfo)
stimuli = extractStimulus("path/to/abf/file")
ElectroPhysiology.filter_data
— MethodFilters data in the `exp` object using a digital filter.
# Parameters
- exp : Experiment{F, T}
an object containing the data to be filtered
- freq_start : float (optional)
start frequency for the filter, default is 1.0
- freq_stop : float (optional)
stop frequency for the filter, default is 55.0
- bandwidth : float (optional)
bandwidth for the filter, default is 10.0
- mode : Symbol (optional)
filter mode, can be :Lowpass, :Highpass, :Bandpass, :Bandstop, default is :Lowpass
- method : Symbol (optional)
method used to design the filter, can be :Butterworth, :Chebyshev1, :Chebyshev2, :Elliptic, default is :Chebyshev2
- pole : int (optional)
number of poles for the filter, default is 8
- ripple : float (optional)
ripple for the filter, default is 15.0
- attenuation : float (optional)
attenuation for the filter, default is 100.0
- filter_channels : int or Vector{String} (optional)
channels to be filtered, can be an integer index or a vector of channel names, default is -1 (all channels)
# Returns
- The input exp object is modified in place.
# Example
```julia
exp = Experiment(data_array, dt)
filter_data!(exp, freq_start=5, freq_stop=10, mode=:Bandpass)
```
ElectroPhysiology.findChIdx
— MethodA quick convienance function that returns the index of the channel that is named
ElectroPhysiology.getIntensity
— MethodsetIntensity(stimulus_protocols::StimulusProtocol{T, Flash}, photons::Vector)
This allows the intensity of the stimulus protocol (or multiple stimulus protocols be set).
Arguments
stimulus_protocol::StimulusProtocol{T, S} where S <: Flash
: A stimulus protocolphotons::Vector
: a vector of numbers representing the photon amount.
ElectroPhysiology.getROImask
— MethodThis function gets the ROI label and returns the mask
ElectroPhysiology.getWaveform
— MethodgetWaveform(abfInfo::Dict{String, Any}, trial, channel; channel_type)
extracts a waveform from the data, digital stimuli, or analog stimuli
... #Arguments NEEDED: -'abfInfo': A dictionary containing all info parsed from the the .abf file -'trial': trial/trials that will be read from the data or stimuli This is a Int64 number or a list of numbers that represents the index/indexes of the trial -'channel': The channel which is set to be the explicit stimulus This can either be a channel index, or a string OPTIONS: -'channel_type': This represents where the waveform will come from. There are 3 options: data -> this is the actual data of the file analog -> this is the analog stimulus of the file digital -> this is the digital stimulus of the file ...
ElectroPhysiology.getchannel
— Method getchannel(trace::Experiment, ch_idx::Int64; verbose=false)
Return a new Experiment object with data from a single channel specified by ch_idx.
Arguments
trace: An Experiment object containing the experimental data.
ch_idx: The index of the channel to extract.
ch_name: The name of the channel to extract
Returns
data: A new Experiment object containing the data from the specified channel.
Examples
getchannel(trace::Experiment, ch_idx::Int64; verbose=false) = getdata(trace, :, :, ch_idx; verbose=verbose)
ElectroPhysiology.getdata
— Methodgetdata(trace::Experiment, trials, timepoints, channels::Union{String,Vector{String}})
getdata(trace::Experiment, trials, timepoints, channels; verbose=false)
Return a new Experiment
object with a specified subset of data extracted from the input trace
based on trials
, timepoints
, and channels
.
Arguments
trace
: AnExperiment
object containing the experimental data.trials
: A selection of trials to include in the new data.timepoints
: A selection of timepoints to include in the new data.channels
: AString
orVector{String}
specifying the channels to include in the new data.
Returns
data
: A newExperiment
object containing the specified subset of data.
Example
data = getdata(trace, 1:5, 100:200, ["Ch1", "Ch2"])
ElectroPhysiology.match_channels
— Methodmatch_channels(exp1::Experiment, exp2::Experiment)
Return two modified Experiment
objects with their channels matched.
If the number of channels in exp1
and exp2
is not equal, this function will drop extra channels from the Experiment
object with more channels, making both objects have the same number of channels.
Arguments
exp1
: AnExperiment
object containing the experimental exp.exp2
: AnotherExperiment
object to be matched withexp1
.
Returns
(exp1_modified, exp2_modified)
: A tuple containing the two modifiedExperiment
objects with matched channels.
Example
exp1 = Experiment(exp_array1)
exp2 = Experiment(exp_array2)
exp1_modified, exp2_modified = match_channels(exp1, exp2)
ElectroPhysiology.openABF
— MethodThis function opens the ABF file in clampfit
ElectroPhysiology.pad
— Methodpad(trace::Experiment{F,T}, n_add::Int64; position::Symbol=:post, val::T=0.0) where {T <: Real}
pad!(trace::Experiment{F,T}, n_add::Int64; position::Symbol=:post, val::T=0.0) where {T <: Real}
Pad the data in a given Experiment
object by adding elements with a specified value val
either before or after the existing data. This function returns a new Experiment
object with the padded data. pad! is the inplace version, while pad creates a new experiment
Arguments
trace
: AnExperiment{F,T}
object containing the experimental data.n_add
: The number of elements to add.position
: (Optional) A symbol specifying where to add the elements. Can be:pre
(before) or:post
(after). Default is:post
.val
: (Optional) The value to use for padding. Default is 0.0.
Example
exp = Experiment(data_array)
padded_exp = pad(exp, 100, position=:pre, val=0.0)
ElectroPhysiology.parseABF
— MethodparseABF(super_folder::String; extension::String=".abf")
Search for files with a specific extension (default is ".abf") in a given directory and its subdirectories. Returns a list of file paths for all matching files.
Arguments
super_folder
: A string representing the path to the root directory to search for files.extension
: (Optional) A string representing the file extension to search for (default is ".abf").
Returns
file_list
: An array of strings representing the file paths of all matching files.
Throws
ArgumentError
: If no matching files are found in the given directory.
Examples
file_list = parseABF("path/to/folder")
file_list = parseABF("path/to/folder", extension=".txt")
ElectroPhysiology.readABF
— MethodreadABF(::Type{T}, abf_data::Union{String,Vector{UInt8}};
trials::Union{Int64,Vector{Int64}}=-1,
channels::Union{Int64, Vector{String}}=["Vm_prime", "Vm_prime4"],
average_trials::Bool=false,
stimulus_name::Union{String, Vector{String}, Nothing}="IN 7",
stimulus_threshold::T=2.5,
warn_bad_channel=false,
flatten_episodic::Bool=false,
time_unit=:s,
) where {T<:Real}
Read an Axon Binary File (ABF) and return an Experiment
object. The function extracts data for the specified trials and channels, and optionally averages trials or flattens episodic data.
Arguments
abf_data
: AString
representing the ABF file path or aVector{UInt8}
containing the ABF file content.trials
: AnInt64
or aVector{Int64}
specifying the trials to extract. Default is -1 (all trials).channels
: AnInt64
or aVector{String}
specifying the channels to extract. Default is ["Vmprime", "Vmprime4"].average_trials
: ABool
specifying whether to average the trials. Default isfalse
.stimulus_name
: AString
,Vector{String}
, orNothing
specifying the stimulus name(s). Default is "IN 7".stimulus_threshold
: A threshold value of typeT
for the stimulus. Default is 2.5.warn_bad_channel
: ABool
specifying whether to warn if a channel is improper. Default isfalse
.flatten_episodic
: ABool
specifying whether to flatten episodic stimulation to be continuous. Default isfalse
.time_unit
: ASymbol
specifying the time unit. Default is:s
(seconds).
Returns
- An
Experiment
object containing the extracted data, along with metadata.
Example
exp = readABF(Float32, "path/to/abf_file.abf")
ElectroPhysiology.readABFInfo
— MethodThis scans the axon binary and extracts all the most useful header information
For datashape 1 -> channels 2 -> dataspan 3 -> trials
ElectroPhysiology.readABFInfo
— MethodIt may become useful (in the case of Pluto.jl) to read the data directly from Binary Data
ElectroPhysiology.readStruct
— MethodThese functions handle the byte interpretations of the ABF file
ElectroPhysiology.recordROI
— MethodROIs are masks. A ROI is a mask of falses (which are not included in the image) and trues (which are)
ElectroPhysiology.scaleby!
— Methodscaleby!(data::Experiment{F,T}, val::T) where T <: Real
scaleby!(data::Experiment{F,T}, val::Vector{T}) where T <: Real
Scale the data elements in the given Experiment
object by a scalar value val
in-place. If val is a vector of values, The length of the vector should match either the number of channels or the number of trials in the experiment.
Arguments
data
: AnExperiment{F,T}
object containing the experimental data.val
: A scalar value by which to scale the data.
Example
exp = Experiment(data_array)
scaleby!(exp, 2.0)
ElectroPhysiology.setIntensity
— MethodsetIntensity(stimulus_protocols::StimulusProtocol{T, Flash}, photons::Vector{T}) where T<:Real
setIntensity(stimulus_protocols::StimulusProtocol{T, Flash}, photon::T) where T<:Real
This allows the intensity of the stimulus protocol (or multiple stimulus protocols be set).
Arguments
stimulus_protocol::StimulusProtocol{T, S} where S <: Flash
: A stimulus protocolphotons::Vector
: a vector of numbers representing the photon amount.
Examples
ElectroPhysiology.sub_exp
— Methodsub_exp(exp1::Experiment, exp2::Experiment)
Subtract the exp of exp2
from exp1
and return a new Experiment
object with the resulting exp.
This function will automatically match the channels of both Experiment
objects if they do not match. If the channels do not match, it will drop the unmatching channels by default.
Arguments
exp1
: AnExperiment
object containing the experimental exp.exp2
: AnotherExperiment
object containing the exp to be subtracted fromexp1
.
Returns
exp
: A newExperiment
object with the resulting exp after the subtraction.
Example
exp1 = Experiment(exp_array1)
exp2 = Experiment(exp_array2)
result_exp = sub_exp(exp1, exp2)
ElectroPhysiology.truncate_data!
— Methodtruncate_data!(trace::Experiment; t_pre=1.0, t_post=4.0, t_begin=nothing, t_end=nothing, truncate_based_on=:stimulus_beginning)
truncate_data(trace::Experiment; kwargs...)
Truncate data in the Experiment
object, in-place, either based on the stimulus position or a specified time range.
Arguments
trace
: AnExperiment
object containing the experimental data.t_pre
: (Optional) Time before the stimulus to truncate the data. Default is 1.0.t_post
: (Optional) Time after the stimulus to truncate the data. Default is 4.0.t_begin
: (Optional) Start time of the time range for truncation.t_end
: (Optional) End time of the time range for truncation.truncate_based_on
: (Optional) A symbol specifying the truncation method. Can be:stimulus_beginning
,:stimulus_end
, or:time_range
. Default is:stimulus_beginning
.
Example
exp = Experiment(data_array)
truncate_data!(exp, t_pre=0.5, t_post=2.5)
exp = Experiment(data_array)
truncated_exp = truncate_data(exp, t_pre=0.5, t_post=2.5)