[arvados] created: 2.5.0-261-g945eba28b
git repository hosting
git at public.arvados.org
Wed Mar 8 16:56:06 UTC 2023
at 945eba28be38c66484deb5656472fad502087ee7 (commit)
commit 945eba28be38c66484deb5656472fad502087ee7
Author: AnetaSta22 <107112384+AnetaSta22 at users.noreply.github.com>
Date: Thu Feb 23 14:19:02 2023 +0100
speed up write function
Contributed by Aneta Stanczyk <aneta.stanczyk at contractors.roche.com>
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index e362de604..655bf98b3 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -198,22 +198,14 @@ Collection <- R6::R6Class(
#' @param istable Used in writing txt file to check if the file is table or not.
#' @examples
#' collection <- Collection$new(arv, collectionUUID)
- #' writeFile <- collection$writeFile("myoutput.csv", file, istable = NULL) # csv
- #' writeFile <- collection$writeFile("myoutput.fasta", file, istable = NULL) # fasta
- #' writeFile <- collection$writeFile("myoutputtable.txt", file, istable = "yes") # txt table
- #' writeFile <- collection$writeFile("myoutputtext.txt", file, istable = "no") # txt text
- #' writeFile <- collection$writeFile("myoutputbinary.dat", file) # binary
- #' writeFile <- collection$writeFile("myoutputxlsx.xlsx", file) # xlsx
- writeFile = function(name, file, istable = NULL, seqName = NULL)
- {
- # prepare file and connection
- arvFile <- collection$create(name)[[1]]
- arvFile <- collection$get(name)
- arvConnection <- arvFile$connection("w")
- # get file format
- FileName <- arvFile$getName()
- FileName <- tolower(FileName)
- FileFormat <- gsub(".*\\.", "", FileName)
+ #' writeFile <- collection$writeFile(name = "myoutput.csv", file = file, fileFormat = "csv", istable = NULL, collectionUUID = collectionUUID) # csv
+ #' writeFile <- collection$writeFile(name = "myoutput.tsv", file = file, fileFormat = "tsv", istable = NULL, collectionUUID = collectionUUID) # tsv
+ #' writeFile <- collection$writeFile(name = "myoutput.fasta", file = file, fileFormat = "fasta", istable = NULL, collectionUUID = collectionUUID) # fasta
+ #' writeFile <- collection$writeFile(name = "myoutputtable.txt", file = file, fileFormat = "txt", istable = "yes", collectionUUID = collectionUUID) # txt table
+ #' writeFile <- collection$writeFile(name = "myoutputtext.txt", file = file, fileFormat = "txt", istable = "no", collectionUUID = collectionUUID) # txt text
+ #' writeFile <- collection$writeFile(name = "myoutputbinary.dat", file = file, fileFormat = "dat", collectionUUID = collectionUUID) # binary
+ #' writeFile <- collection$writeFile(name = "myoutputxlsx.xlsx", file = file, fileFormat = "xlsx", collectionUUID = collectionUUID) # xlsx
+ writeFile = function(name, file, collectionUUID, fileFormat, istable = NULL, seqName = NULL) {
# set enviroment
ARVADOS_API_TOKEN <- Sys.getenv("ARVADOS_API_TOKEN")
@@ -227,22 +219,25 @@ Collection <- R6::R6Class(
"AWS_DEFAULT_REGION" = "collections",
"AWS_S3_ENDPOINT" = gsub("api[.]", "", ARVADOS_API_HOST))
- if (FileFormat == "txt") {
+ # save file
+ if (fileFormat == "txt") {
if (istable == "yes") {
- aws.s3::s3write_using(file, FUN = write.table, object = name, bucket = my_collection)
+ aws.s3::s3write_using(file, FUN = write.table, object = name, bucket = collectionUUID)
} else if (istable == "no") {
- aws.s3::s3write_using(file, FUN = writeChar, object = name, bucket = my_collection)
+ aws.s3::s3write_using(file, FUN = writeChar, object = name, bucket = collectionUUID)
} else {
stop(paste("Specify parametr istable"))
}
- } else if (FileFormat == "csv") {
- aws.s3::s3write_using(file, FUN = write.csv, object = name, bucket = my_collection)
- } else if (FileFormat == "fasta") {
- aws.s3::s3write_using(file, FUN = seqinr::write.fasta, name = seqName, object = name, bucket = my_collection)
- } else if (FileFormat == "xlsx") {
- aws.s3::s3write_using(file, FUN = openxlsx::write.xlsx, object = name, bucket = my_collection)
- } else if (FileFormat == "dat" || FileFormat == "bin") {
- aws.s3::s3write_using(file, FUN = writeBin, object = name, bucket = my_collection)
+ } else if (fileFormat == "csv") {
+ aws.s3::s3write_using(file, FUN = write.csv, object = name, bucket = collectionUUID)
+ } else if (fileFormat == "tsv") {
+ aws.s3::s3write_using(file, FUN = write.table, row.names = FALSE, sep = "\t", object = name, bucket = collectionUUID)
+ } else if (fileFormat == "fasta") {
+ aws.s3::s3write_using(file, FUN = seqinr::write.fasta, name = seqName, object = name, bucket = collectionUUID)
+ } else if (fileFormat == "xlsx") {
+ aws.s3::s3write_using(file, FUN = openxlsx::write.xlsx, object = name, bucket = collectionUUID)
+ } else if (fileFormat == "dat" || fileFormat == "bin") {
+ aws.s3::s3write_using(file, FUN = writeBin, object = name, bucket = collectionUUID)
} else {
stop(parse(('File format not supported, use arvadosFile$connection() and customise it')))
}
diff --git a/sdk/R/man/Collection.Rd b/sdk/R/man/Collection.Rd
index 5fbf1c1a1..bb72cc1b3 100644
--- a/sdk/R/man/Collection.Rd
+++ b/sdk/R/man/Collection.Rd
@@ -32,12 +32,13 @@ readFile <- collection$readArvFile(arvadosFile, Ncol = 5, Nrow = 150, istable =
## ------------------------------------------------
collection <- Collection$new(arv, collectionUUID)
-writeFile <- collection$writeFile("myoutput.csv", file, istable = NULL) # csv
-writeFile <- collection$writeFile("myoutput.fasta", file, istable = NULL) # fasta
-writeFile <- collection$writeFile("myoutputtable.txt", file, istable = "yes") # txt table
-writeFile <- collection$writeFile("myoutputtext.txt", file, istable = "no") # txt text
-writeFile <- collection$writeFile("myoutputbinary.dat", file) # binary
-writeFile <- collection$writeFile("myoutputxlsx.xlsx", file) # xlsx
+writeFile <- collection$writeFile(name = "myoutput.csv", file = file, fileFormat = "csv", istable = NULL, collectionUUID = collectionUUID) # csv
+writeFile <- collection$writeFile(name = "myoutput.tsv", file = file, fileFormat = "tsv", istable = NULL, collectionUUID = collectionUUID) # tsv
+writeFile <- collection$writeFile(name = "myoutput.fasta", file = file, fileFormat = "fasta", istable = NULL, collectionUUID = collectionUUID) # fasta
+writeFile <- collection$writeFile(name = "myoutputtable.txt", file = file, fileFormat = "txt", istable = "yes", collectionUUID = collectionUUID) # txt table
+writeFile <- collection$writeFile(name = "myoutputtext.txt", file = file, fileFormat = "txt", istable = "no", collectionUUID = collectionUUID) # txt text
+writeFile <- collection$writeFile(name = "myoutputbinary.dat", file = file, fileFormat = "dat", collectionUUID = collectionUUID) # binary
+writeFile <- collection$writeFile(name = "myoutputxlsx.xlsx", file = file, fileFormat = "xlsx", collectionUUID = collectionUUID) # xlsx
## ------------------------------------------------
## Method `Collection$create`
@@ -216,7 +217,14 @@ readFile <- collection$readArvFile(arvadosFile, Ncol = 5, Nrow = 150, istable =
\subsection{Method \code{writeFile()}}{
Write file content
\subsection{Usage}{
-\if{html}{\out{<div class="r">}}\preformatted{Collection$writeFile(name, file, istable = NULL, seqName = NULL)}\if{html}{\out{</div>}}
+\if{html}{\out{<div class="r">}}\preformatted{Collection$writeFile(
+ name,
+ file,
+ collectionUUID,
+ fileFormat,
+ istable = NULL,
+ seqName = NULL
+)}\if{html}{\out{</div>}}
}
\subsection{Arguments}{
@@ -233,12 +241,13 @@ Write file content
\subsection{Examples}{
\if{html}{\out{<div class="r example copy">}}
\preformatted{collection <- Collection$new(arv, collectionUUID)
-writeFile <- collection$writeFile("myoutput.csv", file, istable = NULL) # csv
-writeFile <- collection$writeFile("myoutput.fasta", file, istable = NULL) # fasta
-writeFile <- collection$writeFile("myoutputtable.txt", file, istable = "yes") # txt table
-writeFile <- collection$writeFile("myoutputtext.txt", file, istable = "no") # txt text
-writeFile <- collection$writeFile("myoutputbinary.dat", file) # binary
-writeFile <- collection$writeFile("myoutputxlsx.xlsx", file) # xlsx
+writeFile <- collection$writeFile(name = "myoutput.csv", file = file, fileFormat = "csv", istable = NULL, collectionUUID = collectionUUID) # csv
+writeFile <- collection$writeFile(name = "myoutput.tsv", file = file, fileFormat = "tsv", istable = NULL, collectionUUID = collectionUUID) # tsv
+writeFile <- collection$writeFile(name = "myoutput.fasta", file = file, fileFormat = "fasta", istable = NULL, collectionUUID = collectionUUID) # fasta
+writeFile <- collection$writeFile(name = "myoutputtable.txt", file = file, fileFormat = "txt", istable = "yes", collectionUUID = collectionUUID) # txt table
+writeFile <- collection$writeFile(name = "myoutputtext.txt", file = file, fileFormat = "txt", istable = "no", collectionUUID = collectionUUID) # txt text
+writeFile <- collection$writeFile(name = "myoutputbinary.dat", file = file, fileFormat = "dat", collectionUUID = collectionUUID) # binary
+writeFile <- collection$writeFile(name = "myoutputxlsx.xlsx", file = file, fileFormat = "xlsx", collectionUUID = collectionUUID) # xlsx
}
\if{html}{\out{</div>}}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list