Last active
August 29, 2019 01:14
-
-
Save Shians/dc8dc5865eb8972252bbee4c4f81f7b8 to your computer and use it in GitHub Desktop.
Generate nanopolish index in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env Rscript | |
| library(fs) | |
| library(rhdf5) | |
| library(parallel) | |
| library(purrr) | |
| library(stringr) | |
| library(dplyr) | |
| library(tidyr) | |
| index_fast5 <- function(fastq_file, fast5_dir) { | |
| stopifnot(file_exists(fastq_file)) | |
| f5_files <- path_real( | |
| dir_ls(fast5_dir, glob="*.fast5") | |
| ) | |
| stopifnot(length(f5_files) > 0) | |
| names(f5_files) <- f5_files | |
| x <- mclapply( | |
| f5_files, | |
| partial(h5ls, recursive = FALSE), | |
| mc.cores = 128L # OS begins complaining when I go up to 512 processes | |
| ) | |
| # this creates a table with almost the same information as readdb files | |
| # just need to trim the paths and read names | |
| index <- bind_rows(x, .id = "fast5_file") %>% | |
| mutate(read = str_remove(name, "^read_")) %>% | |
| select(read, fast5_file) | |
| readdb_name <- paste0(fastq_file, ".index.readdb") | |
| write_tsv(index, path = readdb_name, col_names = FALSE) | |
| } | |
| args <- commandArgs(trailingOnly = TRUE) | |
| fastq_file <- args[1] | |
| fast5_dir <- args[2] | |
| index_fast5(fastq_file, fast5_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment