Al-Murphy / MungeSumstats

Rapid standardisation and quality control of GWAS or QTL summary statistics
https://doi.org/doi:10.18129/B9.bioc.MungeSumstats
75 stars 16 forks source link

Saved formatted files disappear after restarting R session #33

Closed bschilder closed 3 years ago

bschilder commented 3 years ago

Not sure what's up here, thought temp files stuck around for a while (at least a couple days). I ran import_sumstats, which ran all the way through and supposedly wrote several files (according to the messages), restarted my R session and now they supposedly don't exist.

Are tempdir() and tempfile() doing something different what I thought they were doing?

bschilder commented 3 years ago

Confirmed this; these files are indeed deleted after restarting R session. Really good to know.

In that case, i think we should change the default dir to "./" and automatically create a new folder "formatted" where the results will go. That way, when processing multiple files, even if R crashes for whatever reason (or the user exits without knowing to copy all their formatted files elsewhere first), the time they spent processing won't be wasted.

check_save_path() always makes sure the directory users specify insave_path exists, and creates it if not.

bschilder commented 3 years ago

Also added some path QC at the beginning of check_save_path():

...
#### Do a bit of QC to get the full path ####
## Expand "~" into full path bc it isn't recognized in certain envs (eg Python)
save_path <- path.expand(save_path) 
## Expand relative path "./" into absolute path bc it's less ambiguous 
save_path <- gsub("^[.]/",paste0(getwd(),"/"),save_path)
...
Al-Murphy commented 3 years ago

@bschilder we can't change the default dir to "./", it's a bioconductor requirement that it defaults to a temp directory. As long as you have it as an input, the user can update from the temp to wherever they like

bschilder commented 3 years ago

Yikes! that's a weird one. ok, in that case let's provide ample warnings to user in both the README and the functions. I'd hate for anyone to run MungeSumstats for hours only to realise nothing was saved

bschilder commented 3 years ago

Now added here:

check_save_path <- function(save_path,
                            write_vcf=FALSE){
    #### Add warning to users tha temp files arent actually saved ####
    if(dirname(save_path)==tempdir()){
        message("WARNING: Formatted results will be saved to `tempdir()`.",
                "This means all results will be deleted upon ending the R session.",
                "To keep results, change `save_path` (e.g. `save_path='./formatted/'`)",
                " or make sure to copy files elsewhere after processing.")
    }
...
...