Skip to content

Commit

Permalink
Merge pull request #187 from dule1322/CTX-6635
Browse files Browse the repository at this point in the history
CTX-6635: Fix metadata entry with sample file matching
  • Loading branch information
igorperic17 authored Aug 20, 2024
2 parents f1202a9 + a8699d0 commit 299549b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
10 changes: 6 additions & 4 deletions tasks/r-alpha-beta-diversity/main.r
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ perpareSampleData <- function(phyloseqObject, targetColumn) {
subset_samples_custom <- function(pseq, targetColumnValue) {
metadata <- data.frame(sample_data(pseq))
if (!targetColumnValue %in% unique(metadata$target)) {
print(paste("Could not find", targetColumnValue, "among the samples"))
return(NULL)
}

Expand Down Expand Up @@ -210,10 +209,13 @@ validateTargetValues <- function(sampleDataFrame, targetValues) {
}

genusAbundancePlot <- function(pseq_bac, target_column_value, output_path, taskRun) {
print(sprintf("Creating abundance plot for %s", target_column_value))
sa <- subset_samples_custom(pseq_bac, target_column_value)
if (is.null(sa)) {
return()
}

print(sprintf("Creating abundance plot for %s", target_column_value))
genus_col_index <- which(rank_names(pseq_bac) == "genus")
sa <- subset_samples_custom(pseq_bac, target_column_value)

genus_sum = tapply(taxa_sums(sa), tax_table(sa)[, "genus"], sum, na.rm = FALSE)
topgenera = names(sort(genus_sum, TRUE))[1:30]
Expand Down Expand Up @@ -269,7 +271,7 @@ validatePhyoseq <- function(phyloseqObject) {
sampleName <- rownames(metadata)[counter + 1]
if (asvCount == 0) {
sample_data(phyloseqObject) <- subset(metadata, metadata$sampleId != sampleName)
print(paste0("Sample ", sampleName, " has 0 ASVs in the OTU table!"))
print(paste0("Sample ", sampleName, " has 0 ASVs in the OTU table! This sample will be skipped during processing!"))
}
counter <- counter + 1
}
Expand Down
22 changes: 19 additions & 3 deletions tasks/r-dada2/main.r
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,15 @@ tryFilterAndTrim <- function(
}

getSampleName <- function(forward_path, metadata) {
forward_name <- basename(forward_path)

for (sampleId in metadata$sampleId) {
if (startsWith(basename(forward_path), sampleId)) {
return(sampleId)
sample_length <- nchar(sampleId)
if (substr(forward_name, 1, sample_length) == sampleId) {
next_char <- substr(forward_name, sample_length + 1, sample_length + 1)
if (!grepl("[[:alnum:]]", next_char)) {
return(sampleId)
}
}
}

Expand Down Expand Up @@ -454,17 +460,27 @@ main <- function(taskRun) {
)

for (path in filtered_forward_read_paths) {
taskRun$createArtifact(
print(paste0("Uploading filtered_reads/", basename(path), " to artifacts..."))
artifact <- taskRun$createArtifact(
path,
file.path("filtered_reads", basename(path))
)

if (is.null(artifact)) {
print(paste0("Failed to upload filtered_reads/", basename(path), " to artifacts"))
}
}

for (path in filtered_reverse_read_paths) {
print(paste0("Uploading filtered_reads/", basename(path), " to artifacts..."))
taskRun$createArtifact(
path,
file.path("filtered_reads", basename(path))
)

if (is.null(artifact)) {
print(paste0("Failed to upload filtered_reads/", basename(path), " to artifacts"))
}
}

filtering_results_path <- file.path(output_path, "filtering_results.csv")
Expand Down

0 comments on commit 299549b

Please sign in to comment.