-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathviews.Rmd
More file actions
128 lines (107 loc) · 4.23 KB
/
Copy pathviews.Rmd
File metadata and controls
128 lines (107 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
title: "Views"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Views}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
## Views
A view is a view of all entities (File, Folder, Project, Table, Docker Repository, View) within one or more Projects or Folders. Views can:
* Provide a way of isolating or linking data based on similarities
* Provide the ability to link entities together by their annotations
* Allow view/editing entities attributes in bulk
* Allow entities to be easily searched and queried
Preliminaries:
```{r collapse=TRUE}
library(reticulate)
library(synapser)
syn <- reticulate::import("synapseclient")
EntityViewType <- syn$EntityViewType
synLogin()
# 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)
# Add some annotations
file$annotations = list(contributor = "UW", rank = "X")
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$annotations = list(contributor = "UW", rank = "X")
file2 <- synStore(file2)
```
Creating a View:
```{r collapse=TRUE}
view <- EntityViewSchema(name = "my first file view",
columns = c(
Column(name = "contributor", columnType = "STRING"),
Column(name = "class", columnType = "STRING"),
Column(name = "rank", columnType = "STRING"),
Column(name = "string_list", columnType = "STRING_LIST")),
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:
```{r collapse=TRUE}
EntityViewType
```
```{r include = FALSE}
# wait for the view to be created
Sys.sleep(10)
```
To see the content of your newly created View, use synTableQuery():
```{r collapse=TRUE}
queryResults <- synTableQuery(sprintf("select * from %s", view$properties$id))
```
```{r}
data <- as.data.frame(queryResults)
data
```
## Updating Annotations using View
To update 'class' and 'string_list' annotations for all files in the view, simply update the view:
```{r collapse=TRUE, eval=FALSE}
data["class"] <- list(c("V", "VI"))
# update string_list annotation
string_list_values <- list(list("a,b,c"), list("d,e,f"))
data["string_list"] <- sapply(string_list_values, function(x) rjson::toJSON(x))
synStore(Table(view$properties$id, data))
```
The change in annotations is reflected in synGetAnnotations():
```{r collapse=TRUE, eval=FALSE}
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.
```{r collapse=TRUE, eval=FALSE}
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.
```{r collapse=TRUE}
data$contributor[1] <- c("Sage Bionetworks")
synStore(Table(view$properties$id, data[1,]))
```
## Update View's Content
A view can contain different types of entity. To change the types of entity that will show up in a view:
```{r collapse=TRUE}
view <- synGet(view$properties$id)
view$set_entity_types(list(EntityViewType$FILE))
```
A View is a Table. Please visit [Tables vignettes](tables.html) to see how to change schema, update content, and other operations that can be done on View.
```{r collapse=TRUE}
synDelete(project)
```