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

Error while making a pairwise list for alpha diversity compression #143

Closed
shashibisht9 opened this issue Jul 3, 2020 · 4 comments
Closed

Comments

@shashibisht9
Copy link

Hi,
While making shannon diversity comparison between two genotypes: wt (n=11) and test (n=10) I got this error.
bmi <- levels(ps1.meta$Genotype)
bmi.pairs <- combn(seq_along(bmi), 2, simplify = FALSE, FUN = function(i)bmi[i])

Error in combn(seq_along(bmi), 2, simplify = FALSE, FUN = function(i) bmi[i]) :
n < m
So I wonder if something is wrong, either in the data or in the commands.
Thanks for help!
Shashi

@microsud
Copy link
Member

microsud commented Jul 3, 2020

Thanks for writing to us. Does the command work with example data atlass1006 in the package? If it works with the package example data atlass1006 and not with your data then please provide a minimal-reproducible-example. It will help us better support you.

Best wishes,
Sudarshan

@shashibisht9
Copy link
Author

Thank you for reply.
Yes, this command does work with the example dataset. I have attached the example file. Let me know if anything else is needed.

Version info:
R version 4.0.2 (2020-06-22)
library(microbiome); packageVersion("microbiome")
[1] ‘1.11.0’

example_file.zip

@microsud
Copy link
Member

microsud commented Jul 4, 2020

Thanks for providing the example.
In the example provided by you, there are only two groups to compare and therefore the step (below) is not required!
bmi.pairs <- combn(seq_along(bmi), 2, simplify = FALSE, FUN = function(i)bmi[i])
Please check the Statistical tools for high-throughput data analysis webiste

Nevertheless, I explain the issue below for future reference.

library(microbiome)
ps <-  readRDS("pseq_object.rds")    
metadf <- meta(ps)    
head(metadf) # check metadata  
str(metadf) # check  how the variables are stored. The output is below  

###########   The output is like this
 'data.frame':   21 obs. of  4 variables:  
 $ Genotype   : chr  "awt/wt" "awt/wt" "awt/wt" "awt/wt" ...  
 $ Description: chr  "WT (Female 10)" "WT (Female 11)" "WT (Female 12)" "WT (Female 13)" ...   
 $ Age        : int  81 81 81 68 68 116 116 81 79 79 ...   
 $ Sex        : chr  "Female" "Female" "Female" "Female" ...   
###########   

It seems the column of interest has information stored as a character.
This link will provide some information on the use of characters and factors in R.

This can be addressed in two ways.
First option: Use unique()


bmi <- unique(metadf$Genotype)
print(bmi)

Second option: convert charactor to factor

metadf$Genotype.fact <- as.factor(metadf$Genotype)

str(metadf)
################The output is like this
 'data.frame':   21 obs. of  5 variables:
 $ Genotype     : chr  "awt/wt" "awt/wt" "awt/wt" "awt/wt" ...
 $ Description  : chr  "WT (Female 10)" "WT (Female 11)" "WT (Female 12)" "WT (Female 13)" ...
 $ Age          : int  81 81 81 68 68 116 116 81 79 79 ...
 $ Sex          : chr  "Female" "Female" "Female" "Female" ...
 $ Genotype.fact: Factor w/ 2 levels "awt/wt","S839I/S839I": 1 1 1 1 1 1 1 1 2 2 ...
#############################

check Genotype.fact is a Factor while Genotype is chr i.e. charactor.

bmi <- levels(metadf$Genotype.fact)
print(bmi) 
bmi.pairs <- combn(seq_along(bmi), 2, simplify = FALSE, FUN = function(i)bmi[i])
print(bmi.pairs)  # this will print all pair-wise comparision that will be tested in subsequent codes

If this solves your issue, please make sure to close it.
All the best with your analysis!

@shashibisht9
Copy link
Author

This solved the problem. Thank you!

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