Search
Question: Using msa msaPrettyPrint(): saving multiple alignement fasta file
1
17 months ago by
Olorin50
Olorin50 wrote:

Hello.

I know when I use msaPrettyPrint() function, this write the aligned sequences in fasta file ;

C:/Users/SEBASTIEN/AppData/Local/Temp/RtmpMTD00Y/seq21e072f6414e.fasta

Is there a way to change the ouput directory?

modified 13 months ago by tongtong.wang12100 • written 17 months ago by Olorin50
2
17 months ago by
UBodenhofer250
Johannes Kepler University, Linz, Austria
UBodenhofer250 wrote:

Thanks for all the contributions in this thread! The problem is that TeX cannot handle spaces and some special characters in paths, especially on Windows. That may lead to problems with temporary files, but also if the path to the current working directory has some "illegal" characters in it. In case such a problem occurs, use a different working directory the path to which does not have any spaces or other illegal characters. In case this occurs with temporary files, use the 'file' argument to redirect the temporary files. I think this sums up all the previous suggestions. By the way, this is also mentioned in Section 7.8 of the package vignette (page 33 in the current version).

1
17 months ago by
United States
James W. MacDonald46k wrote:

Have you looked at the help page for the function you are using? In particular the 'file' argument?

1
17 months ago by
Olorin50
Olorin50 wrote:
I'm trying this

# #
bdir = "E:/DOCTORAT/workspace/alignement_prot_ribo_all"
workdir = file.path(bdir,"one_file_per_ptne/")
outdir = file.path(bdir,"alignements")

myFiles = list.files(path = workdir,full.names = TRUE)
for (i in 1:66){
newdir = substr(basename(myFiles[i]), start = 1 ,stop = 6)
output = file.path(outdir, newdir)
dir.create(output,showWarnings = FALSE)
current_align <- msa(current_seq)
fasta_file = paste(outdir,'/',newdir,".aln",sep="")
pdf_file = paste(outdir,"/" ,newdir,".pdf",sep="")
file = output, alFile = fasta_file)
}

But there are errors on alFile and file:

