From 5ed731169cfb6a50d0480243805aae56b37fb4d2 Mon Sep 17 00:00:00 2001 From: Liripo <54770415+Liripo@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:18:20 +0800 Subject: [PATCH] Update loadContigs.R Prevent file.pattern from being NULL, causing all files in the directory to be read. --- R/loadContigs.R | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/R/loadContigs.R b/R/loadContigs.R index 469c9f3f..2d34dead 100644 --- a/R/loadContigs.R +++ b/R/loadContigs.R @@ -43,18 +43,19 @@ loadContigs <- function(input, format = "10X") { #Loading from directory, recursively if (inherits(x=input, what ="character")) { - format.list <- list("WAT3R" = "barcode_results.csv", - "10X" = "filtered_contig_annotations.csv", - "AIRR" = "airr_rearrangement.tsv", - "Dandelion" = "all_contig_dandelion.tsv", - "Immcantation" = "_data.tsv", - "MiXCR" = "clones.tsv", - "JSON" = ".json", - "TRUST4" = "barcode_report.tsv", - "BD" = "Contigs_AIRR.tsv", - "Omniscope" =c("_OSB.csv", "_OST.csv"), - "ParseBio" = "barcode_report.tsv") - file.pattern <- format.list[[format]] + file.pattern <- switch(format, + "WAT3R" = "barcode_results.csv", + "10X" = "filtered_contig_annotations.csv", + "AIRR" = "airr_rearrangement.tsv", + "Dandelion" = "all_contig_dandelion.tsv", + "Immcantation" = "_data.tsv", + "MiXCR" = "clones.tsv", + "JSON" = ".json", + "TRUST4" = "barcode_report.tsv", + "BD" = "Contigs_AIRR.tsv", + "Omniscope" = c("_OSB.csv", "_OST.csv"), + "ParseBio" = "barcode_report.tsv", + stop("Invalid format: ",format)) contig.files <- list.files(input, paste0(file.pattern, collapse = "|"), recursive = TRUE, full.names = TRUE) if (format %in% c("10X", "WAT3R", "Omniscope")) { @@ -285,4 +286,4 @@ loadContigs <- function(input, colnames(df[[i]]) <- c("barcode", "chain", "reads", "v_gene", "d_gene", "j_gene", "c_gene", "cdr3_nt", "cdr3", "productive") } return(df) -} \ No newline at end of file +}