From 1b1108a22b5ee1228bea81997fcd566bcf4d504a Mon Sep 17 00:00:00 2001
From: Kenzo-Hugo Hillion <kenzo-hugo.hillion1@pasteur.fr>
Date: Wed, 26 Jun 2019 17:34:03 +0200
Subject: [PATCH] Update documentation to run application

---
 .gitignore                                    |  1 +
 README.md                                     | 29 +++++++++++-
 .../IGC_sample.annotation_OF.summary          |  0
 backend/requirements.txt                      |  8 +++-
 backend/scripts/load_kegg_ko.py               |  6 ++-
 docker-compose.dev.yaml                       |  2 +-
 frontend/src/components/Histogram.vue         | 44 +++++++++----------
 7 files changed, 64 insertions(+), 26 deletions(-)
 rename {dev_data => backend/dev_data}/IGC_sample.annotation_OF.summary (100%)

diff --git a/.gitignore b/.gitignore
index 0b050b1..ef3dcd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ __pycache__/
 .env
 .env_dev
 .idea/
+.vscode
 
 # Backend static files
 backend/public
diff --git a/README.md b/README.md
index b30ddc9..0fc2c1b 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,8 @@ Therefore to run the application you need:
 
 #### Configuration
 
+For `docker-compose`, you need to create a `.env` file: `touch .env`.
+
 The settings of the Django server is based on the `backend/.env` file. You can copy the sample file
 (`cp backend/.env.sample backend/.env`) and fill in the variables.
 
@@ -29,4 +31,29 @@ You can of course customize more of the Django server settings in the `settings`
 
 ### Run the application
 
-#### Populate the database
\ No newline at end of file
+For the moment, only the `docker-compose.dev.yaml` is used. To run the application simply run the command:
+
+```bash
+docker-compose -f docker-compose.dev.yaml up --build
+```
+
+The `--build` option is only necessary during the first usage or when you make changes that need the docker
+container to be built again.
+
+Since directories with source codes are mounted in the containers, changes you make locally should be
+directly reflected on the application.
+
+#### Populate the database
+
+You have a set of scripts available within the `backend/scripts` directory that you can execute directly
+from within the container. First identify the container ID corresponding to the backend with `docker ps` command. Then you can execute a bash terminal within the container and execute the scripts you want:
+
+```bash
+docker exec -it YOURCONTAINER_ID bash
+root@YOURCONTAINER_ID:/code# python scripts/script.py
+```
+
+For the moment you can:
+
+* Import all kegg orthologies with `load_kegg.py`: It directly fetch all KEGGs KO from the KEGG REST API.
+* Import genes from IGC catalog from the [annotation file](ftp://ftp.cngb.org/pub/SciRAID/Microbiome/humanGut_9.9M/GeneAnnotation/IGC.annotation_OF.summary.gz). You can a small part of this annotation file in the `dev_data` folder.
diff --git a/dev_data/IGC_sample.annotation_OF.summary b/backend/dev_data/IGC_sample.annotation_OF.summary
similarity index 100%
rename from dev_data/IGC_sample.annotation_OF.summary
rename to backend/dev_data/IGC_sample.annotation_OF.summary
diff --git a/backend/requirements.txt b/backend/requirements.txt
index 6100e13..deec47d 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -1,3 +1,5 @@
+certifi==2019.6.16
+chardet==3.0.4
 Django==2.2.1
 django-cors-headers==3.0.2
 django-environ==0.4.5
@@ -5,10 +7,14 @@ django-extensions==2.1.7
 django-filter==2.1.0
 djangorestframework==3.9.4
 djangorestframework-jwt==1.11.0
+idna==2.8
 numpy==1.16.4
 pandas==0.24.2
 psycopg2==2.8.2
 PyJWT==1.7.1
+python-dateutil==2.8.0
 pytz==2019.1
+requests==2.22.0
 six==1.12.0
-sqlparse==0.3.0
\ No newline at end of file
+sqlparse==0.3.0
+urllib3==1.25.3
diff --git a/backend/scripts/load_kegg_ko.py b/backend/scripts/load_kegg_ko.py
index c0b6952..7222c28 100755
--- a/backend/scripts/load_kegg_ko.py
+++ b/backend/scripts/load_kegg_ko.py
@@ -37,7 +37,11 @@ def parse_ko(line):
     """
     content = line.split('\t')
     function_id = content[0].split(':')[1]
-    names = content[1].split(';')
+    if ';' in content[1]:
+        names = content[1].split(';')
+    else:
+        _LOGGER.warning(f"Parsing issue with {function_id}, corresponding line: {line}")
+        names = [content[1], '']  # Ugly fix to handle one specific case with no name: K23479
     if '[EC:' in names[1]:
         ec_number = names[1].split('[EC:')[1].rstrip(']')
     else:
diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml
index e06183b..40ead5c 100644
--- a/docker-compose.dev.yaml
+++ b/docker-compose.dev.yaml
@@ -33,7 +33,7 @@ services:
     build:
       context: ./frontend
     volumes:
-      - ./frontend:/app:ro
+      - ./frontend:/app
       - '/app/node_modules'
     ports:
       - "8080:8080"
diff --git a/frontend/src/components/Histogram.vue b/frontend/src/components/Histogram.vue
index 1740393..27e6d51 100644
--- a/frontend/src/components/Histogram.vue
+++ b/frontend/src/components/Histogram.vue
@@ -8,32 +8,32 @@
 import Chart from 'chart.js';
 
 export default {
-	props: {
-		geneLengthData: {
-			type: Object,
-			required: true
-		}
-	},
-	updated() {
-		this.createChart('histogram');
-	},
-	methods: {
+  props: {
+    geneLengthData: {
+      type: Object,
+      required: true,
+    },
+  },
+  updated() {
+    this.createChart('histogram');
+  },
+  methods: {
     createChart(chartId) {
       const ctx = document.getElementById(chartId);
       const histoData = {
-      	labels: this.geneLengthData.labels,
-      	datasets:[
-      		{
-      			label: 'Number of genes',
-      			data: this.geneLengthData.counts
-      		}
-      	]
-      }
+        labels: this.geneLengthData.labels,
+        datasets: [
+          {
+            label: 'Number of genes',
+            data: this.geneLengthData.counts,
+          },
+        ],
+      };
       const myChart = new Chart(ctx, {
         type: 'bar',
         data: histoData,
       });
-    }
-  }
-}
-</script>
\ No newline at end of file
+    },
+  },
+};
+</script>
-- 
GitLab