Skip to content

Commit

Permalink
rename get_info to extract_subject_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSkukies committed Oct 7, 2024
1 parent 41861fe commit 73776d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions src/load.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
bids_layout(bidsPath::AbstractString;
derivatives::Bool=true,
specificFolder::Union{Nothing,AbstractString}=nothing,
excludeFolder::Union{Nothing,AbstractString}=nothing,
specific_folder::Union{Nothing,AbstractString}=nothing,
exclude_folder::Union{Nothing,AbstractString}=nothing,
ses::Union{Nothing,AbstractString}=nothing,
task::Union{Nothing,AbstractString}=nothing,
run::Union{Nothing,AbstractString}=nothing)
Expand All @@ -12,9 +12,9 @@ Main function to load paths of all subjects in one bids_root folder. Will return
## Keywords
- `derivatives::Bool = true`\\
Look for data in the derivatives folder
- `specificFolder::Union{Nothing,AbstractString} = nothing`\\
- `specific_folder::Union{Nothing,AbstractString} = nothing`\\
Specify a specific folder name in either derivatives or bids_root to look for data.
- `excludeFolder::Union{Nothing,AbstractString} = nothing`\\
- `exclude_folder::Union{Nothing,AbstractString} = nothing`\\
Exclude a specific folder from data detection.
- `ses:Union{Nothing,AbstractString} = nothing`\\
Which session to load; loads all if nothing
Expand All @@ -25,8 +25,8 @@ Main function to load paths of all subjects in one bids_root folder. Will return
"""
function bids_layout(bidsPath::AbstractString;
derivatives::Bool=true,
specificFolder::Union{Nothing,AbstractString}=nothing,
excludeFolder::Union{Nothing,AbstractString}=nothing,
specific_folder::Union{Nothing,AbstractString}=nothing,
exclude_folder::Union{Nothing,AbstractString}=nothing,
ses::Union{Nothing,AbstractString}=nothing,
task::Union{Nothing,AbstractString}=nothing,
run::Union{Nothing,AbstractString}=nothing)
Expand Down Expand Up @@ -56,13 +56,13 @@ function bids_layout(bidsPath::AbstractString;
push!(exclude, "derivatives")
end

if excludeFolder !== nothing
exclude = push!(exclude, excludeFolder)
if exclude_folder !== nothing
exclude = push!(exclude, exclude_folder)
end

# Choose a specific folder in either ./ or ./derivatives
if specificFolder !== nothing
bidsPath = joinpath(bidsPath, specificFolder)
if specific_folder !== nothing
bidsPath = joinpath(bidsPath, specific_folder)
end


Expand All @@ -78,7 +78,7 @@ function bids_layout(bidsPath::AbstractString;

# Add additional information
for path in all_paths
get_info!(files_df, path)
extract_subject_id!(files_df, path)
end

# Check for multiple session/tasks/runs
Expand All @@ -95,11 +95,11 @@ function bids_layout(bidsPath::AbstractString;
end

"""
get_info!(files_df, file)
extract_subject_id!(files_df, file)
Internal function to get subject information from dataframe.
"""
function get_info!(files_df, file)
function extract_subject_id!(files_df, file)

# Make regex for parts
regex_sub = r"sub-(\d+)"
Expand Down
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ using Logging


###
@testset "UnfoldBIDS.get_info!" begin
@testset "UnfoldBIDS.extract_subject_id!" begin
# Write your tests here.

# Tests for get_info
# Tests for extract_subject_id
files_df = DataFrame(Sub=[], Ses=[], Task=[], Run=[], File=[])

# Test case 1: All fields present
file1 = "sub-01_ses-02_task-rest_run-01_bold.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file1)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file1)
@test isequal(files_df[1, :], DataFrame(Sub = "01", Ses = "02", Task = "rest", Run = "01", File = file1)[1,:])

# Test case 2: Missing run
file2 = "sub-03_ses-04_task-taskname_bold.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file2)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file2)
@test isequal(files_df[2, :], DataFrame(Sub = "03", Ses = "04", Task = "taskname", Run = missing, File = file2)[1,:])

# Test case 3: Missing session and run
file3 = "sub-05_task-taskname_bold.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file3)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file3)
@test isequal(files_df[3, :], DataFrame(Sub = "05", Ses = missing, Task = "taskname", Run = missing, File = file3)[1,:])

# Test case 4: Missing task and run
file4 = "sub-06_ses-07_bold.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file4)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file4)
@test isequal(files_df[4, :], DataFrame(Sub = "06", Ses = "07", Task = missing, Run = missing, File = file4)[1,:])

# Test case 5: Only subject
file5 = "sub-08_bold.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file5)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file5)
@test isequal(files_df[5, :], DataFrame(Sub = "08", Ses = missing, Task = missing, Run = missing, File = file5)[1,:])

# Test case 6: No matching pattern
file6 = "no_pattern_here.vhdr"
files_df = UnfoldBIDS.get_info!(files_df, file6)
files_df = UnfoldBIDS.extract_subject_id!(files_df, file6)
@test isequal(files_df[6, :], DataFrame(Sub = missing, Ses = missing, Task = missing, Run = missing, File = file6)[1,:])
end

Expand Down

0 comments on commit 73776d6

Please sign in to comment.