Skip to content

Commit

Permalink
add custom_id example in CSV import example
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasCARPi committed Nov 21, 2023
1 parent f1c2093 commit 5d51f04
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
21 changes: 18 additions & 3 deletions examples/09-import-csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def getMetadataFromRow(row):
for keyval in row.items():
field_type = 'text'
# we don't import these columns as metadata
if keyval[0] == 'Name' or keyval[0] == 'Comment':
# Name is the tile, Comment is in the body, and ID is the custom_id.
if keyval[0] == 'Name' or keyval[0] == 'Comment' or keyval[0] == 'ID':
continue
# special case for url/URL column, we make it a type: url
if keyval[0].lower() == 'url':
Expand All @@ -84,19 +85,33 @@ def getMetadataFromRow(row):

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

###########################################
######## WHERE THE MAGIC HAPPENS ##########
###########################################

# Note: use encoding='utf-8-sig' in the open() call if your file has BOM (Byte Order Mark)
# Also make sure that the CSV file was saved as UTF-8 to avoid issues with special characters
with open(CSV_PATH, newline='') as csvfile:
# let's read the CSV using the standard "csv" library from python. No need for anything fancier.
csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
# now we loop over each row in our CSV
for row in csvreader:
# here we add the tag "-20°C freezer" to every row
# the API allows setting tags during creation (POST) of a resource or experiment, so we use it here
response = itemsApi.post_item_with_http_info(body={'category_id': RESOURCE_CATEGORY_ID, 'tags': ['-20°C freezer']})
locationHeaderInResponse = response[2].get('Location')
# that's our ID of the newly created resource
itemId = int(locationHeaderInResponse.split('/').pop())
itemsApi.patch_item(itemId, body={'title': row['Name'], 'body': getBodyFromRow(row), 'metadata': getMetadataFromRow(row)})

# Patch the item to change its content:
# the "Name" column becomes our title
# the "Body" is generated from the "Comment" column content with the "getBodyFromRow()" function
# for the "ID" column we match it to the "custom_id" property in elab
# and the extra fields (metadata) is built with a function
# the single line below will make all those changes at once
itemsApi.patch_item(itemId, body={'title': row['Name'], 'body': getBodyFromRow(row), 'custom_id': row['ID'], 'metadata': getMetadataFromRow(row)})
14 changes: 7 additions & 7 deletions examples/data/antibodies.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name,Vendor,Vendor Reference,URL,Concentration,Price,Raised in,Recognizes,Comment
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
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
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"
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é.
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."
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",
Name,ID,Vendor,Vendor Reference,URL,Concentration,Price,Raised in,Recognizes,Comment
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
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
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"
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é.
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."
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 comments on commit 5d51f04

Please sign in to comment.