Skip to content

Commit 97e5901

Browse files
authored
Merge pull request #2 from ENCODE-DCC/dev
v0.3.3
2 parents 8a5a7a5 + bfe5a97 commit 97e5901

4 files changed

Lines changed: 76 additions & 17 deletions

File tree

README.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
11
## ENCODE metadata submitter
22

3-
Metadata manager based on Google Sheet + Google Apps Script
3+
https://docs.google.com/spreadsheets/d/1mmTsrT4tnD4fRAf7nkdduq810nZvMQxZy0ga4Z_zK74/edit?usp=sharing
44

55

6-
## Google Sheet
6+
## Grant permission first
77

8-
Make a copy of this document.
8+
Grant permissions for the script to access your data on the sheet/account.
99

10-
https://docs.google.com/spreadsheets/d/1mmTsrT4tnD4fRAf7nkdduq810nZvMQxZy0ga4Z_zK74/edit?usp=sharing
1110

11+
## Authorization (username/password)
12+
13+
Go to portail's Profile page and get credentials pair (username/password).
14+
Go to `ENCODE` - `Authorize`. Credentials entered here will be shared for all sheets in the whole spreadsheet, but **NOT SHARED WITH OTHERS EVEN WHEN THEY MAKE A COPY OF YOUR SPREADSHEET**.
15+
16+
17+
## Set a profile name
18+
19+
Go to `ENCODE` - `Set profile name` and enter a valid profile name. A profile name in snakecase or capitalized CamelCase are allowed. For example, `experiment`, `Expertiment`, `biosample_type` and `BiosampleType`. Such profile name should be set for each sheet.
20+
21+
22+
## Check your current profile
23+
24+
Go to `ENCODE` - `Show sheet/header info`.
25+
26+
27+
## Special commented headers
28+
29+
Data values under commented headers will be ignored and not be sent to the portal.
30+
31+
- `#skip`: For all REST actions (GET/PUT/POST). You can additionally make `#skip` header and set row's data cell as 1 to skip REST actions for that specific row.
32+
- `#error`: For debugging purposese. This is filled with `HTTP ERROR CODE` + `HELP TEXT MESSAGE` for any recent REST action.
33+
34+
35+
## Make a POST template based on profile
36+
37+
Once you set a valid profile name, go to `ENCODE` - `Make new template row`. This will make a new row with empty/default values for each property. This templatre include ALL editable properties for a given profile. Some of them are shown but not editable (e.g. `schema_version` and `accession`).
38+
39+
40+
## GET metadata from portal
41+
42+
Make a new header with a proper identifying property (`accession` or `uuid` according to the given profile). And then define accession/uuids you want to retrieve from the portal under the header. Go to `ENCODE` - `Get metadata for all raws`.
43+
44+
45+
## PUT metadata to portal
46+
47+
GET metadata from portal first and then edit it. Set `#skip` as `0` if it is present and then go to `ENCODE` - `PUT all rows to the portal` .
48+
49+
50+
## POST metadata to portal
51+
52+
Starting from a template or existing metadata (retrieved from GET), set `#skip` as `0` if it is present and then go to `ENCODE` - `POST all rows to the portal` .
53+
54+
55+
## How to debug?
56+
57+
Any REST (GET/PUT/POST) action will return `HTTP ERROR CODE` + `HELP TEXT MESSAGE` in the `#error` column. Fix your problem with the help message and resubmit.
58+
59+
60+
## How to search for items on portal
61+
62+
Go to a data cell and hover your mouse on the header (1st row) of the column and check if it's shown as `SEARCH AVAILABLE` in its tooltop. On a data cell that you want to edit, go to `ENCODE` - `Search`. Then you will see a dialog box to edit your values.

src/Library.gs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
const DEBUG = false;
2-
const DEBUG_AUTO_YES = false;
3-
// const DEBUG = true;
4-
// const DEBUG_AUTO_YES = true;
5-
6-
71
function getType(p) {
82
if (Array.isArray(p)) return "array";
93
else if (typeof p == "string") return "string";

src/Metadata.gs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function getNumMetadataInSheet(sheet) {
3030
function makeMetadataUrl(method, profileName, endpoint, identifyingVal) {
3131
switch(method) {
3232
case "GET":
33-
return `${endpoint}/${profileName}/${identifyingVal}/?format=json&frame=edit`;
33+
return `${endpoint}/${profileName}/${identifyingVal}/?format=json&frame=object`;
3434
case "PUT":
3535
return `${endpoint}/${profileName}/${identifyingVal}`;
3636
case "POST":
@@ -54,9 +54,20 @@ function getMetadataFromPortal(identifyingVal, identifyingProp, profileName, end
5454

5555
var responseJson = JSON.parse(response.getContentText());
5656
if (error === 200) {
57-
// if no error, merge parsed JSON to row object
57+
// automatically set #skip as 1 to prevent duplicate GET
5858
object[HEADER_COMMENTED_PROP_SKIP] = 1;
59-
object = {...object, ...responseJson};
59+
60+
// filter out
61+
// - "nonSubmittable" properties
62+
// - properties that are not present in the profile
63+
var profile = getProfile(profileName, endpoint);
64+
var filteredResponseJson = Object.keys(responseJson)
65+
.filter((prop) => profile["properties"].hasOwnProperty(prop))
66+
.filter((prop) => !isNonSubmittableProp(profile, prop))
67+
.reduce((cur, prop) => { return Object.assign(cur, { [prop]: responseJson[prop] })}, {});
68+
69+
// then merge it with commented properties
70+
object = {...object, ...filteredResponseJson};
6071
}
6172
else {
6273
// if error, write helpText to provide debugging information
@@ -95,9 +106,6 @@ function getSortedProps(props, profile, propPriority=DEFAULT_PROP_PRIORITY) {
95106
return sortedProps;
96107
}
97108

98-
99-
getIdentifyingPropForProfile
100-
101109
function updateSheetWithMetadataFromPortal(sheet, profileName, endpointForGet, endpointForProfile) {
102110
var profile = getProfile(profileName, endpointForProfile);
103111
if (!profile) {
@@ -174,7 +182,6 @@ function putSheetToPortal(sheet, profileName, endpointForPut, endpointForProfile
174182

175183
switch(method) {
176184
case "PUT":
177-
178185
var url = makeMetadataUrl(method, profileName, endpointForPut, json[identifyingProp]);
179186
var response = restPut(url, payloadJson=json);
180187
break;

src/UserInterface.gs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DEFAULT_ENDPOINT_WRITE = ENDPOINT_TEST;
66
const KEY_ENDPOINT_READ = "endpointRead";
77
const KEY_ENDPOINT_WRITE = "endpointWrite";
88
const KEY_PROFILE_NAME = "profileName";
9+
const URL_GITHUB = "https://github.com/encode-DCC/google-sheet-metadata-submitter";
910

1011

1112
function onOpen() {
@@ -30,6 +31,8 @@ function onOpen() {
3031
menu.addItem("Set endpoint for WRITE actions", "setEndpointWrite");
3132
menu.addItem("Set profile name", "setProfileName");
3233
menu.addItem("Open profile page", "openProfilePage");
34+
menu.addSeparator();
35+
menu.addItem("Open tool's github page for README", "openToolGithubPage");
3336
menu.addToUi();
3437
}
3538

@@ -90,6 +93,10 @@ function openProfilePage() {
9093
);
9194
}
9295

96+
function openToolGithubPage() {
97+
openUrl(URL_GITHUB);
98+
}
99+
93100
function showSheetAndHeaderInfo() {
94101
alertBox(
95102
"* Sheet information\n" +

0 commit comments

Comments
 (0)