DReichLab / AdmixTools

Tools test whether admixture occurred and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how can I properly get installed admixr into R? error: qpDstat when D

carlosug opened this issue · comments

After I installed AdmixTools into Ubuntu, I followed this tutorial in R: https://bodkan.net/admixr/articles/tutorial.html

I couldn't successfully complete the installation since I got this warning error when I download the package:
install.packages("devtools") devtools::install_github("bodkan/admixr", ref = "v0.7.1", force = TRUE)

** testing if installed package can be loaded from final location
Warning in system("command -v qpDstat", ignore.stdout = TRUE) :
error in running command

If I forced the installation and modified $PATH, and admixr library is downloaded. I can run functions (i.e. eigenstrat(prefix), download_data). Nonetheless, when I try to make the D function, it recalled the non installed qpDstat and I can move ahead:

sh: 1: qpDstat: not found
Error in parsers[[cmd]](log_lines, ...) : attempt to apply non-function
In addition: Warning message:
In system(paste(cmd, "-p", par_file, ">", log_file)) :
error in running command

Can you kindly help me on this? How can I sort this issue out?

Many thanks in advance,
Carlos.

Dear Nick and Carlos,

I am a PhD student of Janet Kelso at the MPI in Leipzig and the developer of the admixr package.

I stumbled upon this issue by accident.

@carlosug Please don't hesitate to open this issue on the admixr issue tracker: https://github.com/bodkan/admixr/issues I will do my best to help as soon as I can.

In general, however, the error message sh: 1: qpDstat: not found strongly indicates the ADMIXTOOLS is not in the $PATH or, at the very least, that R doesn't see it there. I think testing if you see a path to ADMIXTOOLS binaries in the list obtained by running Sys.getenv("PATH") from R is a good start.

Nick, in case there are more admixr-related issues that people submit here, feel free to send them over to https://github.com/bodkan/admixr/issues

Best regards,

Martin

Hi Carlos,

Glad to see that I still managed to reach you even after a couple of weeks since you submitted this issue.

I'm having trouble figuring out what's going on just based on your description. Would you mind doing these couple of things step by step for me, reporting what you get?

  1. In your terminal (not R), run which qpDstat.

What I get on my computer is

 $ which qpDstat
/Users/martin_petr/local/bin/qpDstat

Which means that qpDstat is in the PATH and I can run it like so from the command line (as one normally does without the admixr package):

 $ qpDstat
Usage: qpDstat [options] <file>
   -h          ... Print this message and exit.
   -L <val>    ... use <val> as low value.
   -H <val>    ... use <val> as high value.
   -p <file>   ... use parameters from <file> .
   -v          ... print version and exit.
   -V          ... toggle verbose mode ON.

