Load, Validate, and Consolidate TWAS Weights from Multiple RDS Files
Source:R/file_utils.R
load_twas_weights.RdThis function loads TWAS weight data from multiple RDS files, checks for the presence of specified region and condition. If variable_name_obj is provided, it aligns and consolidates weight matrices based on the object's variant names, filling missing data with zeros. If variable_name_obj is NULL, it checks that all files have the same row numbers for the condition and consolidates weights accordingly.
Arguments
- variable_name_obj
The name of the variable/object to fetch from each file, if not NULL.
- weight_db_file
weight_db_files Vector of file paths for RDS files containing TWAS weights.. Each element organized as region/condition/weights
- condition
The specific condition to be checked and consolidated across all files.
Examples
# Example usage (replace with actual file paths, condition, region, and variable_name_obj):
weight_db_files <- c("path/to/file1.rds", "path/to/file2.rds")
condition <- "example_condition"
region <- "example_region"
variable_name_obj <- "example_variable" # or NULL for standard processing
consolidated_weights <- load_twas_weights(weight_db_files, condition, region, variable_name_obj)
#> Warning: cannot open compressed file 'path/to/file1.rds', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb") : cannot open the connection
print(consolidated_weights)
#> [1] "Error in gzfile(file, \"rb\") : cannot open the connection\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <simpleError in gzfile(file, "rb"): cannot open the connection>