Skip to content

Commit

Permalink
FIX: make sure values are of correct type before json.dumping (#26)
Browse files Browse the repository at this point in the history
* FIX: make sure values are of correct type before json.dumping
* update copyright year
* CI updates
  • Loading branch information
misialq authored Jul 12, 2022
1 parent d9dfa9d commit 3cd8ebf
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 89 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ jobs:
with:
python-version: 3.8
- name: install dependencies
run: python -m pip install --upgrade pip
run: pip install -q flake8 https://github.com/qiime2/q2lint/archive/master.zip
- name: lint
run: |
pip install -q https://github.com/qiime2/q2lint/archive/master.zip
q2lint
pip install -q flake8
flake8
run: make lint

rust-test:
runs-on: ubuntu-latest
Expand All @@ -47,11 +43,19 @@ jobs:
with:
# necessary for versioneer
fetch-depth: 0

- name: Hack - template coverage output path
run: echo "COV=coverage xml -o $GITHUB_WORKSPACE/coverage.xml" >> $GITHUB_ENV

# TODO: update this to @v1 when it lands
- uses: qiime2/action-library-packaging@alpha1
with:
package-name: q2-protein-pca
additional-tests: pytest --pyargs q2_protein_pca
# TODO: update this to `released` when tagging release
build-target: staged
additional-tests: ${{ env.COV }}
build-target: dev
library-token: ${{ secrets.LIBRARY_TOKEN }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2021, QIIME 2 development team.
Copyright (c) 2022, QIIME 2 development team.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 0 additions & 2 deletions ci/recipe/conda_build_config.yaml

This file was deleted.

16 changes: 10 additions & 6 deletions ci/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% set data = load_setup_py_data() %}
{% set version = data.get('version') or 'placehold' %}
{% set release = '.'.join(version.split('.')[:2]) %}

package:
name: q2-protein-pca
Expand All @@ -14,7 +13,7 @@ build:

requirements:
build:
- maturin
- maturin ==0.10.3
- rust ==1.51.0

host:
Expand All @@ -27,16 +26,21 @@ requirements:
- pandas
- numpy
- matplotlib
- qiime2 {{ release }}.*
- q2templates {{ release }}.*
- q2-types {{ release }}.*
- q2-alignment {{ release }}.*
- qiime2 {{ qiime2_epoch }}.*
- q2templates {{ qiime2_epoch }}.*
- q2-types {{ qiime2_epoch }}.*
- q2-alignment {{ qiime2_epoch }}.*

test:
requires:
- coverage
- pytest-cov
imports:
- q2_protein_pca
- qiime2.plugins.protein_pca
- aln_ranking
commands:
- pytest --cov q2_protein_pca --pyargs q2_protein_pca

about:
home: https://github.com/bokulich-lab/q2-protein-pca
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_alignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_format.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_pca.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
9 changes: 6 additions & 3 deletions q2_protein_pca/_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down Expand Up @@ -27,14 +27,17 @@ def _generate_spec(plot_values: pd.DataFrame,
x_col_name: str,
y_col_name: str,
sequence_ids: list) -> dict:
# replace NaNs
plot_values = plot_values.replace({np.nan: None})
# convert types to object (json.dumps cannot dump pandas' Int64)
plot_values.iloc[:, 5:] = plot_values.iloc[:, 5:].astype(object)
spec = {
'$schema': 'https://vega.github.io/schema/vega/v4.2.json',
'width': 300,
'height': 300,
'data': [
{'name': 'values',
'values': plot_values.replace(
{np.nan: None}).to_dict(orient='records')},
'values': plot_values.to_dict(orient='records')},
],
'scales': [
{'name': 'xScale',
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_ranking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_transformer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/plugin_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
139 changes: 91 additions & 48 deletions q2_protein_pca/tests/data/expected_spec.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from copy import deepcopy

EXPECTED_SPEC = {
'$schema': 'https://vega.github.io/schema/vega/v4.2.json',
'width': 300,
'height': 300,
'data': [
{'name': 'values',
'values': [{'PC1': 0.0, 'PC2': 0.0}, {'PC1': 0.1, 'PC2': 0.2}, {'PC1': -0.5, 'PC2': -0.1}]},
{
'name': 'values',
'values': [
{
'id': 'pos1', 'PC1': 0, 'PC2': 0,
'euclid_dist': 0, 'max_dist': 0.26, 'COL3': 1
},
{
'id': 'pos2', 'PC1': 0.1, 'PC2': 0.2,
'euclid_dist': 0.05, 'max_dist': 0.26, 'COL3': 2
},
{
'id': 'pos3', 'PC1': -0.5, 'PC2': -0.1,
'euclid_dist': 0.26, 'max_dist': 0.26, 'COL3': 3
}
]
},
],
'scales': [
{'name': 'xScale',
'domain': {'data': 'values', 'field': 'PC1'},
'range': 'width'},
{'name': 'yScale',
'domain': {'data': 'values', 'field': 'PC2'},
'range': 'height'}],
{
'name': 'xScale',
'domain': {'data': 'values', 'field': 'PC1'},
'range': 'width'
},
{
'name': 'yScale',
'domain': {'data': 'values', 'field': 'PC2'},
'range': 'height'
}],
'axes': [
{'scale': 'xScale', 'orient': 'bottom', 'title': 'PC1'},
{'scale': 'yScale', 'orient': 'left', 'title': 'PC2'}],
Expand All @@ -30,58 +50,81 @@
"description": "Conservation level [%]",
"value": 90,
"bind": {
"input": "range",
"min": 0,
"max": 100,
"step": 1,
"debounce": 10,
"element": "#conservation-level-slider"
"input": "range",
"min": 0,
"max": 100,
"step": 1,
"debounce": 10,
"element": "#conservation-level-slider"
}
},
{
"name": "sequenceID",
"description": "Sequence ID",
"bind": {
"input": "select",
"options": ["id1", "id2", "id3"],
"element": "#sequence-id-selector"
"input": "select",
"options": ["id1", "id2", "id3"],
"element": "#sequence-id-selector"
}
},
{
"name": "hideMissingPositions",
"description": "Hide missing positions",
"bind": {
"input": "checkbox",
"element": "#hide-positions-selector"
"input": "checkbox",
"element": "#hide-positions-selector"
},
}
],
'marks': [
{'type': 'symbol',
'from': {'data': 'values'},
'encode': {
'hover': {
'fill': {'value': '#d62728'},
'opacity': {'value': 0.8}},
'enter': {
'x': {'scale': 'xScale', 'field': 'PC1'},
'y': {'scale': 'yScale', 'field': 'PC2'}},
'update': {
'fill': [
{
'test': "datum.euclid_dist / datum.max_distance <= (1 - conservationLevel / 100)",
'value': '#3182bd'
},
{'value': 'black'}
],
'opacity': [
{
'test': "datum[sequenceID] == null && hideMissingPositions",
'value': 0.0
},
{'value': 0.8}],
'tooltip': {
'signal': f"{{'title': 'position ' + datum['id'], "
f"'PC1': datum['PC1'], "
f"'PC2': datum['PC2']}}"}
}}}]}
{
'type': 'symbol',
'from': {'data': 'values'},
'encode': {
'hover': {
'fill': {'value': '#d62728'},
'opacity': {'value': 0.8}
},
'enter': {
'x': {'scale': 'xScale', 'field': 'PC1'},
'y': {'scale': 'yScale', 'field': 'PC2'}
},
'update': {
'fill': [
{
'test': "datum.euclid_dist / datum.max_distance <= (1 - conservationLevel / 100)",
'value': '#3182bd'
},
{'value': 'black'}
],
'opacity': [
{
'test': "datum[sequenceID] == null && hideMissingPositions",
'value': 0.0
},
{'value': 0.8}],
'tooltip': {
'signal': f"{{'title': 'position ' + datum['id'], "
f"'PC1': datum['PC1'], "
f"'PC2': datum['PC2']}}"
}
}
}
}]
}

EXPECTED_SPEC_WITH_NANS = deepcopy(EXPECTED_SPEC)
EXPECTED_SPEC_WITH_NANS['data'][0]['values'] = [
{
'id': 'pos1', 'PC1': 0, 'PC2': 0,
'euclid_dist': 0, 'max_dist': 0.26, 'COL3': None
},
{
'id': 'pos2', 'PC1': 0.1, 'PC2': 0.2,
'euclid_dist': 0.05, 'max_dist': 0.26, 'COL3': 2
},
{
'id': 'pos3', 'PC1': -0.5, 'PC2': -0.1,
'euclid_dist': 0.26, 'max_dist': 0.26, 'COL3': 3
}
]
2 changes: 1 addition & 1 deletion q2_protein_pca/tests/test_alignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
2 changes: 1 addition & 1 deletion q2_protein_pca/tests/test_pca.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021, QIIME 2 development team.
# Copyright (c) 2022, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand Down
Loading

0 comments on commit 3cd8ebf

Please sign in to comment.