Error in msaPrettyPrint(current_align, output = "pdf", showNames = "none",  :
The parameter alFile has an invalid argument

If i remove alFile:

Error in msaPrettyPrint(current_align, output = "pdf", showNames = "none",  :
The file name suffix and output type do not match!

___________________________________________________________________________________________________

EDIT: Solution for specifying output files names

It's working now, we have to specify both .pdf and .fasta in file name

  fasta_file = paste(outdir,'/',newdir,".fasta",sep="")
pdf_file = paste(output,"/",newdir,".pdf",sep="")
print(pdf_file)
msaPrettyPrint(current_align, output="pdf", showConsensus = "none", askForOverwrite=FALSE, verbose=FALSE,
file = pdf_file, alFile = fasta_file )
}

But my loop is broken with an error:

 Error in texi2dvi(texfile, quiet = !verbose, pdf = identical(output, "pdf"),  :
unable to run 'pdflatex' on 'E:/DOCTORAT/workspace/alignement_prot_ribo_all/alignements/L1_all.tex' In addition: Warning message:
running command '"pdflatex" -interaction=nonstopmode "E:/DOCTORAT/workspace/alignement_prot_ribo_all/alignements/L1_all.tex"' had status 1 

If i open tex file with texmaker, the compliation is working... So i don't know whats going wrong

1
17 months ago by
Olorin50
Olorin50 wrote:

PROBLEM SOLVED:

I have resolved my problems.

1. Save tex file with msaPrettyPrint()

2. Construct pdf with texi2pdf()

bdir = "E:/DOCTORAT/workspace/alignement_prot_ribo_all"
workdir = file.path(bdir,"one_file_per_ptne/")
outdir = file.path(bdir,"alignements")

myFiles = list.files(path = workdir,full.names = TRUE)
for (i in 1:66){
newdir = substr(basename(myFiles[i]), start = 1 ,stop = 6)
output = file.path(outdir, newdir)
dir.create(output,showWarnings = FALSE)
current_align <- msa(current_seq)
fasta_file = paste(outdir,'/',newdir,".fasta",sep="")
tex_file = paste(outdir,"/",newdir,".tex",sep="")
print(pdf_file)
msaPrettyPrint(current_align, output="tex", showConsensus = "none", askForOverwrite=FALSE, verbose=FALSE,
file = tex_file, alFile = fasta_file )
texi2pdf(tex_file, clean=TRUE)
}
0
17 months ago by
DigDeep0
DigDeep0 wrote:

Hi all,

I have tried the solution, but I receive the following error:

Error in .normarg_input_filepath(filepath) :   'filepath' must be a character vector with no NAs

Unsure of where to go from here...

1

Can you please provide more information about the exact context in which this error message occurs? Otherwise it is really hard to analyze the situation. If possible, provide a complete minimum working example in which this error occurs in a reproducible way.

Indeed, I am using the generic example provided in the msa manual

Here:

library(msa)

mySequenceFile <- system.file("examples", "exampleAA.fasta", package="msa")
mySequences

myFirstAlignment <- msa(mySequences)
myFirstAlignment

print(myFirstAlignment, show="complete")

msaPrettyPrint(myFirstAlignment, output="pdf", showNames="none",

Error in texi2dvi(texfile, quiet = !verbose, pdf = identical(output, "pdf"),  :
unable to run 'pdflatex' on 'myFirstAlignment.tex'
running command '"pdflatex" -interaction=nonstopmode "myFirstAlignment.tex"' had status 1



At this point in time I follow the solution provided in this forum...

bdir = "Home_space"
workdir = file.path(bdir,"one_file_per_ptne/")
outdir = file.path(bdir,"alignements")

myFiles = list.files(path = workdir,full.names = TRUE)
for (i in 1:66){
newdir = substr(basename(myFiles[i]), start = 1 ,stop = 6)
output = file.path(outdir, newdir)
dir.create(output,showWarnings = FALSE)
current_align <- msa(current_seq)
fasta_file = paste(outdir,'/',newdir,".fasta",sep="")
tex_file = paste(outdir,"/",newdir,".tex",sep="")
print(pdf_file)
msaPrettyPrint(current_align, output="tex", showConsensus = "none", askForOverwrite=FALSE, verbose=FALSE,
file = tex_file, alFile = fasta_file )
texi2pdf(tex_file, clean=TRUE)
}

But I get this error:

Error in .normarg_input_filepath(filepath) :
'filepath' must be a character vector with no NAs
1

The new error message is clear: you do not even have the data and files that are needed to run your code, e.g. the file name vector 'myFiles'. So, you cannot use the solution as it is, but only the general idea of it. And the general idea is to use the 'alFile' argument to avoid possible issues with the name and/or location of the temporary FASTA file to which the alignment is written. Please try the following:

library(msa)

mySequenceFile <- system.file("examples", "exampleAA.fasta", package="msa")
mySequences

myFirstAlignment <- msa(mySequences)
myFirstAlignment

msaPrettyPrint(myFirstAlignment, alFile="./myFile.fasta", output="pdf", showNames="none",
showLogo="none", askForOverwrite=FALSE, verbose=FALSE)

If it works, fine. If not, there might also be an issue with your LaTeX installation. (do you have it at all on your system?) In case the problem persists and you post another error report, please enclose the output of 'sessionInfo()' and also check first whether TeX/LaTeX is installed.

If i run your code including the alFile="./myFile.fasta". Yes,my current working directory have the fasta file. But if the output="pdf",there is error:
Error in texi2dvi(texfile, quiet = !verbose, pdf = identical(output, "pdf"),  :
unable to run 'pdflatex' on 'myFirstAlignment.tex'
running command '"pdflatex" -interaction=nonstopmode "myFirstAlignment.tex"' had status 1 .

If i use the output="tex",and then run it with Latax. the pdf file appeared correctly. I don't know why?

I can only speculate. Maybe try the following: run msaPrettyPrint() with 'output="tex"' and then run texi2pdf() (from the 'tools' package) on that file. That's basically what msaPrettyPrint() does too. If that does not work, then I'll have to look into my package's code. If it does not work either, there might be a problem with the way your R installation "cooperates" with TeX/LaTeX. By the way, does the working directory's path have any spaces or special characters in it?

Hi there. Please excuse that I don't know how to format my code in this forum properly. I am a first time user, and I just signed up to chime in and let you know I have the same problem. I just installed Bioconductor today specifically to look at the msa package. I have now tried the introductory code in both R-Studio (R version 3.4.3) and in the basic R GUI (same version). Neither works. The following code is what I used:

library(msa)

mySequenceFile <- system.file("examples", "exampleAA.fasta", package="msa")

mySequences <- readAAStringSet(mySequenceFile)

myFirstAlignment<-msa(mySequences)

msaPrettyPrint(myFirstAlignment, output="tex", showNames="none",showLogo="none", askForOverwrite=FALSE,verbose=FALSE)

texi2pdf('myFirstAlignment.tex',clean=TRUE)

The working directory is my desktop, so I have also tried "~/Desktop/myFirstAlignment.tex". I have also tried using texi2dvi with pdf set to true. In every case it gives the following error:

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  :
Running 'texi2dvi' on '~/Desktop/myFirstAlignment.tex' failed.

Thanks.

Since you cannot run texi2dvi() itself, the problem is not within the 'msa' package. You either have no TeX/LaTeX system installed or it is improperly installed (e.g. the execution paths are not correctly set). I suggest you open a shell/command prompt window, change to the directory  '~/Desktop/' and run the command 'pdflatex myFirstAlignment'. What happens?

0
13 months ago by
tongtong.wang12100 wrote:
Could you please specify what are these three parameters stand for?
what should be included in bdir, workdir and outdir?

bdir = "E:/DOCTORAT/workspace/alignement_prot_ribo_all"
workdir = file.path(bdir,"one_file_per_ptne/")
outdir = file.path(bdir,"alignements")
These are not directly related to msaPrettyPrint() or any other 'msa' functionality. Olorin used them for his example posted above. He reads FASTA files from 'workdir' and writes the output of msaPrettyPrint() to 'outdir'. 'bdir' is just the base directory, of which 'workdir' and 'outdir' are sub-directories.