Skip to content

Commit

Permalink
Merge pull request #8 from gf-dcc/feat/manage-sample-ids
Browse files Browse the repository at this point in the history
Add prelim script
  • Loading branch information
anngvu authored Jul 17, 2024
2 parents b3d33e2 + e9c4f23 commit 7117974
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions manage-sample-ids/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Sample ID Management

Collection of utility scripts that help with managing sample entities for the BEN Collaborative Project / Breast Atlas in Synapse.
There is potential functionality for extracting ids, inferring linkage of existing sample entities with data files, etc., that may be more automated eventually.
27 changes: 27 additions & 0 deletions manage-sample-ids/extract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
library(synapser)

synapser::synLogin(authToken = Sys.getenv("SYNAPSE_AUTH_TOKEN"))

# It is easiest to use a fileview to get all nested children in "Samples"
SampleTracking <- "syn52225331"

tb <- synapser::synTableQuery(glue::glue("select id from {SampleTracking}"))
ids <- as.data.frame(tb)$id

asPatientID <- function(s) regmatches(s, regexpr("[A-Z]+[0-9]?-?[0-9]+", s))

errors <- c()

for(i in ids) {

entity <- synapser::synGet(i, downloadFile = FALSE)
pID <- asPatientID(entity$properties$name)
entity$annotations$PatientID <- pID

# For now, let's just use the entity name as sample name
entity$annotations$SampleID <- entity$properties$name
tryCatch(synapser::synStore(entity), error = function(e) { cat("Skipped ", i, "\n"); errors <- append(errors, i) })
}



0 comments on commit 7117974

Please sign in to comment.