MegaScale / src /02.3_assemble_structure_datasets.R
maom's picture
update upload assemble and upload scripts
f356ef8
#' Assemble PDBs
#'
#' @param data_path character directory .pdb.gz files are located
#' @param output_path character output .parquet path
#'
#' Write output_path .parquet file with columns
#' <id> <pdb>
assemble_models <- function(
data_path,
output_path) {
cat(
"data path: ", data_path, "\n",
"output path: ", output_path, "\n",
sep = "")
file_index <- 1
models <- list.files(
path = data_path,
full.names = TRUE,
pattern = "*.pdb",
recursive = TRUE) |>
purrr::map_dfr(.f = function(path) {
file_handle <- path |>
file(open = "rb") |>
gzcon()
if( file_index %% 20 == 0) {
cat("Reading '", path, "' ", file_index, "\n", sep = "")
}
file_index <<- file_index + 1
lines <- file_handle |> readLines()
file_handle |> close()
data.frame(
name = path |>
basename() |>
stringr::str_replace("[:]", "|"),
pdb = lines |> paste0(collapse = "\n"))
})
models |> arrow::write_parquet(output_path)
models
}
assemble_models(
data_path = "data/AlphaFold_model_PDBs",
output_path = "intermediate/AlphaFold_model_PDBs.parquet")