Search
Question: Using msa msaPrettyPrint(): saving multiple alignement fasta file
1
gravatar for Olorin
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?

ADD COMMENTlink modified 13 months ago by tongtong.wang12100 • written 17 months ago by Olorin50
2
gravatar for UBodenhofer
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).

ADD COMMENTlink written 17 months ago by UBodenhofer250
1
gravatar for James W. MacDonald
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?

ADD COMMENTlink written 17 months ago by James W. MacDonald46k
1
gravatar for Olorin
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_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 COMMENTlink modified 17 months ago • written 17 months ago by Olorin50
1
gravatar for Olorin
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_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 COMMENTlink written 17 months ago by Olorin50
0
gravatar for DigDeep
17 months ago by
DigDeep0
Canada
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...

ADD COMMENTlink written 17 months ago by DigDeep0
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.

ADD REPLYlink written 17 months ago by UBodenhofer250

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 REPLYlink written 17 months ago by DigDeep0
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 <- 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 REPLYlink modified 17 months ago • written 17 months ago by UBodenhofer250
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 REPLYlink modified 5 months ago • written 5 months ago by luokaikmt0

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 REPLYlink written 5 months ago by UBodenhofer250

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 REPLYlink modified 11 weeks ago • written 11 weeks ago by davidceichhorn0

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 REPLYlink written 11 weeks ago by UBodenhofer250
0
gravatar for tongtong.wang1210
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")
ADD COMMENTlink written 13 months ago by tongtong.wang12100

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 REPLYlink written 13 months ago by UBodenhofer250
Please log in to add an answer.

Help
Access

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