Question: Perform a function on several FASTA files R (Biostrings) Error in Call2(new_input_ExternalFilePtr", fp, PACKAGE = "Biostrings")
gravatar for kevin.debray
2.7 years ago by
kevin.debray0 wrote:

Hello everyone!

I need to perform a function on several fasta files located in the same folder. I first created a file object which lists the files names present in the Rtest folder.

files <- list.files(path="~/R/Rtest")

Then I put my script into a function called genWS. The first step of this function is to import the files one by one to perform a series of actions on them.

genWS <- function(input) {
x<-readDNAStringSet(file="input", format="fasta")

At the end of the script I put a FOR loop to go on the next fasta file.

for (j in 1:length(files)) {

My problem is that I got this error when I try to run the whole script despite it works fine when I import fasta file one by one manually.

Error in .Call2("new_input_ExternalFilePtr", fp, PACKAGE = "Biostrings") : 
  cannot open file 'input'
Called from: .Call2("new_input_ExternalFilePtr", fp, PACKAGE = "Biostrings")

Any idea of what happen and how to solve it ?


biostrings R fasta call2 • 1.1k views
ADD COMMENTlink modified 2.7 years ago by Martin Morgan ♦♦ 23k • written 2.7 years ago by kevin.debray0
Answer: Perform a function on several FASTA files R (Biostrings) Error in Call2(new_inpu
gravatar for Martin Morgan
2.7 years ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

Use readDNAStringSet(file=input, ...) i.e., the variable, rather than a character string "input".

Unrelated to your problem, but R knows how to iterate over vectors, so the loop can be written

for (file in files)

Usually 1:length(x) is the wrong thing to do -- it produces surprising results when length(x) equals 0 -- and a better practice would use seq_along()  or seq_len().

ADD COMMENTlink written 2.7 years ago by Martin Morgan ♦♦ 23k

Also FWIW note that you can load all your files at once by passing all their paths to readDNAStringSet() e.g. readDNAStringSet(files) where files is the character vector you obtained with list.files(path="~/R/Rtest"). So, depending on what you need to do with the sequences, and granted that you have enough memory to load them all, it might be that you don't need a loop at all.


ADD REPLYlink written 2.7 years ago by Hervé Pagès ♦♦ 14k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 139 users visited in the last hour