Skip to content

miaSimShiny link added#57

Merged
antagomir merged 35 commits intomainfrom
devel
Dec 28, 2022
Merged

miaSimShiny link added#57
antagomir merged 35 commits intomainfrom
devel

Conversation

@YagmurSimsekk
Copy link
Member

No description provided.

@antagomir
Copy link
Member

Checks still failing, @YagmurSimsekk

@antagomir
Copy link
Member

The error says "unable to find version master" -> does the GHA still refer to master branch? Should be easy to fix in .github/workflows yml files?

Copy link
Member

@antagomir antagomir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good initial material.

It seems that in many places the already existing functionality from mia & miaViz can be used, avoiding reinventing the wheel and replacing those with less thoroughly tested code.

I suggest @YagmurSimsekk and @TuomasBorman could have a look at this as part of their miaSim contributions when his schedule will allow.

Comment on lines 286 to 331
# makePlot(simulation_GLV[[scenario]][[row]][[local_community]]$matrix)
dfs_to_bind[[scenario]] <- append(dfs_to_bind[[scenario]], list(simulation_GLV[[scenario]][[row]][[local_community]]$matrix[time = 1000, ]))
}

### form otu tables ####
otu_table[[scenario]][[row]] <- bind_rows(dfs_to_bind[[scenario]])
otu_table[[scenario]][[row]] <- subset(otu_table[[scenario]][[row]], select = -time)
otu_table[[scenario]][[row]][is.na(otu_table[[scenario]][[row]])] <- 0

### calculate jensen-shannon distance and plot PCoA ####
jsd[[scenario]][[row]] <- JSD(as.matrix(otu_table[[scenario]][[row]]))
PCoA[[scenario]][[row]] <- ape::pcoa(as.dist(jsd[[scenario]][[row]]))
PCoA_coord[[scenario]][[row]] <- PCoA[[scenario]][[row]]$vectors[, 1:2]
colnames(PCoA_coord[[scenario]][[row]]) <- c("PCo1", "PCo2")

bestk[[scenario]][[row]] <- 2
PAM[[scenario]][[row]] <- pam(PCoA[[scenario]][[row]]$vectors, k = 2)
SI[[scenario]][[row]] <- PAM[[scenario]][[row]]$silinfo$avg.width

for (k in 3:10) {
PAMtemp <- pam(PCoA[[scenario]][[row]]$vectors, k = k)
if (PAMtemp$silinfo$avg.width > SI[[scenario]][[row]]) {
SI[[scenario]][[row]] <- PAMtemp$silinfo$avg.width
bestk[[scenario]][[row]] <- k
PAM[[scenario]][[row]] <- PAMtemp
}
}

groups[[scenario]][[row]] <- factor(PAM[[scenario]][[row]]$clustering)

dataframe_pcoa <- as.data.frame(PCoA_coord[[scenario]][[row]])
dataframe_pcoa$group <- groups[[scenario]][[row]]
pcoa_plot[[scenario]][[row]] <- ggplot(
dataframe_pcoa,
aes(x = PCo1, y = PCo2, color = group)
) +
ggtitle(paste("scenario", scenario, scenarios[scenario], ";", "alpha =", params$alpha[[row]])) +
geom_point() +
# coord_fixed(xlim = c(-1, 1), ylim = c(-1, 1)) +
theme_bw() +
scale_color_manual(values = customPalette) +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5))
print(pcoa_plot[[scenario]][[row]])
}

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part could be using more extensively the readily available functionality from mia, miaTime, miaViz.

That could simpilify the implementation considerably.

@TuomasBorman could you have a look as part of contribution to miaSim manuscript? I can recheck afterwards if there are further suggestions.

