Skip to content

Commit

Permalink
lint R
Browse files Browse the repository at this point in the history
  • Loading branch information
paulzierep committed Oct 14, 2024
1 parent 4eb49d0 commit 1f99467
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tools/decontam/test-data/decontam_Rscript.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ head(metadata, 1000)
# store test data
# stores the row names as column,
#see https://stackoverflow.com/questions/2478352
#/write-table-writes-unwanted-leading-empty-column-to-header-when-has-rownames
# see https://stackoverflow.com/questions/2478352
# /write-table-writes-unwanted-leading-empty-column-to-header-when-has-rownames
write.table(data.frame("SampleID" = rownames(otu), otu),
file = file.path(getwd(), "otu_input.tsv"),
sep = "\t",
Expand Down Expand Up @@ -111,9 +111,9 @@ meta2$control <- as.logical(meta2[[control_column]])
sampledata <- sample_data(meta2)
# create dummy tax table (actually not needed,
#but nice to learn how to load phyloseq objects)
# but nice to learn how to load phyloseq objects)
taxmat <- as.data.frame(matrix(sample(letters, 10, replace = TRUE),
nrow = ncol(otu2), ncol = 7))
nrow = ncol(otu2), ncol = 7))
rownames(taxmat) <- colnames(otu2)
tax <- tax_table(as.matrix(taxmat))
Expand All @@ -129,25 +129,25 @@ df$LibrarySize <- sample_sums(ps)
df <- df[order(df$LibrarySize), ]
df$Index <- seq_len(nrow(df))
ggplot(data = df, aes(x = Index, y = LibrarySize, color = control)) +
geom_point()
geom_point()
```

# plot 2

```{r plot prevalence}
contamdf_prev <- isContaminant(ps,
method = "prevalence",
neg = "control",
threshold = 0.5)
method = "prevalence",
neg = "control",
threshold = 0.5)
table(contamdf_prev$contaminant)
ps_pa <- transform_sample_counts(ps, function(abund) 1 * (abund > 0))
ps_pa_neg <- prune_samples(sample_data(ps_pa)$control == TRUE, ps_pa)
ps_pa_pos <- prune_samples(sample_data(ps_pa)$control == FALSE, ps_pa)
# Make data_frame of prevalence in positive and negative samples
df_pa <- data.frame(
pa_pos = taxa_sums(ps_pa_pos), pa_neg = taxa_sums(ps_pa_neg),
contaminant = contamdf_prev$contaminant
pa_pos = taxa_sums(ps_pa_pos), pa_neg = taxa_sums(ps_pa_neg),
contaminant = contamdf_prev$contaminant
)
ggplot(data = df_pa, aes(x = pa_neg, y = pa_pos, color = contaminant)) +
geom_point() +
Expand Down

0 comments on commit 1f99467

Please sign in to comment.