Entering edit mode
7.4 years ago
amboyd63391
•
0
Hi. I am receiving the following error [Error in writeXStringSet(df, paste(mylist, ".fasta", sep = "")) : 'x' must be an XStringSet object] when I incorporate lines into a function that is called on multiple lists. I did not receive the error when testing the lines on lists individually prior to incorporating into a function.
#Load libraries
warnings()
libraries <- c("Biostrings", "GenomicRanges", "GenomicRanges", "rtracklayer", "systemPipeR", "seqLogo", "ShortRead")
require(libraries)
lapply(libraries, require, character.only = TRUE)
#Load fasta file
Dovetail <- readDNAStringSet("Dovetail_BNG5.fasta")
PacBio <- readDNAStringSet("NGS_BNG5.fasta")
#List of suspected repeats
Dovetail1165 <- c("scaff786","scaff512","scaff8")
Dovetail1517 <- c("scaff596","scaff836","scaff74","scaff797|chimeric1|chimeric1")
Dovetail1296 <- c("scaff785","scaff282")
Dovetail1129 <- c("scaff178")
PacBio1517 <- c("000669F 000197762:B~000464852:B~000464852:B~000120316:E ctg_linear 43041 89420|quiver","000675F 000527442:E~000002404:E~000226606:B~000226606:B ctg_linear 42511 120197|quiver","000112F 000084279:E~000240622:B~000067280:E~000538070:B ctg_linear 486748 2352344|quiver|chimeric2")
PacBio1094 <- c("000524F 000490584:B~000507987:E~000374947:B~000305785:E ctg_linear 69032 174633|quiver","000797F 000153655:B~000214382:B~000191639:B~000197863:E ctg_linear 31178 85564|quiver","000616F 000335276:E~000451200:B~000451200:B~000009618:B ctg_linear 50929 185604|quiver","000723F 000515164:E~000292821:E~000108362:B~000335276:B ctg_linear 36742 80248|quiver","000590F 000324237:E~000324237:E~000239559:E~000191639:B ctg_linear 55730 156389|quiver")
PacBio1165 <- c("000052F 000490894:B~000016930:B~000204225:E~000311543:E ctg_linear 847874 3706218|quiver","000567F 000156153:E~000498244:E~000519059:E~000519059:E ctg_linear 61461 116946|quiver","000681F 000315928:E~000315928:E~000464822:B~000315928:E ctg_linear 41586 41976|quiver")
#function to generate output fastas of suspected repeats mapping to same anchor
RepeatsFasta <- function(mylist,myfasta) {
for (entry in mylist) {
myi=1
for (name in names(myfasta)) {
if(entry %in% ROWNAMES(myfasta)[myi]) {
df <- DNAStringSet(df, myfasta[myi])
}
myi=myi+1
}
}
#df <- unique(df)
writeXStringSet(df, paste(mylist, ".fasta", sep = ""))
#df <- ()
}
#function to iteratively call
MyCaller <-function(mymaps) {
for (anchors in mymaps) {
fastatype=gsub('[[:digit:]]+',"",anchors)
RepeatsFasta(anchors,fastatype)
}
}
#Maplist
myargs <- c("Dovetail1165","Dovetail1517","Dovetail1296","Dovetail1129","PacBio1517","PacBio1094","PacBio1165")
MyCaller(myargs)
Have you looked at ?DNAStringSet constructor help page? DNAStringSet() expects a character vector of strings or a Xstring object as a first argument, where you have 'df', a variable which does not appear to be initialized before first use. If you are seeking to generate .fasta files for a subset of named sequences (your suspected repeats) you could do so by directly indexing into your DNAStringSet with the names of the sequences you wish to extract, perhaps something like:
writeXStringSet(Dovetail[Dovetail1165], ...)