Using msa msaPrettyPrint(): saving multiple alignement fasta file
6
1
Entering edit mode
Olorin ▴ 50
@olorin-12230
Last seen 7.8 years ago

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?

msa msaprettyprint() fasta • 11k views
ADD COMMENT
2
Entering edit mode
UBod ▴ 300
@ubodenhofer-5425
Last seen 6 months ago
University of Applied Sciences Upper Au…

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).

ADD COMMENT
1
Entering edit mode
@james-w-macdonald-5106
Last seen 1 day ago
United States

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

ADD COMMENT
1
Entering edit mode
Olorin ▴ 50
@olorin-12230
Last seen 7.8 years ago
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_seq <- readAAStringSet(myFiles[i])
  current_align <- msa(current_seq)
  fasta_file = paste(outdir,'/',newdir,".aln",sep="")
  pdf_file = paste(outdir,"/" ,newdir,".pdf",sep="")
  msaPrettyPrint(current_align, output="pdf", showNames="none", askForOverwrite=FALSE, verbose=FALSE,
                  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

ADD COMMENT
1
Entering edit mode
Olorin ▴ 50
@olorin-12230
Last seen 7.8 years ago

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_seq <- readAAStringSet(myFiles[i])
  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)
}
ADD COMMENT
0
Entering edit mode
DigDeep • 0
@digdeep-12240
Last seen 7.8 years ago
Canada

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...

ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

Here:
 

library(msa)

system.file("tex", "texshade.sty", package="msa")

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

myFirstAlignment <- msa(mySequences)
myFirstAlignment

print(myFirstAlignment, show="complete")

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

Error in texi2dvi(texfile, quiet = !verbose, pdf = identical(output, "pdf"),  : 
  unable to run 'pdflatex' on 'myFirstAlignment.tex'
In addition: Warning message:
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_seq <- readAAStringSet(myFiles[i])
  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
ADD REPLY
1
Entering edit mode

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 <- readAAStringSet(mySequenceFile)
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.

ADD REPLY
0
Entering edit mode
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'
In addition: Warning message:
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?

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode
@tongtongwang1210-13157
Last seen 7.5 years ago
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")
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 532 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6