Closed LIEHUZUO123 closed 2 years ago
Dear Vivid,
if you want to subset (or want to assign values to) a list you have to use double square brackets and not a single square bracket as you would do for vector and matrices e.g. marker[[i]]
instead of marker[i]
. You need to do this for all your list objects like marker, tree, result
.
Kind regards,
Klaus
Dear package phangorn developers,
I find the function modelTest is pretty efficient, thanks! I tried to write a R script to make it works for a batch of files. I put 215 aligned fasta files each contain multiple sequences in the target folder and tested the following cods:
library(ape) library(seqinr) library(phangorn)
setwd("F:\ R test\RAD-marker_215")
list filenames in the target directory
filenames <- list.files(path=" F:\ R test\RAD-marker_215", pattern=".fasta", full.names=T)
marker=lapply(filenames, read.fasta)
create an empty data frame as container for the results
result_frame=data.frame(row.names=filenames, Model=rep(NA, length(filenames)), BIC=rep(NA, length(filenames))) result_frame
for (i in 1:length(filenames)) { marker[i]= as.phyDat(marker[i]) tree[i]= NJ(dist.ml(marker[i])) result[i]= modelTest(marker[i], tree[i], model = c("JC", "F81", "HKY", "GTR", "SYM")) min_Model= result[which(result$BIC==min(result$BIC)), 'Model'] min_BIC= result[which(result$BIC==min(result$BIC))] result_frame[i,1]= min_Model result_frame[i,2]= min_BIC }
result_frame
However, when I run the codes, the error message says: “Error in UseMethod("as.phyDat") : "as.phyDat" is not suitable for "list"object”.
Then I see marker=lapply(filenames, read.fasta) create a big list. How can I solve this problem? I have thousands of markers to test for substitution models and I definitely do not want to calculate them one by one.
Thank you for your considerations!
Best regards,
Vivid