diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e095..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..74459b697 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 35415829b..5d64c867e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 189f24ab6..c8e807676 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/documentation_builder/metadata.ipynb b/documentation_builder/metadata.ipynb index 44dc1d291..ccf282d14 100644 --- a/documentation_builder/metadata.ipynb +++ b/documentation_builder/metadata.ipynb @@ -1,108 +1,299 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Metadata\n", - "\n", - "Metadata in the form of annotations, provenance or additional key:value pairs is an important asset for a model.\n", - "Such data can be handled via the `annotation` field on cobra objects" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true, - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [ - { - "ename": "ValueError", - "evalue": "time data '2020-08-26T23:28:20' does not match format '%Y-%m-%dT%H:%M:%S%z'", - "output_type": "error", - "traceback": [ - "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mvalidate_datetime\u001B[0;34m(datetime_str)\u001B[0m\n\u001B[1;32m 254\u001B[0m \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 255\u001B[0;31m \u001B[0mdatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstrptime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdatetime_str\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"%Y-%m-%dT%H:%M:%S%z\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 256\u001B[0m \u001B[0;32mexcept\u001B[0m \u001B[0mValueError\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m/usr/lib/python3.7/_strptime.py\u001B[0m in \u001B[0;36m_strptime_datetime\u001B[0;34m(cls, data_string, format)\u001B[0m\n\u001B[1;32m 576\u001B[0m format string.\"\"\"\n\u001B[0;32m--> 577\u001B[0;31m \u001B[0mtt\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mfraction\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mgmtoff_fraction\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0m_strptime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdata_string\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mformat\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 578\u001B[0m \u001B[0mtzname\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mgmtoff\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mtt\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m-\u001B[0m\u001B[0;36m2\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m/usr/lib/python3.7/_strptime.py\u001B[0m in \u001B[0;36m_strptime\u001B[0;34m(data_string, format)\u001B[0m\n\u001B[1;32m 358\u001B[0m raise ValueError(\"time data %r does not match format %r\" %\n\u001B[0;32m--> 359\u001B[0;31m (data_string, format))\n\u001B[0m\u001B[1;32m 360\u001B[0m \u001B[0;32mif\u001B[0m \u001B[0mlen\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdata_string\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m!=\u001B[0m \u001B[0mfound\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;31mValueError\u001B[0m: time data '2020-08-26T23:28:20' does not match format '%Y-%m-%dT%H:%M:%S%z'", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mvalidate_datetime\u001B[0;34m(datetime_str)\u001B[0m\n\u001B[1;32m 269\u001B[0m \u001B[0;32mtry\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 270\u001B[0;31m \u001B[0mdatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstrptime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdate_p36\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"%Y-%m-%dT%H:%M:%S%z\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 271\u001B[0m \u001B[0;32mexcept\u001B[0m \u001B[0mValueError\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m/usr/lib/python3.7/_strptime.py\u001B[0m in \u001B[0;36m_strptime_datetime\u001B[0;34m(cls, data_string, format)\u001B[0m\n\u001B[1;32m 576\u001B[0m format string.\"\"\"\n\u001B[0;32m--> 577\u001B[0;31m \u001B[0mtt\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mfraction\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mgmtoff_fraction\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0m_strptime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdata_string\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mformat\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 578\u001B[0m \u001B[0mtzname\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mgmtoff\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mtt\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m-\u001B[0m\u001B[0;36m2\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m/usr/lib/python3.7/_strptime.py\u001B[0m in \u001B[0;36m_strptime\u001B[0;34m(data_string, format)\u001B[0m\n\u001B[1;32m 358\u001B[0m raise ValueError(\"time data %r does not match format %r\" %\n\u001B[0;32m--> 359\u001B[0;31m (data_string, format))\n\u001B[0m\u001B[1;32m 360\u001B[0m \u001B[0;32mif\u001B[0m \u001B[0mlen\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdata_string\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m!=\u001B[0m \u001B[0mfound\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mend\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;31mValueError\u001B[0m: time data '2020-08-26T23:28:20' does not match format '%Y-%m-%dT%H:%M:%S%z'", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", - "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 11\u001B[0m metabolite.annotation.history = History(\n\u001B[1;32m 12\u001B[0m \u001B[0mcreators\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mcreator\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 13\u001B[0;31m \u001B[0mcreated_date\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mHistoryDatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mutcnow\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 14\u001B[0m \u001B[0mmodified_dates\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mHistoryDatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mutcnow\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 15\u001B[0m )\n", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mutcnow\u001B[0;34m()\u001B[0m\n\u001B[1;32m 239\u001B[0m \u001B[0mutcnow\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mdatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mutcnow\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 240\u001B[0m \u001B[0mvalue\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mutcnow\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstrftime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"%Y-%m-%dT%H:%M:%S%z\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 241\u001B[0;31m \u001B[0;32mreturn\u001B[0m \u001B[0mHistoryDatetime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 242\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 243\u001B[0m \u001B[0;34m@\u001B[0m\u001B[0mstaticmethod\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36m__init__\u001B[0;34m(self, history_datetime)\u001B[0m\n\u001B[1;32m 207\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0m__init__\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mhistory_datetime\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mstr\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 208\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_datetime\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;32mNone\u001B[0m \u001B[0;31m# type: str\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 209\u001B[0;31m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdatetime\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mhistory_datetime\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 210\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 211\u001B[0m \u001B[0;34m@\u001B[0m\u001B[0mproperty\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mdatetime\u001B[0;34m(self, value)\u001B[0m\n\u001B[1;32m 215\u001B[0m \u001B[0;34m@\u001B[0m\u001B[0mdatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msetter\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 216\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0mdatetime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mvalue\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m->\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 217\u001B[0;31m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_datetime\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mparse_datetime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 218\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 219\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0mparse_datetime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mvalue\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m->\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mparse_datetime\u001B[0;34m(self, value)\u001B[0m\n\u001B[1;32m 223\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0mvalue\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdatetime\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 224\u001B[0m \u001B[0;32melif\u001B[0m \u001B[0misinstance\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 225\u001B[0;31m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mvalidate_datetime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 226\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0mvalue\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 227\u001B[0m \u001B[0;32melif\u001B[0m \u001B[0misinstance\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mdatetime\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/git/cobrapy-hemnant/src/cobra/core/metadata/history.py\u001B[0m in \u001B[0;36mvalidate_datetime\u001B[0;34m(datetime_str)\u001B[0m\n\u001B[1;32m 270\u001B[0m \u001B[0mdatetime\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mstrptime\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdate_p36\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m\"%Y-%m-%dT%H:%M:%S%z\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 271\u001B[0m \u001B[0;32mexcept\u001B[0m \u001B[0mValueError\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 272\u001B[0;31m \u001B[0;32mraise\u001B[0m \u001B[0mValueError\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mstr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0me\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 273\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0;32mTrue\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 274\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;31mValueError\u001B[0m: time data '2020-08-26T23:28:20' does not match format '%Y-%m-%dT%H:%M:%S%z'" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + }, + "colab": { + "name": "metadata.ipynb", + "provenance": [] } - ], - "source": [ - "from cobra.core import Metabolite\n", - "from cobra.core.metadata import History, Creator, HistoryDatetime\n", - "\n", - "metabolite = Metabolite(id=\"glc\", name=\"D-glucose\")\n", - "creator = Creator(\n", - " first_name=\"Max\",\n", - " last_name=\"Mustermann\",\n", - " organization_name=\"Muster University\",\n", - " email=\"max.mustermann@cobrapy.org\"\n", - ")\n", - "metabolite.annotation.history = History(\n", - " creators=[creator],\n", - " created_date=HistoryDatetime.utcnow(),\n", - " modified_dates=[HistoryDatetime.utcnow()],\n", - ")" - ] }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [ - "\n" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "bVgYSbcPLbwU", + "colab_type": "text" + }, + "source": [ + "# Metadata\n", + "\n", + "Metadata in the form of annotations, provenance or additional key:value pairs is an important asset for a model.\n", + "Such data can be handled via the `annotation` field on cobra objects" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Rv-QKmAPM8PY", + "colab_type": "text" + }, + "source": [ + "# History\n", + "\n", + "History attribute, present in the `annotation` attribute of a COBRA component, stores the history of the component like creators, created date and modified date of that component." + ] + }, + { + "cell_type": "code", + "metadata": { + "pycharm": { + "name": "#%%\n" + }, + "id": "EsBAtYeHLbwc", + "colab_type": "code", + "colab": {} + }, + "source": [ + "from cobra.core import Metabolite\n", + "from cobra.core.metadata import History, Creator, HistoryDatetime\n", + "\n", + "metabolite = Metabolite(id=\"glc\", name=\"D-glucose\")\n" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "11wwIBGHWM66", + "colab_type": "text" + }, + "source": [ + "The dates have to be objects of `HistoryDateTime` class and creators that of `Creator` class. We can add then directly via constructor." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Tmo3MUtpWn8K", + "colab_type": "code", + "colab": {} + }, + "source": [ + "history = History(\n", + " creators=[\n", + " Creator(\n", + " first_name=\"Matthias\",\n", + " last_name=\"Koenig\",\n", + " organization_name=\"HU\",\n", + " email=\"test@test.com\",\n", + " ),\n", + " ],\n", + " created_date=HistoryDatetime(\"2020-06-26T02:34:30+05:30\"),\n", + " modified_dates=[\n", + " HistoryDatetime(\"2020-06-26T12:34:11+00:00\"),\n", + " HistoryDatetime(\"2020-06-26T00:34:11+05:30\"),\n", + " ],\n", + " )\n", + "\n", + "metabolite.annotation.history = history" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6EtjXs5FWsB2", + "colab_type": "text" + }, + "source": [ + "Or we can also add them by making object separtely and then adding in the history object." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "9tiNKucaW1nT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "new_creator = Creator(\n", + " first_name=\"Andreas\",\n", + " last_name=\"Draeger\",\n", + " organization_name=\"University of Tübingen\",\n", + " email=\"test2@test2.com\",\n", + " )\n", + "\n", + "metabolite.annotation.history.creators.append(new_creator)\n", + "modified_hdtime = HistoryDatetime()\n", + "modified_hdtime.utcnow()\n", + "metabolite.annotation.history.modified_dates.append(modified_hdtime)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "wXst9A76PuoJ", + "colab_type": "text" + }, + "source": [ + "# CVTerms\n", + "\n", + "CVTerms stands for Controlled Vocabulary Terms, are is used to store the external resources which are linked with the given COBRA component. We can make CVTerm's object either by passing the data directly from the constructor. We can also define the nested data for linked resources." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "whC9AASSQKnn", + "colab_type": "code", + "colab": {} + }, + "source": [ + "annotation_dict = {\n", + " \"bqb_hasTaxon\": [{\"resources\": [\"http://identifiers.org/taxonomy/511145\"]}],\n", + " \"bqm_is\": [\n", + " {\n", + " \"nested_data\": {\n", + " \"bqb_isDescribedBy\": [\n", + " {\"resources\": [\"https://identifiers.org/pubmed/1111111\"]},\n", + " {\"resources\": [\"https://identifiers.org/eco/ECO:0000004\"]},\n", + " ]\n", + " },\n", + " \"resources\": [\"http://identifiers.org/bigg.model/e_coli_core\"],\n", + " }\n", + " ],\n", + "}\n", + "\n", + "cvterms = CVTerms(annotation_dict)\n", + "metabolite.annotation.cvterms = cvterms\n", + "\n" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-BP4wL2JXUlK", + "colab_type": "text" + }, + "source": [ + "Or we can also add data by making separate `CVTerm` objects and then adding them at a particular index (indexing is done for a single qualifier for adding alternative annotation)." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "DEyuH1cqXoar", + "colab_type": "code", + "colab": {} + }, + "source": [ + "cvterm1 = CVTerm(Qualifier.bqb_isDescribedBy, \"http://identifiers.org/doi/10.1128/ecosalplus.10.2.1\")\n", + "cvterm2 = CVTerm(Qualifier.bqb_isDescribedBy, \"http://identifiers.org/ncbigi/gi:16128336\")\n", + "\n", + "metabolite.annotation.cvterms.add_cvterm(cvterm1, 0)\n", + "metabolite.annotation.cvterms.add_cvterm(cvterm1, 1)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "olUCYEdwSw6k", + "colab_type": "text" + }, + "source": [ + "# KeyValuePairs\n", + "\n", + "The KeyValuePair class is used for storing any type of key-value pair data, which is not suitable to store anywhere else in the model" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ENKACjXES9k1", + "colab_type": "code", + "colab": {} + }, + "source": [ + " entry1 = {\n", + " \"id\": \"id1\",\n", + " \"name\": \"abc_xyz\",\n", + " \"key\": \"key1\",\n", + " \"value\": \"45\",\n", + " \"uri\": \"https://tinyurl.com/ybyr7b62\",\n", + " }\n", + " entry2 = KeyValueEntry.from_data({\n", + " \"id\": \"id2\",\n", + " \"name\": \"abc_xyz2\",\n", + " \"key\": \"key2\",\n", + " \"value\": \"48\",\n", + " \"uri\": \"https://tinyurl2.com/ybyr7b62\",\n", + " })\n", + "\n", + " kvp = KeyValuePairs(entries=[entry1, entry2])\n", + " metabolite.annotation.keyvaluepairs = kvp" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Rl3UV44OTe4Q", + "colab_type": "text" + }, + "source": [ + "# Notes\n", + "The `notes` field under a COBRA component is used to store the notes data. Though it is not a right place to store key-value pairs, but earlier implementation has left many models where notes field have key-value pairs inside it. The current implementation contains a notes string as well as a notes dictionary, both synchronized with each other. One can only update values inside the notes dictioanry, adding new key-value pairs is restricted. Updating the dictionary will update the notes string also (only the key-value pair part). String manipulation, if required, will have to be done manually." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "psrA4ROmU4X6", + "colab_type": "code", + "colab": {} + }, + "source": [ + "notes_str = (\n", + " '\\\n", + "\\n\\\n", + " \\n\\\n", + "
\\n\\\n", + "

Key1 : Value 1

\\n\\\n", + "

Key2 : Value2

\\n\\\n", + "
\\n\\\n", + "

A Heading

\\n\\\n", + "
e_coli_core - Escherichia coli '\n", + " \"str. K-12 substr. MG1655
\\n\\\n", + "
\\n\\\n", + "

Key3 : Value 3

\\n\\\n", + "
\\n\\\n", + " \\n\\\n", + "
\"\n", + ")\n", + "\n", + "metabolite.notes = Notes(notes_str)\n", + "metabolite.notes[\"Key1\"] = \"New Value1\"" + ], + "execution_count": null, + "outputs": [] } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.0" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + ] +}