Skip to content

Commit

Permalink
Merge pull request #112 from eastgenomics/improve_url_value_typing
Browse files Browse the repository at this point in the history
Fix url value typing
  • Loading branch information
mattgarner authored Jul 13, 2022
2 parents f35a463 + 7802cbc commit f61b0ce
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
4 changes: 2 additions & 2 deletions dxapp.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"title": "eggd_generate_variant_workbook",
"summary": "Create Excel workbook from VEP annotated vcf",
"dxapi": "1.0.0",
"version": "2.1.0",
"version": "2.1.1",
"authorizedUsers": [
"org-emee_1"
],
"developers":[
"org-emee_1"
],
"properties": {
"githubRelease": "v2.1.0"
"githubRelease": "v2.1.1"
},
"inputSpec": [
{
Expand Down
25 changes: 25 additions & 0 deletions resources/home/dnanexus/generate_workbook/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import sys

sys.path.append(os.path.abspath(
os.path.join(os.path.realpath(__file__), '../../')
))

from utils.utils import is_numeric


def test_is_numeric():
"""
Tests that all forms of numerical value are correctly identified as
being numeric
"""
numeric_values = ['5', '5.5', '-0.1', '1e-5']
non_numeric_values = ['5,6', '5, 6', '.', '3/4', ]

assert all([is_numeric(x) for x in numeric_values]), (
'some numeric values do not properly evaluate to being numeric'
)

assert all([not is_numeric(x) for x in non_numeric_values]), (
'some non-numeric values wrongly evaluate to being numeric'
)
21 changes: 2 additions & 19 deletions resources/home/dnanexus/generate_workbook/utils/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openpyxl.styles.fills import PatternFill
import pandas as pd

from .utils import is_numeric

# openpyxl style settings
THIN = Side(border_style="thin", color="000000")
Expand Down Expand Up @@ -531,28 +532,10 @@ def set_types(self, worksheet) -> None:
"""
for cells in worksheet.rows:
for cell in cells:
if self.is_numeric(cell.value):
if is_numeric(cell.value):
cell.data_type = 'n'


def is_numeric(self, value) -> bool:
"""
Returns true if given value is in some form numeric
Parameters
----------
value : str
string to check if can be cast to numeric type
Returns
-------
bool
True if value can be numeric
"""
return str(value).lstrip('-').replace('.', '').replace(
'e-', '', 1).replace('e', '').isdigit()


def set_font(self, worksheet) -> None:
"""
Set font to all cells in variant sheet to Calibri
Expand Down
16 changes: 16 additions & 0 deletions resources/home/dnanexus/generate_workbook/utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_numeric(value:str) -> bool:
"""
Returns true if given value is in some form numeric
Parameters
----------
value : str
string to check if can be cast to numeric type
Returns
-------
bool
True if value can be numeric
"""
return str(value).lstrip('-').replace('.', '').replace(
'e-', '', 1).replace('e', '').isdigit()
3 changes: 2 additions & 1 deletion resources/home/dnanexus/generate_workbook/utils/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .columns import splitColumns
from .filters import filter
from .utils import is_numeric


class vcf():
Expand Down Expand Up @@ -483,7 +484,7 @@ def make_hyperlink(self, column, url, value, build):
# If URL is too long just display the value
return value[column]

if any([value[column].endswith(x) for x in ['_AC', '_AF', '_AN']]):
if is_numeric(value[column]):
# return numeric values not wrapped in quotes
return f'=HYPERLINK("{url}", {value[column]})'
else:
Expand Down

0 comments on commit f61b0ce

Please sign in to comment.