From 6951429c2810f860bf59ec1d9ed66b7bbb9767b4 Mon Sep 17 00:00:00 2001 From: loeswerkman Date: Fri, 1 Oct 2021 17:53:11 +0200 Subject: [PATCH 1/4] Add source to VOG when creating new variants --- src/inc-js-variants.php | 20 ++++++++++++++++--- src/install/inc-sql-tables.php | 6 ++++-- src/variants.php | 35 ++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/inc-js-variants.php b/src/inc-js-variants.php index 182d7b926..57674e518 100644 --- a/src/inc-js-variants.php +++ b/src/inc-js-variants.php @@ -4,14 +4,15 @@ * LEIDEN OPEN VARIATION DATABASE (LOVD) * * Created : 2011-11-08 - * Modified : 2020-07-23 - * For LOVD : 3.0-25 + * Modified : 2020-10-01 + * For LOVD : 3.5-pre-02 * * Copyright : 2004-2020 Leiden University Medical Center; http://www.LUMC.nl/ * Programmers : Ivar C. Lugtenburg * Ivo F.A.C. Fokkema * Daan Asscheman * M. Kroon + * L. Werkman * * * This file is part of LOVD. @@ -32,7 +33,7 @@ *************/ header('Content-type: text/javascript; charset=UTF-8'); -header('Expires: ' . date('r', time()+(180*60))); +// header('Expires: ' . date('r', time()+(180*60))); define('AJAX_FALSE', '0'); define('AJAX_TRUE', '1'); @@ -179,6 +180,19 @@ function lovd_convertPosition (oElement) // Function that can map a variant to other transcripts or the genome. var oThisDNA = $(oElement).siblings('input:first'); + var oVariantSource = $('input[name$="source"]'); + if (oVariantSource.val() == "") { + var sSource = ""; + alert(oThisDNA.attr("name")); + alert(oThisDNA.attr("name").indexOf("VariantOnTranscript")); + if (oThisDNA.attr("name").indexOf("VariantOnTranscript") >= 0) { + sSource = "VOT"; + } else { + pos = oThisDNA.attr("name").lastIndexOf("/"); + sSource = oThisDNA.attr("name").substr(pos + 1); + } + oVariantSource.val(sSource); + } var oAllDNA = $('input[name$="_VariantOnTranscript/DNA"]'); $(oAllDNA).removeClass().siblings('img:first').attr({ src: 'gfx/trans.png', diff --git a/src/install/inc-sql-tables.php b/src/install/inc-sql-tables.php index ad44f181a..e98e98fe5 100644 --- a/src/install/inc-sql-tables.php +++ b/src/install/inc-sql-tables.php @@ -4,13 +4,14 @@ * LEIDEN OPEN VARIATION DATABASE (LOVD) * * Created : 2009-10-22 - * Modified : 2021-04-22 - * For LOVD : 3.0-27 + * Modified : 2021-10-01 + * For LOVD : 3.5-pre-02 * * Copyright : 2004-2021 Leiden University Medical Center; http://www.LUMC.nl/ * Programmers : Ivo F.A.C. Fokkema * Ivar C. Lugtenburg * M. Kroon + * L. Werkman * * * This file is part of LOVD. @@ -351,6 +352,7 @@ position_g_start INT(10) UNSIGNED, position_g_end INT(10) UNSIGNED, type VARCHAR(10), + source VARCHAR(4), mapping_flags TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, average_frequency FLOAT, owned_by SMALLINT(5) UNSIGNED ZEROFILL, diff --git a/src/variants.php b/src/variants.php index 4cf163ded..52dde43f2 100644 --- a/src/variants.php +++ b/src/variants.php @@ -4,8 +4,8 @@ * LEIDEN OPEN VARIATION DATABASE (LOVD) * * Created : 2010-12-21 - * Modified : 2021-08-13 - * For LOVD : 3.0-27 + * Modified : 2021-10-01 + * For LOVD : 3.5-pre-02 * * Copyright : 2004-2021 Leiden University Medical Center; http://www.LUMC.nl/ * Programmers : Ivar C. Lugtenburg @@ -14,6 +14,7 @@ * Zuotian Tatum * Daan Asscheman * M. Kroon + * L. Werkman * * * This file is part of LOVD. @@ -805,7 +806,7 @@ function(sData) { if (!lovd_error()) { // Prepare the fields to be used for both genomic and transcript variant information. $aFieldsGenome = array_merge( - array('allele', 'effectid', 'chromosome', 'position_g_start', 'type', 'position_g_end', 'owned_by', 'statusid', 'created_by', 'created_date'), + array('allele', 'effectid', 'chromosome', 'position_g_start', 'type', 'source', 'position_g_end', 'owned_by', 'statusid', 'created_by', 'created_date'), $_DATA['Genome']->buildFields()); // Prepare values. @@ -823,6 +824,31 @@ function(sData) { $_POST['type'] = NULL; } + // Add the source of the variant if a source can be found. + if (empty($_POST['source'])) { + // If nothing is given, the source is set to null, meaning that the source is unknown. + unset($aFieldsGenome[array_search('source', $aFieldsGenome)]); + + } elseif ($_POST['source'] == 'VOT') { + // If the source is not a genome, but there is something given, we know it is a transcript. + // A transcript is described by adding an empty string as the source of the variant. + $_POST['source'] = ''; + + } else { + // If the source of the variant is not a transcript, it is a genome build. + // We will then send the ID of this genome build to the database. + $sColumnSuffix = substr(strrchr($_POST['source'], '/'), 1); + if ($sColumnSuffix == 'DNA') { + $sColumnSuffix = ''; + } + + // Get the ID by its column suffix and give this as the source. + $sID = $_DB->query( + 'SELECT id FROM ' . TABLE_GENOME_BUILDS . + 'WHERE column_suffix = ?', array($sColumnSuffix))->fetchColumn(); + $_POST['source'] = $sID; + } + $_POST['owned_by'] = ($_AUTH['level'] >= LEVEL_CURATOR? $_POST['owned_by'] : $_AUTH['id']); $_POST['statusid'] = ($_AUTH['level'] >= LEVEL_CURATOR? $_POST['statusid'] : STATUS_IN_PROGRESS); $_POST['created_by'] = $_AUTH['id']; @@ -932,7 +958,8 @@ function(sData) { lovd_includeJS('inc-js-custom_links.php'); // Table. - print('
' . "\n"); + print(' ' . "\n" . + ' ' . "\n"); // Array which will make up the form table. $aForm = array_merge( From dfcbb786d6b8367bff8713677dc692fe6c4cf85c Mon Sep 17 00:00:00 2001 From: loeswerkman Date: Tue, 5 Oct 2021 10:48:45 +0200 Subject: [PATCH 2/4] Add source to existing VOG table when upgrading LOVD --- src/inc-js-variants.php | 2 +- src/inc-upgrade.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/inc-js-variants.php b/src/inc-js-variants.php index 57674e518..e4839b36a 100644 --- a/src/inc-js-variants.php +++ b/src/inc-js-variants.php @@ -33,7 +33,7 @@ *************/ header('Content-type: text/javascript; charset=UTF-8'); -// header('Expires: ' . date('r', time()+(180*60))); +header('Expires: ' . date('r', time()+(180*60))); define('AJAX_FALSE', '0'); define('AJAX_TRUE', '1'); diff --git a/src/inc-upgrade.php b/src/inc-upgrade.php index f1793dbdf..35e5a43a0 100644 --- a/src/inc-upgrade.php +++ b/src/inc-upgrade.php @@ -833,6 +833,14 @@ function lovd_addConditionalSQL ($sCondition, $aConditionArgs, $sSQL) VALUES ("' . $_CONF['refseq_build'] . '", "' . $_CONF['refseq_build'] . ' / ' . $_SETT['human_builds'][$_CONF['refseq_build']]['ncbi_name'] . '", 0, NOW())', ), + '3.5-pre-03' => array( + 'ALTER TABLE ' . TABLE_VARIANTS . + 'ADD COLUMN source VARCHAR(4) ', + 'UPDATE ' . TABLE_VARIANTS . 'AS v' . + ' SET source = (SELECT id FROM ' . TABLE_GENOME_BUILDS . + ' WHERE column_suffix = "")' . + ' WHERE v.id NOT IN (SELECT id FROM ' . TABLE_VARIANTS_ON_TRANSCRIPTS . ')', + ), ); if ($sCalcVersionDB < lovd_calculateVersion('3.0-alpha-01')) { From 49bf4a1302c2f5bef24bca62cb2efd609f556580 Mon Sep 17 00:00:00 2001 From: loeswerkman Date: Tue, 5 Oct 2021 11:55:22 +0200 Subject: [PATCH 3/4] Apply fixes after comments on pull request --- src/inc-init.php | 2 +- src/inc-js-variants.php | 2 -- src/inc-upgrade.php | 10 ++++------ src/variants.php | 8 ++------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/inc-init.php b/src/inc-init.php index 3c7f35bd0..21ea46176 100644 --- a/src/inc-init.php +++ b/src/inc-init.php @@ -174,7 +174,7 @@ $_SETT = array( 'system' => array( - 'version' => '3.5-pre-02', + 'version' => '3.5-pre-03', ), 'user_levels' => array( diff --git a/src/inc-js-variants.php b/src/inc-js-variants.php index e4839b36a..42625925f 100644 --- a/src/inc-js-variants.php +++ b/src/inc-js-variants.php @@ -183,8 +183,6 @@ function lovd_convertPosition (oElement) var oVariantSource = $('input[name$="source"]'); if (oVariantSource.val() == "") { var sSource = ""; - alert(oThisDNA.attr("name")); - alert(oThisDNA.attr("name").indexOf("VariantOnTranscript")); if (oThisDNA.attr("name").indexOf("VariantOnTranscript") >= 0) { sSource = "VOT"; } else { diff --git a/src/inc-upgrade.php b/src/inc-upgrade.php index 35e5a43a0..c71d0c714 100644 --- a/src/inc-upgrade.php +++ b/src/inc-upgrade.php @@ -834,12 +834,10 @@ function lovd_addConditionalSQL ($sCondition, $aConditionArgs, $sSQL) $_SETT['human_builds'][$_CONF['refseq_build']]['ncbi_name'] . '", 0, NOW())', ), '3.5-pre-03' => array( - 'ALTER TABLE ' . TABLE_VARIANTS . - 'ADD COLUMN source VARCHAR(4) ', - 'UPDATE ' . TABLE_VARIANTS . 'AS v' . - ' SET source = (SELECT id FROM ' . TABLE_GENOME_BUILDS . - ' WHERE column_suffix = "")' . - ' WHERE v.id NOT IN (SELECT id FROM ' . TABLE_VARIANTS_ON_TRANSCRIPTS . ')', + 'ALTER TABLE ' . TABLE_VARIANTS . ' ADD COLUMN source VARCHAR(4) AFTER type', + 'UPDATE ' . TABLE_VARIANTS . ' AS vog' . + ' SET source = (SELECT id FROM ' . TABLE_GENOME_BUILDS . ' WHERE column_suffix = "")' . + ' WHERE vog.id NOT IN (SELECT id FROM ' . TABLE_VARIANTS_ON_TRANSCRIPTS . ')', ), ); diff --git a/src/variants.php b/src/variants.php index 52dde43f2..2dc1525cf 100644 --- a/src/variants.php +++ b/src/variants.php @@ -830,17 +830,13 @@ function(sData) { unset($aFieldsGenome[array_search('source', $aFieldsGenome)]); } elseif ($_POST['source'] == 'VOT') { - // If the source is not a genome, but there is something given, we know it is a transcript. - // A transcript is described by adding an empty string as the source of the variant. + // If the source is a transcript, we describe it with an empty string. $_POST['source'] = ''; } else { // If the source of the variant is not a transcript, it is a genome build. // We will then send the ID of this genome build to the database. - $sColumnSuffix = substr(strrchr($_POST['source'], '/'), 1); - if ($sColumnSuffix == 'DNA') { - $sColumnSuffix = ''; - } + $sColumnSuffix = ($_POST['source'] == 'DNA'? '' : $_POST['source']); // Get the ID by its column suffix and give this as the source. $sID = $_DB->query( From 8a17146a88ab3904d4b8015f5a3bd0a90703b9bd Mon Sep 17 00:00:00 2001 From: Ivo Fokkema Date: Tue, 5 Oct 2021 15:11:09 +0200 Subject: [PATCH 4/4] Fixed missing whitespace and some clarifications. - SQL is prettier and easier to read when aligned. - Since I already forgot an implementation detail, better document it. --- src/inc-upgrade.php | 6 +++--- src/variants.php | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/inc-upgrade.php b/src/inc-upgrade.php index c71d0c714..832bf646a 100644 --- a/src/inc-upgrade.php +++ b/src/inc-upgrade.php @@ -835,9 +835,9 @@ function lovd_addConditionalSQL ($sCondition, $aConditionArgs, $sSQL) ), '3.5-pre-03' => array( 'ALTER TABLE ' . TABLE_VARIANTS . ' ADD COLUMN source VARCHAR(4) AFTER type', - 'UPDATE ' . TABLE_VARIANTS . ' AS vog' . - ' SET source = (SELECT id FROM ' . TABLE_GENOME_BUILDS . ' WHERE column_suffix = "")' . - ' WHERE vog.id NOT IN (SELECT id FROM ' . TABLE_VARIANTS_ON_TRANSCRIPTS . ')', + 'UPDATE ' . TABLE_VARIANTS . ' AS vog + SET source = (SELECT id FROM ' . TABLE_GENOME_BUILDS . ' WHERE column_suffix = "") + WHERE vog.id NOT IN (SELECT id FROM ' . TABLE_VARIANTS_ON_TRANSCRIPTS . ')', ), ); diff --git a/src/variants.php b/src/variants.php index 2dc1525cf..1dc76ad80 100644 --- a/src/variants.php +++ b/src/variants.php @@ -4,8 +4,8 @@ * LEIDEN OPEN VARIATION DATABASE (LOVD) * * Created : 2010-12-21 - * Modified : 2021-10-01 - * For LOVD : 3.5-pre-02 + * Modified : 2021-10-05 + * For LOVD : 3.5-pre-03 * * Copyright : 2004-2021 Leiden University Medical Center; http://www.LUMC.nl/ * Programmers : Ivar C. Lugtenburg @@ -836,12 +836,14 @@ function(sData) { } else { // If the source of the variant is not a transcript, it is a genome build. // We will then send the ID of this genome build to the database. + // We have received the last piece of the field used, which may + // be a genome build (from VOG/DNA/hg38) or "DNA" (from VOG/DNA). $sColumnSuffix = ($_POST['source'] == 'DNA'? '' : $_POST['source']); // Get the ID by its column suffix and give this as the source. $sID = $_DB->query( - 'SELECT id FROM ' . TABLE_GENOME_BUILDS . - 'WHERE column_suffix = ?', array($sColumnSuffix))->fetchColumn(); + 'SELECT id FROM ' . TABLE_GENOME_BUILDS . ' + WHERE column_suffix = ?', array($sColumnSuffix))->fetchColumn(); $_POST['source'] = $sID; }