Comment on lines 339 to 347
for (row in seq_len(nrow(params))) {
pcoa_plot_sis[[row]] <- ggplot(as.data.frame(PCoA_coord[[1]][[row]]), aes(x = PCo1, y = PCo2)) +
geom_point(aes(color = group_sis[[row]])) +
ggtitle(paste("alpha =", params$alpha[[row]])) +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
print(pcoa_plot_sis[[row]])

# ggsave(paste0("pcoa_validation_", params$alpha[row], ".pdf"), plot = pcoa_plot_sis[[row]], dpi = 300, width = 6, height = 6, units = "cm")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, could we just use plotReducedDim functions?

@@ -0,0 +1,443 @@
---
title: "caseStudy2-NutrientThreshold"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that the Rmd files should be in folder vignettes/articles/ in order to be shown on the pkg homepage. Not sure. To check.

Comment on lines 3 to 15
author:
- name: Yu Gao
email: gaoyu19920914@gmail.com
- name: Daniel Rios Garza
email: danielrios.garza@kuleuven.be
- name: Karoline Faust
email: karoline.faust@kuleuven.be
- name: Yagmur Simsek
email: yagmur.simsek@hsrw.org
- name: Emma Gheysen
email: emma.gheysen@student.kuleuven.be
- name: Leo Lahti
email: leo.lahti@iki.fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: author list - how about just citing the miaSim package landing page which has up-to-date author list? This would help to avoid replicating the same info in multiple places. Just a suggestion.

Comment on lines +104 to +128
gradient.df.generator <- function(n_row, n_col, density_row, max_gradient, error_interval){
list_initial <- list()
dissimilarity.gradient <- seq(from = 0, to = max_gradient, length.out = n_row)
for (i in seq_len(n_row)){
print(i)
if (i == 1){
row_temp <- rbeta(n_col, 1, 1/n_col)
col_to_remove <- sample(x = seq_len(n_col), size = n_col-n_col*density_row)
row_temp[col_to_remove] <- 0
list_initial[[i]] <- row_temp
} else {
while (length(list_initial) < i) {
row_temp <- rbeta(n_col, 1, 1/n_col)
col_to_remove <- sample(x = seq_len(n_col), size = n_col-n_col*density_row)
row_temp[col_to_remove] <- 0
diff_temp <- abs(vegdist(rbind(list_initial[[1]], row_temp), method = "bray") - dissimilarity.gradient[i])
if (diff_temp < error_interval) {
list_initial[[i]] <- row_temp
}
}
}
}
dataframe_to_return <- as.data.frame(t(matrix(unlist(list_initial), ncol = n_row)))
return(dataframe_to_return)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first impression is that it might be possible to simplify this considerably but I am not sure?


```

## make umap plots
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, use miaViz and related

n_rep <- 50
```

## initial the output dataframes to store data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> initial -> initialize


## generating function

this function generates a data frame, where each row is arranged in an increasing dissimilarity to the first row.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is shared with another vignette page; would it make sense to just add this in miaSim package in order to simplify the vignette example? This part is taking now perhaps catching attention from other more central aspects?

t_end = 1000,
t_step = 1,
t_store = 1000)
CRMspecies <- getCommunity(CRMtest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCommunity should be replaces with mia functionality

Comment on lines 232 to 240
p_fig2_result_df <- ggplot(result_df, aes(x = n_resources, y = value, group = n_resources)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(alpha = 0.2, width = 0.2) +
facet_grid(. ~ factor(n_species, levels = n_species_types)) +
theme_bw() +
scale_x_continuous(trans = "log2", breaks = n_resources_types) +
xlab("number of resources") +
ylab("growth yield (number of individuals)")
p_fig2_result_df
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use miaViz here?

@antagomir
Copy link
Member

miaSimShiny link was added to README.md
I moved it to README.Rmd (I push soon)
the README.md is generated (and hence rewritten) based on Rmd file..

@antagomir
Copy link
Member

Ok this failed the checks so I went to see in more detail.

Changes:

  • Vignette used packages that were not mentioned in DESCRIPTION Suggests: field; added there now
  • Vignette examples are prohibitively slow for automated build checks; I reduced the number of combinations to go through in for loops drastically for demo purposes to speed up.
  • Some other more minor polishing

Additional updates will be neeeded but easier to do after this PR is merged.

Later PRs should be more compact in size so that the process stays more manageable.

@antagomir
Copy link
Member

Ok - I had to skip vignette fixes for now to get this through. Much of the fixes would require the new features that are only available after the merge. Let's take note on the PR comments later.

@antagomir antagomir merged commit da30d9e into main Dec 28, 2022
@YagmurSimsekk YagmurSimsekk deleted the devel branch December 30, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants