File View

A file view is a view of all Files within one or more Projects or Folders. File views can:

  • Provide a way of isolating or linking data based on similarities
  • Provide the ability to link Files together by their annotations
  • Allow view/editing File attributes in bulk
  • Allow Files to be easily searched and queried

Preliminaries:

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.
synLogin()
## Welcome, migrationAdmin!
## 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)
## ################################################## Uploading file to Synapse storage ##################################################
Uploading [--------------------]0.00%   0.0bytes/37.0bytes  fileb9607dd60dca     
Uploading [####################]100.00%   37.0bytes/37.0bytes (29.7bytes/s) fileb9607dd60dca Done...

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)
## ################################################## Uploading file to Synapse storage ##################################################
Uploading [--------------------]0.00%   0.0bytes/38.0bytes  fileb96070238950     
Uploading [####################]100.00%   38.0bytes/38.0bytes (58.9bytes/s) fileb96070238950 Done...

# add some annotations
synSetAnnotations(file, list(contributor = "Sage", class = "V"))
## $class
## $class[[1]]
## [1] "V"
## 
## 
## $contributor
## $contributor[[1]]
## [1] "Sage"
synSetAnnotations(file2, list(contributor = "UW", rank = "X"))
## $rank
## $rank[[1]]
## [1] "X"
## 
## 
## $contributor
## $contributor[[1]]
## [1] "UW"

Creating a File 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,
                         add_default_columns = TRUE)

view <- synStore(view)

To see the content of your newly created File View, use synTableQuery():

Updating Annotations using File View

To update ‘class’ annotation for ‘file2’, simply update the view:

data["class"] <- c("V", "VI")
synStore(Table(view$properties$id, data))

The change in annotations reflect in synGetAnnotations():

synGetAnnotations(file2$properties$id)

A File View is a Table. Please visit Tables vignettes to see how to change schema, update content, and other operations that can be done on File View.