Micropower with weighted unifrac

I'm trying to run Micropower using weighted unifrac distance matrices following the outline found here: https://gist.githubusercontent.com/brendankelly/6673e8596d3cde3fac7d493d7747aa80/raw/59ee6a6be3db8bd751817cdd7c31c7bd12d4d5f8/micropower_simulation_example.R

For the following command,

sd_wu_df <- data.frame(otu_number=round(as.numeric(gsub(".txt","",gsub("otu","",sapply(strsplit(names(sd_wu),"_"),FUN=function(x){x[[4]]})), fixed = TRUE))),sd=sapply(sd_wu, FUN=function(x){sd(as.dist(x))}))

I get this: Error in x[[4]] : subscript out of bounds

The script will only run if I sub 1 in for 4 as follows:

sd_wu_df <- data.frame(otu_number=round(as.numeric(gsub(".txt","",gsub("otu","",sapply(strsplit(names(sd_wu),"_"),FUN=function(x){x[[1]]})), fixed = TRUE))),sd=sapply(sd_wu, FUN=function(x){sd(as.dist(x))}))

But then I get this:
Warning message:
In data.frame(otu_number = round(as.numeric(gsub(".txt", "", gsub("otu", :
NAs introduced by coercion

That causes my table to have NA for otu_number, meaning I can't do the next steps in the script. Screen shot below. What is the problem with the script?

Screen Shot 2021-01-21 at 3.23.10 PM

Figured it out if anyone else runs into the same problem. Since my tables were output as .tsv files, I just had to switch .txt to .tsv. Still had to sub in [1] for [4]. Then it ran fine.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.