Skip to content

Commit 8d4c10f

Browse files
Added helper functions for testing treatment strings
1 parent 99cf6aa commit 8d4c10f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/testutils.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,30 @@ function make_estimands_configuration_file(config_generator=make_estimands_confi
202202
filename = joinpath(dir, "configuration.yaml")
203203
TMLE.write_yaml(filename, config)
204204
return filename
205-
end
205+
end
206+
207+
# Additional helper functions for testing GWAS treatment strings
208+
209+
get_only_file_with_suffix(files, suffix) = files[only(findall(x -> endswith(x, suffix), files))]
210+
211+
function files_matching_prefix(prefix)
212+
directory, _prefix = splitdir(prefix)
213+
_directory = directory == "" ? "." : directory
214+
215+
return map(
216+
f -> joinpath(directory, f),
217+
filter(
218+
f -> startswith(f, _prefix),
219+
readdir(_directory)
220+
)
221+
)
222+
end
223+
224+
function read_bed_chromosome(bedprefix)
225+
bed_files = files_matching_prefix(bedprefix)
226+
fam_file = get_only_file_with_suffix(bed_files, "fam")
227+
bim_file = get_only_file_with_suffix(bed_files, "bim")
228+
bed_file = get_only_file_with_suffix(bed_files, "bed")[1:end-4]
229+
return SnpData(bed_file, famnm=fam_file, bimnm=bim_file)
230+
end
231+

0 commit comments

Comments
 (0)