A view is a view of all entities (File, Folder, Project, Table, Docker Repository, View) within one or more Projects or Folders. Views can:
Preliminaries:
library(reticulate)
library(synapser)
##
## TERMS OF USE NOTICE:
## When using Synapse, remember that the terms and conditions of use require that you:
## 1) Attribute data contributors when discussing these data or results from these data.
## 2) Not discriminate, identify, or recontact individuals or groups represented by the data.
## 3) Use and contribute only data de-identified to HIPAA standards.
## 4) Redistribute data only under these same terms of use.
syn <- reticulate::import("synapseclient")
EntityViewType <- syn$EntityViewType
synLogin()
## NULL
# Create a new project
# use hex_digits to generate random string
hex_digits <- c(as.character(0:9), letters[1:6])
projectName <- sprintf("My unique project %s", paste0(sample(hex_digits, 32, replace = TRUE), collapse = ""))
project <- Project(projectName)
project <- synStore(project)
# Create some files
filePath <- tempfile()
connection <- file(filePath)
writeChar("this is the content of the first file", connection, eos = NULL)
close(connection)
file <- File(path = filePath, parent = project)
file <- synStore(file)
filePath2 <- tempfile()
connection2 <- file(filePath2)
writeChar("this is the content of the second file", connection, eos = NULL)
close(connection2)
file2 <- File(path = filePath2, parent = project)
file2 <- synStore(file2)
# add some annotations
synSetAnnotations(file, list(contributor = "Sage", class = "V"))
## $class
## [1] "V"
##
## $contributor
## [1] "Sage"
synSetAnnotations(file2, list(contributor = "UW", rank = "X"))
## $rank
## [1] "X"
##
## $contributor
## [1] "UW"
Creating a View:
view <- EntityViewSchema(name = "my first file view",
columns = c(
Column(name = "contributor", columnType = "STRING"),
Column(name = "class", columnType = "STRING"),
Column(name = "rank", columnType = "STRING")),
parent = project$properties$id,
scopes = project$properties$id,
includeEntityTypes = c(EntityViewType$FILE, EntityViewType$FOLDER),
add_default_columns = TRUE)
view <- synStore(view)
We support the following entity type in a View:
EntityViewType
## <enum 'EntityViewType'>
To see the content of your newly created View, use synTableQuery():
queryResults <- synTableQuery(sprintf("select * from %s", view$properties$id))
data <- as.data.frame(queryResults)
data
## ROW_ID ROW_VERSION ROW_ETAG id
## 1 52417572 1 03d6cee4-35c4-4be7-9021-4b12f6eaa755 syn52417572
## 2 52417573 1 ec739129-fea1-4901-bf71-2611930e94d2 syn52417573
## name description createdOn createdBy
## 1 filed79d5e81ba3e NA 2023-09-09 22:59:50 3324230
## 2 filed79d16ea6ceb NA 2023-09-09 22:59:51 3324230
## etag modifiedOn modifiedBy type
## 1 03d6cee4-35c4-4be7-9021-4b12f6eaa755 2023-09-09 22:59:52 3324230 file
## 2 ec739129-fea1-4901-bf71-2611930e94d2 2023-09-09 22:59:52 3324230 file
## currentVersion parentId benefactorId projectId dataFileHandleId
## 1 1 syn52417571 syn52417571 syn52417571 128471165
## 2 1 syn52417571 syn52417571 syn52417571 128471166
## dataFileSizeBytes dataFileMD5Hex
## 1 37 47dfe7f5eaa49a5413c7b79b67ab9c43
## 2 38 ba01e01b9e3ffea3ebef95efa62998b0
## dataFileConcreteType dataFileBucket
## 1 org.sagebionetworks.repo.model.file.S3FileHandle proddata.sagebase.org
## 2 org.sagebionetworks.repo.model.file.S3FileHandle proddata.sagebase.org
## dataFileKey contributor
## 1 3324230/b4e57ee9-09e5-47eb-b0e7-f72a7286f57f/filed79d5e81ba3e Sage
## 2 3324230/a81a4d30-81bc-47b6-8990-021b9b790207/filed79d16ea6ceb UW
## class rank
## 1 V NA
## 2 NA X
To update ‘class’ annotation for ‘file2’, simply update the view:
The change in annotations is reflected in synGetAnnotations():
synGetAnnotations(file2$properties$id)
A unique etag is associated with every file that updates when changes are made to a file, including the contents, annotations, or metadata. Any updates pushed to Synapse will change an object’s etag.
data$etag
There may be cases where you want to update the annotations on a subset of files in a view. In order to preserve the etag, and thus the file history, you will need to store only the rows that have been modified.
A view can contain different types of entity. To change the types of entity that will show up in a view:
A View is a Table. Please visit Tables vignettes to see how to change schema, update content, and other operations that can be done on View.
synDelete(project)
## NULL