Skip to content

Commit

Permalink
Add more introductory annotation vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
anngvu committed Nov 15, 2024
1 parent 0466174 commit 01cc8c1
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions vignettes/annotate-data-intro.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Introduction to utils for annotating data"
output: rmarkdown::html_vignette
date: 2022-10-17
vignette: >
%\VignetteIndexEntry{annotating-nextflow-processed-data}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Intro

This introduces the annotation utilities with typical examples.
This is expected to be the more useful starting point for using nfportalutils for annotation tasks, to be followed by the more specialized vignetted for annotating NF processed data if needed.

### Set up
```{r, eval=FALSE}
library(nfportalutils)
syn_login()
# Change this to a dev project you have access to
PROJECT <- "syn26462036"
```

### Set annotations on a single file

Create a demo entity.
```{r, eval=FALSE}
synapseclient <- reticulate::import("synapseclient")
# Create an entity with some initial annotations
entity <- synapseclient$Folder("Demo Entity",
parent = PROJECT,
annotations = list(foo = "bar", favorites = c("raindrops", "whiskers")))
entity <- .syn$store(entity)
```

`set_annotations` can be used to add new annotations or correct an existing annotation on an entity.
This wraps the Python client to make it more intuitive to pass in an R list as the annotations as above.
Here, add another annotation *and* correct the `favorites` to "chocolate".
The returned data shows the unchanged `foo`, the updated `favorites`, and a new `n`.
```{r, eval=FALSE}
set_annotations(id = entity$properties$id, annotations = list(favorites = "chocolate", n = 7L))
```

Cleanup.
```{r, eval=FALSE}
.syn$delete(entity)
```

### Annotate in batch using a manifest

A better way to use `set_annotations` for a set of entities, usually files.

First create multiple entities that need to be annotated or corrected in batch.
```{r, eval=FALSE}
objs <- make_folder(parent = PARENT_TEST_PROJECT, folders = c("mock_file_1", "mock_file_2", "mock_file_3"))
ids <- sapply(objs, function(x) x$properties$id)
```

Create example manifest. Note: Another way includes reading in a shematic csv manifest with entityIds and Filenames.
```{r, eval=FALSE}
manifest <- data.table(
entityId = ids,
assay = "drugScreen",
experimentalTimepoint = c(1L, 3L, 7L),
experimentalTimepointUnit = "days",
cellType = list(c("schwann", "macrophage"), c("schwann", "macrophage"), c("schwann", "macrophage"))
)
manifest
```

Apply:
```{r, eval=FALSE}
annotate_with_manifest(manifest)
```

Cleanup.
```{r, eval=FALSE}
for (id in ids) .syn$delete(id)
```

0 comments on commit 01cc8c1

Please sign in to comment.