Mercurial > repos > lecorguille > xcms_fillpeaks
comparison lib.r @ 23:7e289788d37d draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
| author | lecorguille |
|---|---|
| date | Wed, 01 Mar 2017 16:58:07 -0500 |
| parents | 02bb34af0921 |
| children | 4db7afa8284d |
comparison
equal
deleted
inserted
replaced
| 22:a6938c381d4e | 23:7e289788d37d |
|---|---|
| 471 | 471 |
| 472 #cat("\n\n") | 472 #cat("\n\n") |
| 473 | 473 |
| 474 return(as.matrix(md5sum(files))) | 474 return(as.matrix(md5sum(files))) |
| 475 } | 475 } |
| 476 | |
| 477 | |
| 478 # This function get the raw file path from the arguments | |
| 479 getRawfilePathFromArguments <- function(listArguments) { | |
| 480 zipfile = NULL | |
| 481 singlefile = NULL | |
| 482 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] | |
| 483 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] | |
| 484 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] | |
| 485 | |
| 486 if (!is.null(listArguments[["singlefile_galaxyPath"]])) { | |
| 487 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPath"]]; | |
| 488 singlefile_sampleNames = listArguments[["singlefile_sampleName"]] | |
| 489 } | |
| 490 if (!is.null(listArguments[["singlefile_galaxyPathPositive"]])) { | |
| 491 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathPositive"]]; | |
| 492 singlefile_sampleNames = listArguments[["singlefile_sampleNamePositive"]] | |
| 493 } | |
| 494 if (!is.null(listArguments[["singlefile_galaxyPathNegative"]])) { | |
| 495 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathNegative"]]; | |
| 496 singlefile_sampleNames = listArguments[["singlefile_sampleNameNegative"]] | |
| 497 } | |
| 498 if (exists("singlefile_galaxyPaths")){ | |
| 499 singlefile_galaxyPaths = unlist(strsplit(singlefile_galaxyPaths,",")) | |
| 500 singlefile_sampleNames = unlist(strsplit(singlefile_sampleNames,",")) | |
| 501 | |
| 502 singlefile=NULL | |
| 503 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { | |
| 504 singlefile_galaxyPath=singlefile_galaxyPaths[singlefile_galaxyPath_i] | |
| 505 singlefile_sampleName=singlefile_sampleNames[singlefile_galaxyPath_i] | |
| 506 singlefile[[singlefile_sampleName]] = singlefile_galaxyPath | |
| 507 } | |
| 508 } | |
| 509 for (argument in c("zipfile","zipfilePositive","zipfileNegative","singlefile_galaxyPath","singlefile_sampleName","singlefile_galaxyPathPositive","singlefile_sampleNamePositive","singlefile_galaxyPathNegative","singlefile_sampleNameNegative")) { | |
| 510 listArguments[[argument]]=NULL | |
| 511 } | |
| 512 return(list(zipfile=zipfile, singlefile=singlefile, listArguments=listArguments)) | |
| 513 } | |
| 514 | |
| 515 | |
| 516 # This function retrieve the raw file in the working directory | |
| 517 # - if zipfile: unzip the file with its directory tree | |
| 518 # - if singlefiles: set symlink with the good filename | |
| 519 retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile) { | |
| 520 if(!is.null(singlefile) && (length("singlefile")>0)) { | |
| 521 for (singlefile_sampleName in names(singlefile)) { | |
| 522 singlefile_galaxyPath = singlefile[[singlefile_sampleName]] | |
| 523 if(!file.exists(singlefile_galaxyPath)){ | |
| 524 error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!") | |
| 525 print(error_message); stop(error_message) | |
| 526 } | |
| 527 | |
| 528 file.symlink(singlefile_galaxyPath,singlefile_sampleName) | |
| 529 } | |
| 530 directory = "." | |
| 531 | |
| 532 } | |
| 533 if(!is.null(zipfile) && (zipfile!="")) { | |
| 534 if(!file.exists(zipfile)){ | |
| 535 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!") | |
| 536 print(error_message) | |
| 537 stop(error_message) | |
| 538 } | |
| 539 | |
| 540 #list all file in the zip file | |
| 541 #zip_files=unzip(zipfile,list=T)[,"Name"] | |
| 542 | |
| 543 #unzip | |
| 544 suppressWarnings(unzip(zipfile, unzip="unzip")) | |
| 545 | |
| 546 #get the directory name | |
| 547 filesInZip=unzip(zipfile, list=T); | |
| 548 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))); | |
| 549 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] | |
| 550 directory = "." | |
| 551 if (length(directories) == 1) directory = directories | |
| 552 | |
| 553 cat("files_root_directory\t",directory,"\n") | |
| 554 | |
| 555 } | |
| 556 return (directory) | |
| 557 } |
