Skip to content

Commit 5d51f04

Browse files
committed
add custom_id example in CSV import example
1 parent f1c2093 commit 5d51f04

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

examples/09-import-csv.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def getMetadataFromRow(row):
5959
for keyval in row.items():
6060
field_type = 'text'
6161
# we don't import these columns as metadata
62-
if keyval[0] == 'Name' or keyval[0] == 'Comment':
62+
# Name is the tile, Comment is in the body, and ID is the custom_id.
63+
if keyval[0] == 'Name' or keyval[0] == 'Comment' or keyval[0] == 'ID':
6364
continue
6465
# special case for url/URL column, we make it a type: url
6566
if keyval[0].lower() == 'url':
@@ -84,19 +85,33 @@ def getMetadataFromRow(row):
8485

8586
# The column "Comment" will get added to the body of the resource
8687
def getBodyFromRow(row) -> str:
87-
metadata = { 'extra_fields': {} }
8888
for keyval in row.items():
8989
if keyval[0] == 'Comment':
9090
return f'<p>{keyval[1]}</p>'
9191
return ''
9292

93+
###########################################
94+
######## WHERE THE MAGIC HAPPENS ##########
95+
###########################################
96+
9397
# Note: use encoding='utf-8-sig' in the open() call if your file has BOM (Byte Order Mark)
9498
# Also make sure that the CSV file was saved as UTF-8 to avoid issues with special characters
9599
with open(CSV_PATH, newline='') as csvfile:
100+
# let's read the CSV using the standard "csv" library from python. No need for anything fancier.
96101
csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
102+
# now we loop over each row in our CSV
97103
for row in csvreader:
98104
# here we add the tag "-20°C freezer" to every row
105+
# the API allows setting tags during creation (POST) of a resource or experiment, so we use it here
99106
response = itemsApi.post_item_with_http_info(body={'category_id': RESOURCE_CATEGORY_ID, 'tags': ['-20°C freezer']})
100107
locationHeaderInResponse = response[2].get('Location')
108+
# that's our ID of the newly created resource
101109
itemId = int(locationHeaderInResponse.split('/').pop())
102-
itemsApi.patch_item(itemId, body={'title': row['Name'], 'body': getBodyFromRow(row), 'metadata': getMetadataFromRow(row)})
110+
111+
# Patch the item to change its content:
112+
# the "Name" column becomes our title
113+
# the "Body" is generated from the "Comment" column content with the "getBodyFromRow()" function
114+
# for the "ID" column we match it to the "custom_id" property in elab
115+
# and the extra fields (metadata) is built with a function
116+
# the single line below will make all those changes at once
117+
itemsApi.patch_item(itemId, body={'title': row['Name'], 'body': getBodyFromRow(row), 'custom_id': row['ID'], 'metadata': getMetadataFromRow(row)})

examples/data/antibodies.csv

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Name,Vendor,Vendor Reference,URL,Concentration,Price,Raised in,Recognizes,Comment
2-
DDX3 (D19B4) Rabbit mAb,Cell Signaling,8192,https://www.cellsignal.com/products/primary-antibodies/ddx3-d19b4-rabbit-mab/8192,100 μg/mL,110,Rabbit,"Human, Mouse, Rat, Monkey",Use at 1:000 for WB
3-
CAPZB (E4H6C) Rabbit mAb,Cell Signaling,10333,https://www.cellsignal.com/products/primary-antibodies/capzb-e4h6c-rabbit-mab/10333,1 mg/mL,80,Rabbit,"Human, Mouse, Rat",Works very well in WB at 1:10000
4-
RBAP46/RBAP48 (D4F8) Rabbit mAb,Cell Signaling,9067,https://www.cellsignal.com/products/primary-antibodies/rbap46-rbap48-d4f8-rabbit-mab/9067,5 mg/mL,30,Rabbit,"Human, Mouse, Rat, Monkey","Use at 1:500 for IF, not tested in WB yet. Aliquots done by Éric on July 9th, 2023"
5-
Phospho-GIT2 (Tyr392) (D8N9A) Rabbit mAb,Cell Signaling,11873,https://www.cellsignal.com/products/primary-antibodies/phospho-git2-tyr392-d8n9a-rabbit-mab/11873,50 μg/mL,300,Rabbit,Human,Got it from Chloé.
6-
Recombinant Anti-Lamin A + Lamin C antibody [EPR4100] - Nuclear Envelope Marker,Abcam,ab108595,https://www.abcam.com/products/primary-antibodies/lamin-a--lamin-c-antibody-epr4100-nuclear-envelope-marker-ab108595.html,12 μg/mL,250,Rabbit,Human,"The antibody recognizes full length Lamin A/C and the cleaved large unit. We have data to indicate that this antibody gives non-specific staining in IHC with mouse tissues. Based on this we believe the antibody is not suitable for use with mouse samples, as there will be non-specific staining."
7-
Recombinant Anti-Calcineurin A antibody,Abcam,ab282104,https://www.abcam.com/products/primary-antibodies/calcineurin-a-antibody-epr24997-22-ab282104.html,30 mg/mL,132,Rabbit,"Human, Mouse, Rat",
1+
Name,ID,Vendor,Vendor Reference,URL,Concentration,Price,Raised in,Recognizes,Comment
2+
DDX3 (D19B4) Rabbit mAb,3,Cell Signaling,8192,https://www.cellsignal.com/products/primary-antibodies/ddx3-d19b4-rabbit-mab/8192,100 μg/mL,110,Rabbit,"Human, Mouse, Rat, Monkey",Use at 1:000 for WB
3+
CAPZB (E4H6C) Rabbit mAb,4,Cell Signaling,10333,https://www.cellsignal.com/products/primary-antibodies/capzb-e4h6c-rabbit-mab/10333,1 mg/mL,80,Rabbit,"Human, Mouse, Rat",Works very well in WB at 1:10000
4+
RBAP46/RBAP48 (D4F8) Rabbit mAb,5,Cell Signaling,9067,https://www.cellsignal.com/products/primary-antibodies/rbap46-rbap48-d4f8-rabbit-mab/9067,5 mg/mL,30,Rabbit,"Human, Mouse, Rat, Monkey","Use at 1:500 for IF, not tested in WB yet. Aliquots done by Éric on July 9th, 2023"
5+
Phospho-GIT2 (Tyr392) (D8N9A) Rabbit mAb,8,Cell Signaling,11873,https://www.cellsignal.com/products/primary-antibodies/phospho-git2-tyr392-d8n9a-rabbit-mab/11873,50 μg/mL,300,Rabbit,Human,Got it from Chloé.
6+
Recombinant Anti-Lamin A + Lamin C antibody [EPR4100] - Nuclear Envelope Marker,10,Abcam,ab108595,https://www.abcam.com/products/primary-antibodies/lamin-a--lamin-c-antibody-epr4100-nuclear-envelope-marker-ab108595.html,12 μg/mL,250,Rabbit,Human,"The antibody recognizes full length Lamin A/C and the cleaved large unit. We have data to indicate that this antibody gives non-specific staining in IHC with mouse tissues. Based on this we believe the antibody is not suitable for use with mouse samples, as there will be non-specific staining."
7+
Recombinant Anti-Calcineurin A antibody,14,Abcam,ab282104,https://www.abcam.com/products/primary-antibodies/calcineurin-a-antibody-epr24997-22-ab282104.html,30 mg/mL,132,Rabbit,"Human, Mouse, Rat","This antibody, a unique guardian in the arsenal of immunity, stands alone in its precision, tailored to target and defend against threats with unparalleled specificity."

0 commit comments

Comments
 (0)