Datasets:
Download scripts/separate_composite.R from BrentLab/callingcards: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/BrentLab/callingcards/resolve/main/scripts/separate_composite.R
- Command line
-
hf download hf://datasets/BrentLab/callingcards/scripts/separate_composite.R
-
curl -L -o separate_composite.R https://huggingface.co/datasets/BrentLab/callingcards/resolve/main/scripts/separate_composite.R
2.07 kB
| library(tidyverse) | |
| library(arrow) | |
| meta = arrow::read_parquet("~/code/hf/callingcards/annotated_features_meta.parquet") | |
| composite_meta = meta %>% | |
| filter(batch == "composite") | |
| binding_id_to_genome_map_id = meta %>% | |
| select(genome_map_id, binding_id) %>% | |
| filter(complete.cases(.)) %>% | |
| distinct() | |
| composite_binding_id_to_composite_genome_map_id = composite_meta %>% | |
| select(binding_id) %>% | |
| mutate(genome_map_id_set = map(binding_id, function(bid_str) { | |
| # Parse the JSON-like string to extract individual binding_ids | |
| bid_vec = str_extract_all(bid_str, "\\d+")[[1]] | |
| # Look up corresponding genome_map_ids | |
| binding_id_to_genome_map_id %>% | |
| filter(binding_id %in% bid_vec) %>% | |
| pull(genome_map_id)})) %>% | |
| mutate(genome_map_id_set = map_chr(genome_map_id_set, ~paste(.x, collapse = "-"))) | |
| composite_meta_revise = composite_meta %>% | |
| select(-genome_map_id) %>% | |
| left_join(composite_binding_id_to_composite_genome_map_id) %>% | |
| dplyr::relocate(genome_map_id_set) | |
| af_data = arrow::open_dataset("~/code/hf/callingcards/annotated_features") %>% | |
| filter(id %in% composite_meta_revise$id) %>% | |
| collect() %>% | |
| select(-batch) %>% | |
| left_join(composite_meta_revise %>% | |
| select(id, genome_map_id_set)) %>% | |
| select(-id) %>% | |
| dplyr::relocate(genome_map_id_set) | |
| # composite_meta_revise %>% | |
| # select(-id) %>% | |
| # dplyr::relocate(genome_map_id_set) %>% | |
| # arrow::write_parquet( | |
| # "~/code/hf/callingcards/annotated_features_combined_meta.parquet", | |
| # compression = "zstd", | |
| # write_statistics = TRUE, | |
| # use_dictionary = c( | |
| # regulator_locus_tag = TRUE, | |
| # regulator_symbol = TRUE, | |
| # condition = TRUE)) | |
| # | |
| # arrow::write_dataset( | |
| # af_data, | |
| # path = "/home/chase/code/hf/callingcards/annotated_features_combined", | |
| # format = "parquet", | |
| # partitioning = c("genome_map_id_set"), | |
| # existing_data_behavior = "overwrite", | |
| # compression = "zstd", | |
| # write_statistics = TRUE) | |