(Note that I'm on the latest version of Admixtools - your output might differ slightly).

  1. Open R and run library(admixr) - if I get what you're saying, you get the following warning?
> library(admixr)
ADMIXTOOLS binaries could not be found in your $PATH.
Consider modifying the $PATH variable in your .Renviron file
(you can run 'echo "PATH=$PATH" > .Renviron' in the shell).
  1. Still in R, run Sys.getenv("PATH"):
> Sys.getenv("PATH")
[1] "<...>:/Users/martin_petr/local/bin:<...>"

Note that I removed lot of irrelevant PATHs from the output - <...>. Most importantly, note that the PATH list includes the path do the qpDstat command I found in the step 1 above.

If I understand your problem correctly (and its cause), you should not see the qpDstat path in the output of Sys.getenv("PATH") at all.

Which leads to...

  1. Close the R terminal, open it again. Try setting the PATH from R manually based on the output of what you see in step 1. In my case, that would be Sys.setenv(PATH = "/Users/martin_petr/local/bin")

  2. Try running library(admixr) again in the same R session you ran 4. in. If everything works as it should, you should not get the warning again. We can then continue from this, figuring out why editing your .Renviron file as is recommended doesn't work.


I wonder if you even have the Admixtools libraries in the $PATH in the first place (i.e. step 1)? If not, even if you follow the library(admixr) warning, this won't do anything. But that's probably getting ahead of ourselves... and is easy to fix if that turns out to be so.

I got the same problem as @carlosug . All of the above comments help me a lot. But one problem remains unsolved. I post my details as follows:

I have installed admixtools using conda, the link is [https://bioconda.github.io/recipes/admixtools/README.html?highlight=admixtool]

It has been installed to the base environment of miniconda3, the structure of my files :

:~$ conda info --envs
# conda environments:
#
base                  *  /home/ningyu/miniconda3
QC                       /home/ningyu/miniconda3/envs/QC
altsplice                /home/ningyu/miniconda3/envs/altsplice
biotools                 /home/ningyu/miniconda3/envs/biotools
circosplot               /home/ningyu/miniconda3/envs/circosplot
genefamily               /home/ningyu/miniconda3/envs/genefamily
noref                    /home/ningyu/miniconda3/envs/noref
ref                      /home/ningyu/miniconda3/envs/ref

The path of my "pqDstat", and it seems to work well:

:~/miniconda3/bin$  /home/ningyu/miniconda3/bin/qpDstat -v
version: 900
no parameters
## qpDstat version: 900

I added the path to R using Rstudio. In the console window, I typed:
Sys.setenv(PATH = "/home/ningyu/miniconda3/bin")

Then I loaded admixr. NO warning messages

But when I loaded data and tried to run a test, some errors poped up:

trialresult <- d(snps_bol17,W=pops,X="pop10",Y="pop6",Z="pop4")
#Error in file(con, "r") : cannot open connection
#additionally: Warning message:
#In file(con, "r") :
#  cannot open file :'C:\Users\NY_CAF\AppData\Local\Temp\Rtmp2flybG/qpDstat__603316760.log': #No such file or directory

I am very sure that data has been prepared according to the tutorial by @bodkan. Except I change the path of data. The related codes are:

prefix <- c("C:/writedata/bol2017/admixtools/bol2017")
snps_bol17 <- eigenstrat(prefix)

Two files were found in the indicated path:
image

Hope to hear more about this issue. Great thanks to the authors of both packages for saving me from brain-burn searching and digging : )

Hi all,

Sorry for a late reply - I've been very busy with revisions to my paper with no time for development/support work.

@carlosug The fact that even step 1 fails indicates that the ADMIXTOOLS binaries are not actually in the $PATH variable of your system. I would love to help you out with the compilation and setup but unfortunately have currently no capacity to do that. :( I would advise to go to some Unix/Linux forum (https://unix.stackexchange.com/, Ubuntu forum, depending on what you use) and ask there, possibly linking to this discussion. You need someone to help you: 1) compile the software properly, 2) add it to your PATH variable. At the barest minimum, even running Sys.setenv(PATH = "/full/path/to/the/admixtools/binaries/directory") in an R session should get the admixr package working.

@ningyusino First of all, I don't personally use (ana)conda for maintaining R. I have very little experience with it (whenever I tried it it seemed to introduce more problems than it actually tries to solve) but it's great news you got it all working. I should probably give it another shot!

This, however, is the important bit:

cannot open file :'C:\Users\NY_CAF\AppData\Local\Temp\Rtmp2flybG/qpDstat__603316760.log'

This indicates that you're running Windows? I wasn't aware that ADMIXTOOLS is supported on Windows. Is Windows your main system? Is this where you're running qpDstat and others? I haven't used windows in 10 years and I have no idea what it can or cannot do know in terms of using unix utilities.

My guess would be that the command fails because of the last slash is forward (/), not backward (\) as is expected for Windows paths? Again, I have no way to verify this because I don't have an access to a Windows machine...

In principle, I can see if I find a quick and easy way to make the parsing of outputs OS-independent. Assuming this is where the issue really is.

One thing you could do is to check whether the file is really where it's supposed to be (C:\Users\NY_CAF\AppData\Local\Temp\Rtmp2flybG/qpDstat__603316760.log) after that command fails.

Let's continue the discussion here: bodkan/admixr#57 So that we're not cluttering Nick's ADMIXTOOLS-specific issue tracker. Thanks.

Martin