Skip to content
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

Add calc_prop_samples #233

Closed
zachary-foster opened this issue May 9, 2018 · 11 comments
Closed

Add calc_prop_samples #233

zachary-foster opened this issue May 9, 2018 · 11 comments

Comments

@zachary-foster
Copy link
Contributor

This would be like calc_n_samples except it would return the proportion of samples in each group with greater than some number of reads.

@zachary-foster
Copy link
Contributor Author

done

@olar785
Copy link

olar785 commented Jan 30, 2019

Hi Zachary,
I have been trying the calc_prop_samples function (which is very useful by the way) and there seems to be a problem with the labelling of groups returned. In my case I had 3 groups of samples (Nodule, Sediment, Water) and I realised that the values reported for Sediment and Water were inverted. Using the same input data I calculated the values myself for some specific taxa and could confirm that the values for Sediment and Water samples were inverted. I can send you my data if you need.
Thanks

@zachary-foster
Copy link
Contributor Author

Hi @olar785, thanks for the report. Did you use the cols options to specify the columns to use? Something like that might happen if you don't use the cols option and the numeric columns in the table are in a different order than the sample type given to the groups option. Perhaps I should add a warning about that. If you did use the cols option (and it was in the same order as the values given to the group option), then it sounds like a bug. If that is the case, can you send me you data and code? Thanks!

zachary-foster added a commit that referenced this issue Jan 30, 2019
@olar785
Copy link

olar785 commented Jan 30, 2019 via email

@zachary-foster
Copy link
Contributor Author

Ok, I will look into it. I don't see your attachment though. Perhaps you need to attach it on Github rather than via email? Thanks

@zachary-foster
Copy link
Contributor Author

You can also email it to me directly at "[email protected]" if you would rather it not be posted on github

zachary-foster added a commit that referenced this issue Jan 30, 2019
…tly in some data sets when the `groups` option was used.

relates to #233
@zachary-foster
Copy link
Contributor Author

zachary-foster commented Jan 30, 2019

Hi @olar785, it was a bug and I think it is fixed now. I did not notice it before because it only effects some datasets when the groups option is used and the bug did not affect my test data set. Try installing the development version and let me know if it works for you:

devtools::install_github("grunwaldlab/metacoder")
> taxmap_18S <- readRDS("~/Downloads/taxmap_18S.rds")
> 
> hand_res <- lapply(unique(taxmap_18S$data$sample_data$Sample_type), function(site) {
+   site_ids <- taxmap_18S$data$sample_data$sample_id[taxmap_18S$data$sample_data$Sample_type == site]
+   site_data <- taxmap_18S$data$tax_abund[site_ids]
+   hand_res <- apply(MARGIN = 1, site_data, function(x) sum(x > 0) / length(x))
+ })
> names(hand_res) <- unique(taxmap_18S$data$sample_data$Sample_type)
> hand_res <- tibble::as_tibble(hand_res)
> 
> res <- calc_prop_samples(taxmap_18S, "tax_abund", cols = taxmap_18S$data$sample_data$sample_id, groups = taxmap_18S$data$sample_data$Sample_type, other_cols= TRUE)
Calculating the proportion of samples with a value greater than 0 for 219 columns in 3 groups for 556 observations
Warning message:
The following columns will be replaced in the output:
   N-1, N-10, N-11, N-12, N-13, N-14, N-15, N-16, N-17, N-18, N-19, N-2 ... S-216, S-219, S-230, S-241, S-306, S-46, S-48, S-54, S-56, S-87, S-98
 
> 
> all(res[,-1] == hand_res)
[1] TRUE

Thanks again for the report!

@olar785
Copy link

olar785 commented Feb 1, 2019 via email

@zachary-foster
Copy link
Contributor Author

Sorry about that @olar785, I was working on the development branch when I made that bug fix to the master branch and did not rebuild the namespace after switching branches to commit the bug fix on master, so there were references in the namespace to functions that did not exist in master. It should be working now. At least it works for me now.

@olar785
Copy link

olar785 commented Feb 2, 2019

Works like a charm, thank you!

@zachary-foster
Copy link
Contributor Author

no problem!

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

No branches or pull requests

2 participants