dorianps / LINDA

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

Creating project wrapper for LINDA (v0.5.0) and efficiently using built-in cache option #24

Closed labhstats closed 4 years ago

labhstats commented 4 years ago

Dear Dorian,

I am currently building a code wrapper for LINDA (v0.5.0) for a project and I encountered an "issue" when using the "cache = TRUE" option in "linda_predict".

The idea behind the wrapper is that I have multiple stroke cases arranged in BIDS format which I want to run (and re-run parts if something went wrong) continuously without stopping. The problem is that when the "cache = TRUE" option it will stop the whole sequence of code if the segmentation of one case is already finished, which is not ideal for a project wrapper.

The error message returned by R states that it "could not find object L", which I figured was related to the last "return(L)" statement in "linda_predict". This is what I suspect is the core issue. Because after I commented it out in my own "linda_predict_custom", sourced from the package::function LINDA::linda_predict, it then ran for a while until additional errors occurred.

I dont know the extent of work required to compile and change R packages, I will therefore also include a possible workaround. It is a workaround that I have tested to work.

I worked on a possible workaround with a custom "linda_predict" function outside of the LINDA package, but that has proven to be a less than ideal approach. Although by only commenting out "return(L)" at the end of the function, additional (new) errors followed, such as:

These issues were simple enough to correct, although not elegantly, to make "linda_predict_custom" work:

I hope this ratched implementation can be helpful to others that also want to build a wrapper for LINDA for whatever reason.

Do note: As "linda_predict" writes directly to the system I did not personally have need for the output returned by the function. This is and important element for this workaround to be worth trying.

dorianps commented 4 years ago

Hi Lars, I will need to look better into this by next week. From your description looks the error comes when a complete Linda folder exists for the subject, but works in all other cases. If that is the case, I can try to reproduce the error and check the best workaround. But let me know if my understanding is correct at the mean time.

Dorian

On Fri, Aug 30, 2019, 3:19 PM Lars notifications@github.com wrote:

Dear Dorian,

I am currently building a code wrapper for LINDA (v0.5.0) for a project and I encountered an "issue" when using the "cache = TRUE" option in "linda_predict".

The idea behind the wrapper is that I have multiple stroke cases arranged in BIDS format which I want to run (and re-run parts if something went wrong) continuously without stopping. The problem is that when the "cache = TRUE" option it will stop the whole sequence of code if the segmentation of one case is already finished, which is not ideal for a project wrapper.

The error message returned by R states that it "could not find object L", which I figured was related to the last "return(L)" statement in "linda_predict". This is what I suspect is the core issue. Because after I commented it out in my own "linda_predict_custom", sourced from the package::function LINDA::linda_predict, it then ran for a while until additional errors occurred.

I dont know the extent of work required to compile and change R packages, I will therefore also include a possible workaround. It is a workaround that I have tested to work.

I worked on a possible workaround with a custom "linda_predict" function outside of the LINDA package, but that has proven to be a less than ideal approach. Although by only commenting out "return(L)" at the end of the function, additional (new) errors followed, such as:

  • Not finding the "print_msg" function. Which I only found in "dorianps/LINDA/R/aaa_utils.R",
  • And not finding functions found in ANTsRCore, and possibly also in ANTsR and ITKR too.

These issues were simple enough to correct, although not elegantly, to make "linda_predict_custom" work:

  • Copy-pasting the "print_msg" function into Rstudio environment (or in the same file as the R script which is sourced together with "linda_predict_custom").
  • Explicitly requiring and loading the libraries ANTsRCore alongside ANTsR and ITKR before running "linda_predict_custom".

I hope this ratched implementation can be helpful to others that also want to build a wrapper for LINDA for whatever reason.

Do note: As "linda_predict" writes directly to the system I did not personally have need for the output returned by the function. This is and important element for this workaround to be worth trying.

— 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/24?email_source=notifications&email_token=ACFJU7J55RIS26ZXFFHCG3TQHEM4XA5CNFSM4ISNHZ22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIOLHVA, or mute the thread https://github.com/notifications/unsubscribe-auth/ACFJU7MJHFZKZ2CN4ORTPIDQHEM4XANCNFSM4ISNHZ2Q .

labhstats commented 4 years ago

Yes, the I believe the error comes from that case.

To explain better, although it seems you understand: Assume that we have 3 T1w images, each of different individuals and the 2nd one is already completed for some reason. Then "linda_predict" will, as is, do the following in a for-loop: [Edit: Assuming cache = TRUE]

Iteration 1. ID#1 (Not completed) - Runs fine. Iteration 2. ID#2 (Completed) - Code stops. [Error: Could not find object "L"]. Iteration 3. ID#3 (Not completed) - Won't be run, due to the error in earlier iteration.

Lars

dorianps commented 4 years ago

Lars, I pushed some changes in and bumped the version to v0.5.1. You can install this and check if it works for you. The errors don't appear any more, and in addition you should get the regular output of LINDA runs, that is, the list of files produced by linda, even if the run existed from before. Let me know if this resolves the problem the way you need it.

Dorian

dorianps commented 4 years ago

Assuming resolved.