-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/lowdepth sample fix #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,11 +179,42 @@ vdb_make_phylo <- function(metadata, sampleid_col = "sampleid", skip_seqs = TRUE | |
|
|
||
|
|
||
|
|
||
| get_metaphlan_analyses <- function(con, analysis_ids, schema="public") { | ||
| raw_results <- get_subset_pg_df("mgx_metaphlan", "ia_id", analysis_ids, schema=schema) %>% | ||
| get_metaphlan_analyses <- function(con, analysis_ids, schema="public", include_failures=FALSE) { | ||
| raw_results <- get_subset_pg_df("mgx_metaphlan", "ia_id", analysis_ids, schema=schema) | ||
| # we have to deal with samples having no classified -- in those cases metaphlan reports | ||
| # estimated_number_of_reads_from_the_clade as 0, but to make it work with the rest of our code we modify that | ||
| # to nreads_input (eg all the input reads are from the unclassified clade) | ||
| mpa_failures <- raw_results %>% dplyr::filter(clade_name == "unclassified") %>% dplyr::pull(ia_id) | ||
| if (include_failures){ | ||
| if (sum(raw_results[raw_results$clade_name == "unclassified", "estimated_number_of_reads_from_the_clade"]) > 0){ | ||
| print(raw_results[raw_results$clade_name== "unclassified", "ia_id"]) | ||
| stop("some of the above analyses have metaphlan failures where estimated_number of reads from the clade is not zero as expected; please alert of the vdbR delevopers that the metaphlan output has changed") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Hopefully a good catch |
||
| } | ||
| raw_results <- raw_results %>% | ||
| dplyr::mutate(estimated_number_of_reads_from_the_clade = ifelse(clade_name == "unclassified", nreads_input, estimated_number_of_reads_from_the_clade)) %>% | ||
| dplyr::mutate(clade_name = ifelse(clade_name == "unclassified", "UNCLASSIFIED", clade_name)) | ||
| } else{ | ||
| if(length(mpa_failures) != 0) { | ||
| # get corresponding sampleids for informative error message | ||
| for (tbl in c("isabl_api_analysis_targets", "isabl_api_experiment", "isabl_api_sample")){ | ||
| if (!tbl %in% ls()) { | ||
| get_table_from_database(tbl) | ||
| } | ||
| } | ||
| problem_sample_analyses <- data.frame(analysis_id = mpa_failures) %>% | ||
| dplyr::left_join( isabl_api_analysis_targets, by="analysis_id") %>% | ||
| dplyr::left_join(isabl_api_experiment %>% dplyr::select(experiment_id = id, sample_id), by="experiment_id") %>% | ||
| dplyr::left_join(isabl_api_sample %>% dplyr::select(sample_id = id, identifier), by="sample_id") %>% | ||
| dplyr::select(analysis_id, identifier) | ||
| stop(paste("Metaphlan detected no taxa in the following sample's analyses; these samples must be removed from your metadata to create a phyloseq object:\n", paste0(capture.output(print(problem_sample_analyses)), collapse = "\n"))) | ||
| } | ||
| } | ||
| # TODO: parametarize this to get sgb level results | ||
| raw_results <- raw_results %>% | ||
| dplyr::filter(grepl("UNCLASSIFIED", clade_name) | grepl(".*\\|s__.*", clade_name)) %>% | ||
| dplyr::filter(!grepl(".*t__.*", clade_name)) %>% | ||
| dplyr::mutate(clade_name = ifelse(clade_name == "UNCLASSIFIED", "k__UNCLASSIFIED", clade_name)) | ||
|
|
||
| wide_results <- raw_results %>% | ||
| dplyr::select(ia_id, clade_name, relative_abundance) %>% | ||
| tidyr::pivot_wider(names_from = ia_id, values_from = relative_abundance, values_fill = 0) | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think this
include_failuresflag is a good way to give people the data for all the samples they sequenced if they really want it! 👍