Skip to content

Commit

Permalink
Monorepo (#53)
Browse files Browse the repository at this point in the history
* added initial monorepo set-up

* added database-ci.yaml

* updated database > databases in __init__ and tool.pytest.ini_options

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updated databases-ci.yaml for database > databases name change

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* absolute instead of relative path for databases tests

* black formatted databases sub-package

* flake8 in databases and added path to CI

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* black

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* udpated test path

* udpated test path CI

* more database > databases and specified file in tests directory

* black

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* changed --cov argument to missense_kinase_toolkit/databases directory

* changed relative to absolute reference

* --cov=databases

* specify file

* specify test Python file and remove test sub-directory

* fixed typo

* --cov=./

* removed src directory and pyproject.toml/poetry.lock from outer directory

* removed CI file

* --cov=missense_kinase_toolkit/databases

* moving test to sub-directory and --cov=./

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* install package in right directory

* flake8 for test_databases.py

* using ASAP trick for codecov

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reverting back to shell: bash -l {0}

* removed -n auto --durations=10

* added line break to tests

* added strip to Abl sequence

* added strip to both Abl sequences

* reverted to one line Abl sequence

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* noqa E501 for Abl sequence

* removed boilerplate cookiecutter info

* moved setup.cfg to database

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* .codecov.yml updates

* changing coverage report location

* black, pyproject.toml to outer directory

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixing .coverage.xml location and removign direct test reference

* reverting .codecov.yml and duplicate column widths in setup.cfg

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* added __init__.py file in intermediate missense_kinase_toolkit and tests directories

* created TestDatabases class in test file

* clarified that others are for databases sub-package

* commented out tool.pytest.ini_options and tool.coverage.run options for now

* added python3 -m to pip install instructions:

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jessicaw9910 and pre-commit-ci[bot] authored Sep 18, 2024
1 parent e662b5a commit d280a1a
Show file tree
Hide file tree
Showing 42 changed files with 5,302 additions and 5,169 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/CI.yaml → .github/workflows/databases-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
name: CI
name: databases-ci

on:
# GitHub has started calling new repo's first branch "main" https://github.com/github/renaming
# The cookiecutter uses the "--initial-branch" flag when it runs git-init
push:
branches:
- "main"
paths:
- "missense_kinase_toolkit/databases/**"
pull_request:
branches:
- "main"
paths:
- "missense_kinase_toolkit/databases/**"
schedule:
# Weekly tests run on main by default:
# Scheduled workflows run on the latest commit on the default or base branch.
Expand All @@ -27,9 +31,6 @@ jobs:
steps:
- uses: actions/checkout@v3

# - name: Install poetry
# run: pipx install poetry

- name: Additional info about the build
shell: bash
run: |
Expand All @@ -45,37 +46,35 @@ jobs:
environment-name: test
# conda-forge is the default channel now and does not need to be specified
channels: conda-forge,defaults
# cache: 'poetry'
extra-specs: |
python=${{ matrix.python-version }}
- name: Install package
# conda setup requires this special shell
shell: bash -l {0}
run: |
python -m pip install . --no-deps
# python -m pip install poetry
# python -m venv .venv --copies
# poetry config virtualenvs.create false
# poetry install
python -m pip install ./missense_kinase_toolkit/databases --no-deps
micromamba list
- name: Run tests
# conda setup requires this special shell
shell: bash -l {0}
run: |
pytest -v --cov=missense_kinase_toolkit --cov-report=xml --color=yes tests/
# poetry run pytest -v --cov=missense_kinase_toolkit --cov-report=xml --color=yes tests/
# run each package test suite; append to coverage file
# exit immediately if a command exits with a non-zero status
set -e
# pytest -n auto --durations=10 -v --cov-report=xml --cov-report=term --color=yes \
pytest -v --cov-report=xml --color=yes \
--cov=missense_kinase_toolkit/databases \
missense_kinase_toolkit/databases/missense_kinase_toolkit/databases/tests/
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
fail_ci_if_error: false # optional (default = false)
file: ./coverage.xml
flags: unittests # optional
flags: databases # optional
name: codecov-${{ matrix.os }}-py${{ matrix.python-version }}
# https://github.com/codecov/codecov-action
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true # optional (default = false)
# env:
# slug: choderalab/missense-kinase-toolkit
6 changes: 1 addition & 5 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ dependencies:
- pytest-cov
- codecov

# Pip-only installs
#- pip:
# - codecov

# Other
# Databases
- pandas
- bravado
- requests-cache
Expand Down
10 changes: 6 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
Getting Started
===============

This page details how to get started with missense-kinase-toolkit.
This page details how to get started with missense-kinase-toolkit. We have used a monorepo structure where all sub-packages are contained within the `missense-kinase-toolkit` sub-directory.

Installation
++++++++++++

To install the `databases` sub-package using a virtual environment:

.. code-block:: bash
git clone https://github.com/choderalab/missense-kinase-toolkit.git
cd missense-kinase-toolkit
cd missense-kinase-toolkit/missense-kinase-toolkit/databases
python3 -m venv VE
source VE/bin/activate
pip install -e '.[test,extras]'
python3 -m pip install -e '.[dev,test]'
Alternatively, since we have used `poetry` as our default package manager for this project. Once you have cloned the repository and have either installed `poetry` locally or in your environment of interest, you can install the package by running the following command in the root directory of the repository using the provided `poetry.lock` file and the following command
Alternatively, since we have used `poetry` as our default package manager for this project. Once you have cloned the repository and have either installed `poetry` locally or in your environment of interest, you can install the package by running the following command in the root directory of the sub-package repository using the provided `poetry.lock` file and the following command

.. code-block:: bash
Expand Down
1 change: 1 addition & 0 deletions missense_kinase_toolkit/databases/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# databases
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from importlib.metadata import version

__version__ = version("missense-kinase-toolkit")
__version__ = version("databases")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import abstractmethod, ABC
from abc import ABC, abstractmethod

from bravado.client import SwaggerClient
from bravado.requests_client import RequestsClient

Expand All @@ -15,9 +16,7 @@

class SwaggerAPIClient(ABC):
@abstractmethod
def query_api(
self
) -> SwaggerClient:
def query_api(self) -> SwaggerClient:
"""Query a Swagger API and return result.
Parameters
Expand All @@ -35,9 +34,7 @@ def query_api(

class APIKeySwaggerClient(SwaggerAPIClient, ABC):
@abstractmethod
def maybe_get_token(
self
) -> str | None:
def maybe_get_token(self) -> str | None:
"""Get API token, if available.
Returns
Expand All @@ -48,9 +45,7 @@ def maybe_get_token(
"""
...

def set_api_key(
self
) -> RequestsClient:
def set_api_key(self) -> RequestsClient:
"""Set API key for cBioPortal API.
Returns
Expand All @@ -66,7 +61,7 @@ def set_api_key(
self.instance,
f"Bearer {token}",
param_name="Authorization",
param_in="header"
param_in="header",
)
else:
print("No API token provided")
Expand All @@ -75,5 +70,4 @@ def set_api_key(

class RESTAPIClient(ABC):
@abstractmethod
def query_api(self):
...
def query_api(self): ...
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import logging

import pandas as pd
from bravado.client import SwaggerClient
# from pydantic import BaseModel as PydanticBaseModel
# from dataclasses import dataclass

from missense_kinase_toolkit.databases.api_schema import APIKeySwaggerClient
from missense_kinase_toolkit.databases.config import (
get_cbioportal_instance,
maybe_get_cbioportal_token
maybe_get_cbioportal_token,
)
from missense_kinase_toolkit.databases.io_utils import (
parse_iterabc2dataframe,
save_dataframe_to_csv,
)
from missense_kinase_toolkit.databases.api_schema import APIKeySwaggerClient

# from pydantic import BaseModel as PydanticBaseModel
# from dataclasses import dataclass


logger = logging.getLogger(__name__)


class cBioPortal(APIKeySwaggerClient):
"""Class to interact with the cBioPortal API."""

def __init__(self):
"""Initialize cBioPortal Class object.
Expand Down Expand Up @@ -51,8 +54,8 @@ def query_api(self):
config={
"validate_requests": False,
"validate_responses": False,
"validate_swagger_spec": False
}
"validate_swagger_spec": False,
},
)

return cbioportal_api
Expand All @@ -72,6 +75,7 @@ def get_cbioportal(self):

class Mutations(cBioPortal):
"""Class to get mutations from a cBioPortal study."""

def __init__(
self,
study_id: str,
Expand Down Expand Up @@ -110,20 +114,22 @@ def get_all_mutations_by_study(
study_ids = [study.studyId for study in studies]

if self.study_id in study_ids:
#TODO: add incremental error handling beyond missing study
# TODO: add incremental error handling beyond missing study
muts = self._cbioportal.Mutations.getMutationsInMolecularProfileBySampleListIdUsingGET(
molecularProfileId=f"{self.study_id}_mutations",
sampleListId=f"{self.study_id}_all",
projection="DETAILED"
).result()
projection="DETAILED",
).result()
else:
logging.error(f"Study {self.study_id} not found in cBioPortal instance {self.instance}")
logging.error(
f"Study {self.study_id} not found in cBioPortal instance {self.instance}"
)

return muts

def get_cbioportal_cohort_mutations(
self,
bool_save = False,
bool_save=False,
) -> None:
"""Get cBioPortal cohort mutations and optionally save as a CSV file.
Expand All @@ -135,7 +141,8 @@ def get_cbioportal_cohort_mutations(
Notes
-----
The CSV file will be saved in the output directory specified in the configuration file.
As the "gene" ABC object is nested within the "mutation" ABC object, the two dataframes are parsed and concatenated.
As the "gene" ABC object is nested within the "mutation" ABC object,
the two dataframes are parsed and concatenated.
"""
df_muts = parse_iterabc2dataframe(self._mutations)
Expand All @@ -157,4 +164,5 @@ def get_mutations(self):
"""Get cBioPortal mutations."""
return self._mutations

#TODO: implement clinical annotations class

# TODO: implement clinical annotations class
Loading

0 comments on commit d280a1a

Please sign in to comment.