dorianps / LINDA

Lesion Identification with Neighborhood Data Analysis
Apache License 2.0
20 stars 4 forks source link

How to run LINDA from command line? #20

Closed fgfmds closed 5 years ago

fgfmds commented 5 years ago

I noticed that there is an option in the script to run from the command line. If i try:

Rscript linda_predict.R /path/to/file/filename.nii

I get an error about an unexpected "/".

What am i doing wrong?

Thank you.

dorianps commented 5 years ago

Which version are you using? Until 0.2.7 the filename needs to go in the "t1" variable, which will be read by the script. In the current R package at v0.5.0 you can try something like LINDA::linda_predict(filename), or load the library first and then call the function.

I haven't tested the call from Rscript though, you need to find the right way to call it yourself. And btw, please share the correct command if you find it, so I can place it in the readme or wiki.

On Wed, Dec 5, 2018, 7:34 PM fgfmds <notifications@github.com wrote:

I noticed that there is an option in the script to run from the command line. If i try:

Rscript linda_predict.R /path/to/file/filename.nii

I get an error about an unexpected "/".

What am i doing wrong?

Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dorianps/LINDA/issues/20, or mute the thread https://github.com/notifications/unsubscribe-auth/AIqafewfdB-fWLOitrWoRQzhyqiq4D8Wks5u2GYYgaJpZM4ZFluz .

fgfmds commented 5 years ago

I have been experimenting with versions 0.2.6 and 0.2.7. I was able to run 0.2.6 from the command line successfully after making a few small modifications to the script.

Here are the changes I made:

  1. Comment out the following lines:

    parse arguments for command line use

    args=commandArgs(TRUE)

    for(i in 1:length(args)){

    eval(parse(text=args[i]))

    }

  2. Add the following line:

    !/usr/bin/env Rscript

    args = commandArgs(TRUE)

  3. Modify the argument length test section as follows:

    test if there is at least two arguments: if not, return an error

    if (length(args) < 2) { stop("At least two arguments must be supplied: path to T1 file and path to template", call.=FALSE) } else if (length(args)>=2) { t1 = args[1] scriptdir = args[2] }

Once the changes above are in place, I was able to run the script with the following command:

Rscript /path/to/script/0.2.6/linda_predict.R /path/to/T1/file/filename.nii /path/to/template/dir/

I hope people find this helpful, and thank you again for all your help.

dorianps commented 5 years ago

Thank you. Note that we also created a full package with v0.5.0 which would behave like any other R package. But if v0.2.6 is doing the job for you, that's fine, the output should be the same.

fgfmds commented 5 years ago

The truth is we started testing with LINDA when you were still at version 0.2.6. So we've invested some time and effort into getting things to work under that version. We will probably go to v0.5.0 at some point. Thanks again!