PatientLevelPrediction icon indicating copy to clipboard operation
PatientLevelPrediction copied to clipboard

loadPlpAnalysesJson creates empty list on predictionAnalysisList$analyses

Open andtsouch opened this issue 2 years ago • 5 comments

Hi, I am having an issue with the predictionAnalysisList.json, where from what I see the loadPlpAnalysesJson function is creating an empty list json$analyses, which is then out of bounds for the required indexing that is taking place when executing the study.

I am using PLPv5.0.5 and I have hydrated the study package using Hydra v0.3.0. The initial json I use to hydrate the package is copied from ATLAS version 2.8.1.

I am wondering if there is a compatibility issue with the predictionAnalysisList.json file created by that Hydra version issue

andtsouch avatar Jul 25 '22 12:07 andtsouch

Hi Andi,

Pairing the correct PLP with the correct skeleton is difficult. Luckily, thanks to Martijn insisting we use renv, the latest skeletons should have renv files that let you install the R package versions that work with the json specification (see https://github.com/OHDSI/SkeletonPredictionStudy there is a file renv.lock) and there is also code in the Extras folder to create the analysis json outside of ATLAS (as ATLAS uses a really old json spec - so I recommend using the R code to create it instead): see https://github.com/OHDSI/SkeletonPredictionStudy/blob/main/extras/createDevelopmentPackageExample.R with example code using the latest package.

This file explains how to use renv: https://github.com/OHDSI/SkeletonPredictionStudy/blob/main/STUDY-PACKAGE-SETUP.md

Perhaps I can quickly show you how it all works (demo how to create the json spec, create the study package in R and set up the renv) over a teams meeting and we can record that meeting for others as I think this will be useful for everyone?

Best wishes, Jenna

jreps avatar Jul 26 '22 13:07 jreps

Hi Jenna, that's really good notes thank you. I will follow this methodology to try to overcome the issue. It would be amazing with a teams meeting as well, I am pretty sure it would be very useful! Feel free to let me know what suits best.

andtsouch avatar Jul 26 '22 13:07 andtsouch

Thank @jreps for offering a demo. That would be very useful.

nadavrap avatar Jul 28 '22 14:07 nadavrap

Hi @jreps,

I have tested the suggested solution and have overcome the issue with the following ways:

  1. When generating the package with Hydra (as I was currently doing), the inst/settings/predictionAnalysisList.json contains the information from the json file of the PLP study in ATLAS (found under Utilities->Export). This file is expected to have an $analyses object which is not found and thus stops the execution. I am forcing the code to interpret the file by changing the lines 148-151 in the R/Main.R file from: if(is.null(predictionAnalysisList)){ predictionAnalysisList <- backwards(predictionAnalysisListFile) } to if(length(predictionAnalysisList$analyses[[i]])==0){ predictionAnalysisList <- backwards(predictionAnalysisListFile) }

  2. When generating the package using the SkeletonPredictionStudy (as suggested above), the inst/settings/predictionAnalysisList.json contains the modelDesign that you manually define when creating the study package and thus the required $analyses object as well. Therefore the execution runs smoothly. However, if someone wants to use the json definition from ATLAS, that is still possible by simply copy/pasting it in the predictionAnalysisList.json and following the change in the Main.R described above. Additionally, the SkeletonPredictionStudy is not possible to be executed in an environment without internet access, but the code can easily be updated if you donwload the plp-skeleton.zip first and then read it directly, instead of connecting to github.

The issue in general is that the Main.R expects an analyses object in the predictionAnalysisList.json, which is not present when the json file is copied from ATLAS. However, the requirement if(is.null(predictionAnalysisList)) is never met, since there is always predictionAnalysisList file. I think by changing the if clause above might fix the issue.

Thank you for the guidance and feel free to close this issue if you agree that it is resolved. It might be a good idea to still have a recorded tutorial of the SkeletionPredictionStudy package, maybe in the next PLP community call?

andtsouch avatar Aug 09 '22 14:08 andtsouch

Hi @andtsouch I tried your suggestion and was able to get around my problem, however another error came (see below). Do you know what that error means?

Creating cohorts
Connecting using PostgreSQL driver
Creating cohort tables
- Created table results.StudyClaveAZulPackageCohort
- Created table results.StudyClaveAZulPackageCohort_inclusion
- Created table results.StudyClaveAZulPackageCohort_inclusion_result
- Created table results.StudyClaveAZulPackageCohort_inclusion_stats
- Created table results.StudyClaveAZulPackageCohort_summary_stats
- Created table results.StudyClaveAZulPackageCohort_censor_stats
Creating cohort tables took 1.25secs
Loading cohortDefinitionSet
1/2- Generating cohort: Pacientes clave azul                                                                                                   
  |==================================================================================================| 100%
Executing SQL took 1.54 secs
2/2- Generating cohort: Pacientes hospitalizados
  |==================================================================================================| 100%
Executing SQL took 0.31 secs
Generating cohort set took 2.19 secs
Counting cohorts
Counting cohorts took 0.165 secs
Running predictions
Error in StudyClaveAZulPackage::execute(databaseDetails = databaseDetails,  : 
  object 'i' not found
> 

iamalonso avatar Nov 22 '22 20:11 iamalonso