From ba20e77906f82b2f29652c5d9053e721e97a1ea4 Mon Sep 17 00:00:00 2001
From: Kenzo-Hugo Hillion <kenzo-hugo.hillion1@pasteur.fr>
Date: Wed, 7 Aug 2019 18:07:12 +0200
Subject: [PATCH] change name gene_length to length

---
 .../metagenedb/api/catalog/views/test_gene.py |  2 +-
 .../metagenedb/common/utils/parsers/igc.py    |  2 +-
 .../common/utils/parsers/test_igc.py          |  4 +--
 .../scripts/populate_db/import_igc_data.py    |  2 +-
 .../populate_db/test_import_igc_data.py       | 30 +++++++++----------
 frontend/src/views/Genes.vue                  |  4 +--
 6 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/backend/metagenedb/api/catalog/views/test_gene.py b/backend/metagenedb/api/catalog/views/test_gene.py
index 09d36f0..fb13630 100644
--- a/backend/metagenedb/api/catalog/views/test_gene.py
+++ b/backend/metagenedb/api/catalog/views/test_gene.py
@@ -42,7 +42,7 @@ class TestGenes(TestCase):
 class TestCountWindows(TestCase):
 
     def setUp(self):
-        self.window_col = "gene_length"
+        self.window_col = "length"
         self.df = pd.DataFrame(
             [22, 29, 35],
             columns=[self.window_col]
diff --git a/backend/metagenedb/common/utils/parsers/igc.py b/backend/metagenedb/common/utils/parsers/igc.py
index 684b83b..296ed9b 100644
--- a/backend/metagenedb/common/utils/parsers/igc.py
+++ b/backend/metagenedb/common/utils/parsers/igc.py
@@ -33,7 +33,7 @@ class IGCLineParser(object):
             return {
                 'igc_id': gene_info[0],
                 'gene_id': gene_info[1],
-                'gene_length': gene_info[2],
+                'length': gene_info[2],
                 'gene_completeness_status': gene_info[3],
                 'cohort_origin': gene_info[4],
                 'taxo_phylum': gene_info[5],
diff --git a/backend/metagenedb/common/utils/parsers/test_igc.py b/backend/metagenedb/common/utils/parsers/test_igc.py
index 9bfe4f4..d71a713 100644
--- a/backend/metagenedb/common/utils/parsers/test_igc.py
+++ b/backend/metagenedb/common/utils/parsers/test_igc.py
@@ -9,7 +9,7 @@ class TestIGCLineParser(TestCase):
         raw_data = [
             'gene_id',
             'gene_name',
-            'gene_length',
+            'length',
             'gene_completeness_status',
             'cohort_origin',
             'taxo_phylum',
@@ -26,7 +26,7 @@ class TestIGCLineParser(TestCase):
         expected_dict = {
             'igc_id': raw_data[0],
             'gene_id': raw_data[1],
-            'gene_length': raw_data[2],
+            'length': raw_data[2],
             'gene_completeness_status': raw_data[3],
             'cohort_origin': raw_data[4],
             'taxo_phylum': raw_data[5],
diff --git a/backend/scripts/populate_db/import_igc_data.py b/backend/scripts/populate_db/import_igc_data.py
index 5422b1f..8298a55 100755
--- a/backend/scripts/populate_db/import_igc_data.py
+++ b/backend/scripts/populate_db/import_igc_data.py
@@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
 
 PHYLUM_COL = 'taxo_phylum'
 GENUS_COL = 'taxo_genus'
-SELECTED_KEYS = ['gene_id', 'gene_length', 'kegg_ko', PHYLUM_COL, GENUS_COL]
+SELECTED_KEYS = ['gene_id', 'length', 'kegg_ko', PHYLUM_COL, GENUS_COL]
 
 
 def parse_gene(raw_line, selected_keys=SELECTED_KEYS):
diff --git a/backend/scripts/populate_db/test_import_igc_data.py b/backend/scripts/populate_db/test_import_igc_data.py
index b5b03dc..2a834d6 100644
--- a/backend/scripts/populate_db/test_import_igc_data.py
+++ b/backend/scripts/populate_db/test_import_igc_data.py
@@ -13,7 +13,7 @@ class TestParseGene(TestCase):
         raw_data = [
             'gene_id',
             'gene_name',
-            'gene_length',
+            'length',
             'gene_completeness_status',
             'cohort_origin',
             'taxo_phylum',
@@ -34,7 +34,7 @@ class TestParseGene(TestCase):
         """
         expected_dict = {
             'gene_id': 'gene_name',
-            'gene_length': 'gene_length',
+            'length': 'length',
             'kegg_ko': 'kegg',
             'taxo_phylum': 'taxo_phylum',
             'taxo_genus': 'taxo_genus',
@@ -46,10 +46,10 @@ class TestParseGene(TestCase):
         """
         This test should failed and need to be updated when SELECTED_KEYS are changed
         """
-        selected_keys = ['gene_id', 'gene_length']
+        selected_keys = ['gene_id', 'length']
         expected_dict = {
             'gene_id': 'gene_name',
-            'gene_length': 'gene_length'
+            'length': 'length'
         }
         tested_dict = parse_gene(self.raw_line, selected_keys=selected_keys)
         self.assertDictEqual(tested_dict, expected_dict)
@@ -58,10 +58,10 @@ class TestParseGene(TestCase):
         """
         Unknown key should be ignored
         """
-        selected_keys = ['gene_id', 'gene_length', 'secret_code']
+        selected_keys = ['gene_id', 'length', 'secret_code']
         expected_dict = {
             'gene_id': 'gene_name',
-            'gene_length': 'gene_length'
+            'length': 'length'
         }
         tested_dict = parse_gene(self.raw_line, selected_keys=selected_keys)
         self.assertDictEqual(tested_dict, expected_dict)
@@ -72,15 +72,15 @@ class TestUpsertGene(APITestCase):
     def test_insert_valid_gene_no_kegg(self):
         valid_gene = {
             'gene_id': 'test_gene01',
-            'gene_length': 3556
+            'length': 3556
         }
         upsert_gene(valid_gene)
         self.assertEqual(Gene.objects.all().count(), 1)
 
-    def test_insert_invalid_gene_length(self):
+    def test_insert_invalid_length(self):
         invalid_gene = {
             'gene_id': 'test_gene01',
-            'gene_length': 'wrong_format'
+            'length': 'wrong_format'
         }
         with self.assertRaises(ValidationError) as context:  # noqa
             upsert_gene(invalid_gene)
@@ -88,16 +88,16 @@ class TestUpsertGene(APITestCase):
     def test_update_gene(self):
         valid_gene = {
             'gene_id': 'test_gene01',
-            'gene_length': 3556
+            'length': 3556
         }
         updated_gene = {
             'gene_id': 'test_gene01',
-            'gene_length': 356
+            'length': 356
         }
         upsert_gene(valid_gene)
-        self.assertEqual(Gene.objects.get(gene_id="test_gene01").gene_length, 3556)
+        self.assertEqual(Gene.objects.get(gene_id="test_gene01").length, 3556)
         upsert_gene(updated_gene)
-        self.assertEqual(Gene.objects.get(gene_id="test_gene01").gene_length, 356)
+        self.assertEqual(Gene.objects.get(gene_id="test_gene01").length, 356)
 
 
 class TestSelectTaxonomy(TestCase):
@@ -114,13 +114,13 @@ class TestSelectTaxonomy(TestCase):
     def test_both_unknown(self):
         gene_dict = {
             'gene_id': 'gene',
-            'gene_length': 135,
+            'length': 135,
             'taxo_phylum': 'unknown',
             'taxo_genus': 'unknown'
         }
         expected_dict = {
             'gene_id': 'gene',
-            'gene_length': 135
+            'length': 135
         }
         tested_dict = select_taxonomy(gene_dict)
         self.assertDictEqual(tested_dict, expected_dict)
diff --git a/frontend/src/views/Genes.vue b/frontend/src/views/Genes.vue
index 83b4e7c..65f3689 100644
--- a/frontend/src/views/Genes.vue
+++ b/frontend/src/views/Genes.vue
@@ -22,7 +22,7 @@
             >
               <template v-slot:items="props">
                 <td>{{ props.item.gene_id }}</td>
-                <td class="text-xs">{{ props.item.gene_length }}</td>
+                <td class="text-xs">{{ props.item.length }}</td>
                 <td class="text-xs"></td>
                 <td class="text-xs">{{ props.item.functions[0] }}</td>
               </template>
@@ -48,7 +48,7 @@ export default {
           sortable: false,
           value: 'name',
         },
-        { text: 'Length', value: 'gene_length' },
+        { text: 'Length', value: 'length' },
         { text: 'Taxo', sortable: false },
         { text: 'Functions', value: 'functions', sortable: false },
       ],
-- 
GitLab