diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..b4788e8 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,17 @@ +version: 2 + +build: + os: "ubuntu-22.04" + tools: + python: "3.7" + apt_packages: + - gcc + +# Build from the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Explicitly set the version of Python and its requirements +python: + install: + - requirements: requirements-docs.txt \ No newline at end of file diff --git a/docs/examples/cli/introduction_cli.ipynb b/docs/examples/cli/introduction_cli.ipynb index 9df6a01..37df136 100644 --- a/docs/examples/cli/introduction_cli.ipynb +++ b/docs/examples/cli/introduction_cli.ipynb @@ -2,33 +2,39 @@ "cells": [ { "cell_type": "markdown", - "source": [ - "# Introduction" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "# Introduction" + ] }, { "cell_type": "markdown", - "source": [ - "**OpenVariant** offers a command-line interface (CLI) with the main tasks that also can be applied in Python scripts.\n", - "\n", - "On the following command you can check the different options that `openvar` can run." - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "**OpenVariant** offers a command-line interface (CLI) with the main tasks that also can be applied in Python scripts.\n", + "\n", + "On the following command you can check the different options that `openvar` can run." + ] }, { "cell_type": "code", "execution_count": 1, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -55,29 +61,29 @@ "source": [ "%%bash\n", "openvar --help" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Cat*** command" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Cat** command" + ] }, { "cell_type": "code", "execution_count": 2, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -99,29 +105,29 @@ "source": [ "%%bash\n", "openvar cat --help" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Count*** command" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Count** command" + ] }, { "cell_type": "code", "execution_count": 3, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -145,29 +151,29 @@ "source": [ "%%bash\n", "openvar count --help" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Group by*** command" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Group by** command" + ] }, { "cell_type": "code", "execution_count": 4, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -195,29 +201,29 @@ "source": [ "%%bash\n", "openvar groupby --help" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Plugin*** command" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Plugin** command" + ] }, { "cell_type": "code", "execution_count": 5, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -237,13 +243,7 @@ "source": [ "%%bash\n", "openvar plugin --help" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] } ], "metadata": { @@ -267,4 +267,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/examples/cli/main_cli.ipynb b/docs/examples/cli/main_cli.ipynb index f599f3d..2d476e6 100644 --- a/docs/examples/cli/main_cli.ipynb +++ b/docs/examples/cli/main_cli.ipynb @@ -2,49 +2,55 @@ "cells": [ { "cell_type": "markdown", - "source": [ - "# Main tasks" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "# Main tasks" + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "We can run the main tasks that **OpenVariant** offers as a Python package, also, with a shell command. In [Introduction section](./introduction_cli.ipynb) you can check which are the different commands and their options.\n", "\n", "In the following examples we will see a little snip on these tasks.\n", "\n", "--------" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Cat*** command\n", - "\n", - "A simple case of the command:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Cat** command\n", + "\n", + "A simple case of the command:" + ] }, { "cell_type": "code", "execution_count": 1, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -74,58 +80,58 @@ "source": [ "%%bash\n", "openvar cat ../datasets/sample2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Using it with some flags:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "Using it with some flags:" + ] }, { "cell_type": "code", "execution_count": 2, - "outputs": [], - "source": [ - "%%bash\n", - "openvar cat ../datasets/sample2 --output ./output_cat_cmd.tsv --header" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } - } + }, + "outputs": [], + "source": [ + "%%bash\n", + "openvar cat ../datasets/sample2 --output ./output_cat_cmd.tsv --header" + ] }, { "cell_type": "markdown", - "source": [ - "### ***Count*** command\n", - "\n", - "A simple case of the command:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Count** command\n", + "\n", + "A simple case of the command:" + ] }, { "cell_type": "code", "execution_count": 3, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -138,29 +144,29 @@ "source": [ "%%bash\n", "openvar count ../datasets/sample2 -q" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Using it with some flags:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "Using it with some flags:" + ] }, { "cell_type": "code", "execution_count": 4, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -182,17 +188,17 @@ "source": [ "%%bash\n", "openvar count ../datasets/sample2 --group_by \"SYMBOL\" --cores 4 -q" - ], + ] + }, + { + "cell_type": "code", + "execution_count": 5, "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } - } - }, - { - "cell_type": "code", - "execution_count": 5, + }, "outputs": [ { "name": "stdout", @@ -214,31 +220,31 @@ "source": [ "%%bash\n", "openvar count ../datasets/sample2 --group_by \"SYMBOL\" --where \"CANCER == 'ACC'\" --cores 4 -q" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "### ***Group by*** command\n", - "\n", - "A simple case of the command:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "### **Group by** command\n", + "\n", + "A simple case of the command:" + ] }, { "cell_type": "code", "execution_count": 6, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -270,29 +276,29 @@ "source": [ "%%bash\n", "openvar groupby ../datasets/sample2 -g \"CANCER\" --show --header -q" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Using it with some flags:" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "Using it with some flags:" + ] }, { "cell_type": "code", "execution_count": 7, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -306,17 +312,17 @@ "source": [ "%%bash\n", "openvar groupby ../datasets/sample2 -g \"CANCER\" --where \"SYMBOL == 'ATAD3C'\" --cores 4 --show -q" - ], + ] + }, + { + "cell_type": "code", + "execution_count": 8, "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } - } - }, - { - "cell_type": "code", - "execution_count": 8, + }, "outputs": [ { "name": "stdout", @@ -336,45 +342,53 @@ "source": [ "%%bash\n", "openvar groupby ../datasets/sample2 -g \"CANCER\" --script \"grep -E -i '^(B3|ATA)'\" --show --cores 4 -q" - ], + ] + }, + { + "cell_type": "markdown", "metadata": { "collapsed": false, "pycharm": { - "name": "#%%\n" + "name": "#%% md\n" } - } - }, - { - "cell_type": "markdown", + }, "source": [ "\n", - "### ***Plugin*** command\n", + "### **Plugin** command\n", "\n", "_Plugin_ is slightly different than the others commands.\n", "\n", - "On this one we have only one single action: `create`." - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + "On this one we have only one single action: `create`. \n", + "The plugin will use the environment variable `OPENVAR_PLUGIN` directory where to store new plugins.\n", + "\n", + "by default:\n", + "\n", + "```sh\n", + "OPENVAR_PLUGIN=/home/user/.local/share/openvariant\n", + "```\n", + "\n", + "default directory can be changed by exporting a new path to OPENVAR_PLUGIN variable.\n", + "\n", + "i.e.\n", + "```sh\n", + "export OPENVAR_PLUGIN=/my/plugin/path/\n", + "```" + ] }, { "cell_type": "code", "execution_count": null, - "outputs": [], - "source": [ - "%%bash\n", - "openvar plugin create --name add_date --directory ../plugin_system" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } - } + }, + "outputs": [], + "source": [ + "%%bash\n", + "openvar plugin create --name add_date" + ] } ], "metadata": { @@ -398,4 +412,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/examples/tasks/count.ipynb b/docs/examples/tasks/count.ipynb index 15957ef..cd9c55a 100644 --- a/docs/examples/tasks/count.ipynb +++ b/docs/examples/tasks/count.ipynb @@ -2,31 +2,37 @@ "cells": [ { "cell_type": "markdown", - "source": [ - "# _Count_" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "# _Count_" + ] }, { "cell_type": "markdown", - "source": [ - "A simple example where we can find how **count** task works. This task is able with command-line." - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "A simple example where we can find how **count** task works. This task is able with command-line." + ] }, { "cell_type": "code", "execution_count": 1, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "from os import getcwd\n", @@ -35,16 +41,16 @@ "\n", "dataset_folder = f'{dirname(getcwd())}/datasets/sample2'\n", "annotation_path = f'{dirname(getcwd())}/datasets/sample2/annotation.yaml'" - ], + ] + }, + { + "cell_type": "markdown", "metadata": { "collapsed": false, "pycharm": { - "name": "#%%\n" + "name": "#%% md\n" } - } - }, - { - "cell_type": "markdown", + }, "source": [ "`count` task allows us to count the number of rows that result has. It has the following parameters:\n", "\n", @@ -56,17 +62,17 @@ "- `quite` - Do not show the progress meanwhile the parsing is running.\n", "\n", "On the following example we can see a general case of `count` task:" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + ] }, { "cell_type": "code", "execution_count": 2, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -79,16 +85,16 @@ "source": [ "result = count(base_path=dataset_folder, annotation_path=annotation_path, quite=True)\n", "print(f\"Total: {result[0]}\")" - ], + ] + }, + { + "cell_type": "markdown", "metadata": { "collapsed": false, "pycharm": { - "name": "#%%\n" + "name": "#%% md\n" } - } - }, - { - "cell_type": "markdown", + }, "source": [ "One of the parameter on `count` task is `where`. You will be able to apply a conditional filter. The possible operations can be:\n", "\n", @@ -99,18 +105,18 @@ "+ `>=` - More or equal than.\n", "+ `>` - More than.\n", "\n", - "Also, `gropu_by` to group rows on different values of this key. An example of these parameters is the following one:" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + "Also, `group_by` to group rows on different values of this key. An example of these parameters is the following one:" + ] }, { "cell_type": "code", "execution_count": 3, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -125,13 +131,7 @@ "result = count(base_path=dataset_folder, annotation_path=annotation_path, where=\"SYMBOL == 'ATAD3C'\", group_by=\"CANCER\", quite=True)\n", "print(f\"Total: {result[0]}\")\n", "print(f\"Groups and count: {result[1]}\")" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] } ], "metadata": { @@ -155,4 +155,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 311d6a4..5da280c 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,11 +1,21 @@ +============= +Release Notes +============= -********************* -Release notes -********************* +Version history +-------------------- -Version 0.1 -=============================== ++------------+----------+----------------------------------------+----------------------+ +| **Date** | **Ver.** | **Author** | **Comment** | ++------------+----------+----------------------------------------+----------------------+ +| 2024-07-25 | 1.0.0 | `@bbglab `_ | First stable release | +| | | | | ++------------+----------+----------------------------------------+----------------------+ -Version 0.X -=============================== -gfrfrfr \ No newline at end of file +OpenVariant v1.0.0 +================== + +First stable release of OpenVariant. This version includes the following features: + +* Tasks: **find** files, **cat** operation and **group-by**. +* Plugin system: classification of **alteration type**, **alternate allele frequency** getter and **LiftOver** operation. \ No newline at end of file diff --git a/docs/user_guide/cli.rst b/docs/user_guide/cli.rst index 7df0326..a9a743e 100644 --- a/docs/user_guide/cli.rst +++ b/docs/user_guide/cli.rst @@ -97,11 +97,11 @@ Create -------- It will generate the template with required files to apply and run a new plugin with the name stipulated and in the -corresponding directory. +default directory. .. code-block:: bash # Example - openvar plugin create -n reverse_value -d /my_plugins + openvar plugin create -n reverse_value For further details, check :ref:`Command-line interface examples` and you will have a clearer picture on how to use CLI tasks. \ No newline at end of file diff --git a/docs/user_guide/plugin_system.rst b/docs/user_guide/plugin_system.rst index 5e0d920..572caae 100644 --- a/docs/user_guide/plugin_system.rst +++ b/docs/user_guide/plugin_system.rst @@ -19,8 +19,9 @@ visualize how the different classes are connected and composed with **OpenVarian | -As we have mentioned before, the plugin has to be present on the `annotation` file in order to be used. Plugins can be -distributed on different folders where `Builder` will manage to find them and apply the data transformation. +As we have mentioned before, the plugin has to be present on the `annotation` file in order to be used. Custom plugins will be placed in the +folder where the environment variable :bash:`OPENVAR_PLUGIN` points (:bash:`/home/user/.local/share/openvariant/` by default). +The `Builder` will manage to find them and apply the data transformation. Plugins will inherit `Context` and `Plugin` as base classes for each plugin. These classes are described as it follows: **Context** diff --git a/examples/tasks/count.ipynb b/examples/tasks/count.ipynb index 15957ef..cd9c55a 100644 --- a/examples/tasks/count.ipynb +++ b/examples/tasks/count.ipynb @@ -2,31 +2,37 @@ "cells": [ { "cell_type": "markdown", - "source": [ - "# _Count_" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "# _Count_" + ] }, { "cell_type": "markdown", - "source": [ - "A simple example where we can find how **count** task works. This task is able with command-line." - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } - } + }, + "source": [ + "A simple example where we can find how **count** task works. This task is able with command-line." + ] }, { "cell_type": "code", "execution_count": 1, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "from os import getcwd\n", @@ -35,16 +41,16 @@ "\n", "dataset_folder = f'{dirname(getcwd())}/datasets/sample2'\n", "annotation_path = f'{dirname(getcwd())}/datasets/sample2/annotation.yaml'" - ], + ] + }, + { + "cell_type": "markdown", "metadata": { "collapsed": false, "pycharm": { - "name": "#%%\n" + "name": "#%% md\n" } - } - }, - { - "cell_type": "markdown", + }, "source": [ "`count` task allows us to count the number of rows that result has. It has the following parameters:\n", "\n", @@ -56,17 +62,17 @@ "- `quite` - Do not show the progress meanwhile the parsing is running.\n", "\n", "On the following example we can see a general case of `count` task:" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + ] }, { "cell_type": "code", "execution_count": 2, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -79,16 +85,16 @@ "source": [ "result = count(base_path=dataset_folder, annotation_path=annotation_path, quite=True)\n", "print(f\"Total: {result[0]}\")" - ], + ] + }, + { + "cell_type": "markdown", "metadata": { "collapsed": false, "pycharm": { - "name": "#%%\n" + "name": "#%% md\n" } - } - }, - { - "cell_type": "markdown", + }, "source": [ "One of the parameter on `count` task is `where`. You will be able to apply a conditional filter. The possible operations can be:\n", "\n", @@ -99,18 +105,18 @@ "+ `>=` - More or equal than.\n", "+ `>` - More than.\n", "\n", - "Also, `gropu_by` to group rows on different values of this key. An example of these parameters is the following one:" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } + "Also, `group_by` to group rows on different values of this key. An example of these parameters is the following one:" + ] }, { "cell_type": "code", "execution_count": 3, + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -125,13 +131,7 @@ "result = count(base_path=dataset_folder, annotation_path=annotation_path, where=\"SYMBOL == 'ATAD3C'\", group_by=\"CANCER\", quite=True)\n", "print(f\"Total: {result[0]}\")\n", "print(f\"Groups and count: {result[1]}\")" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] } ], "metadata": { @@ -155,4 +155,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/openvariant/annotation/builder.py b/openvariant/annotation/builder.py index 2e6a3c0..206ff7f 100644 --- a/openvariant/annotation/builder.py +++ b/openvariant/annotation/builder.py @@ -249,9 +249,9 @@ def _plugin_builder(x: dict, base_path: str = None) -> PluginBuilder: ctxt = _get_plugin_context(mod) except ModuleNotFoundError: try: - files = list(glob.iglob(f"{os.getcwd()}/**/{x[AnnotationTypes.PLUGIN.value]}", recursive=True)) + files = list(glob.iglob(f"{os.environ['OPENVAR_PLUGIN']}/**/{x[AnnotationTypes.PLUGIN.value]}", recursive=True)) if len(files) == 0: - raise FileNotFoundError(f"Unable to find '{x[AnnotationTypes.PLUGIN.value]}' plugin in '{os.getcwd()}'") + raise FileNotFoundError(f"Unable to find '{x[AnnotationTypes.PLUGIN.value]}' plugin in '{os.environ['OPENVAR_PLUGIN']}'") else: try: for package in files: @@ -263,7 +263,7 @@ def _plugin_builder(x: dict, base_path: str = None) -> PluginBuilder: func = _get_plugin_function(mod) ctxt = _get_plugin_context(mod) except (ImportError, AttributeError): - raise ImportError(f"Unable to import 'run' on the plugin.") + raise ImportError("Unable to import 'run' on the plugin.") except ModuleNotFoundError: raise ModuleNotFoundError(f"Unable to found '{x[AnnotationTypes.PLUGIN.value]}' plugin.") except (ImportError, AttributeError) as e: diff --git a/openvariant/commands/openvar.py b/openvariant/commands/openvar.py index 0150818..1950a94 100644 --- a/openvariant/commands/openvar.py +++ b/openvariant/commands/openvar.py @@ -6,6 +6,7 @@ from openvariant.tasks.count import count as count_task from openvariant.tasks.groupby import group_by as group_by_task from openvariant.tasks.plugin import PluginActions +from openvariant.utils.utils import loadEnvironmentVariables @click.group(context_settings={'help_option_names': ['-h', '--help']}) @@ -13,6 +14,7 @@ def openvar(): """'openvar' is the command-line interface of OpenVariant. Parsing and data transformation of multiple input formats.""" + loadEnvironmentVariables() pass @@ -106,10 +108,9 @@ def groupby(input_path: str, script: str, where: str, group_by: str, cores: int, @openvar.command(name="plugin", short_help='Actions to execute for a plugin: create.') @click.argument('action', type=click.Choice(['create'])) @click.option('--name', '-n', type=click.STRING, help="Name of the plugin.") -@click.option('--directory', '-d', type=click.STRING, help="Directory to reach the plugin.") -def plugin(action, name: str or None, directory: str or None): +def plugin(action, name: str or None): """Actions to apply on the plugin system.""" - PluginActions[action.upper()].value(name, directory) + PluginActions[action.upper()].value(name) if __name__ == "__main__": diff --git a/openvariant/tasks/plugin.py b/openvariant/tasks/plugin.py index 9c2f1e9..163471e 100644 --- a/openvariant/tasks/plugin.py +++ b/openvariant/tasks/plugin.py @@ -8,7 +8,7 @@ from functools import partial -def _add_action(name: str, directory: str = None) -> None: +def _add_action(name: str) -> None: """Create a new plugin It will generate all the required structure for a new plugin (files and folders). @@ -20,7 +20,7 @@ def _add_action(name: str, directory: str = None) -> None: directory : str The path to create the plugin. """ - path = directory if directory is not None else os.getcwd() + path = os.environ['OPENVAR_PLUGIN'] if os.path.exists(f"{path}/{name}"): raise FileExistsError(f"Directory {path}/{name} already exists.") os.mkdir(f"{path}/{name}") diff --git a/openvariant/utils/utils.py b/openvariant/utils/utils.py index 2e9364b..7fc5e2d 100644 --- a/openvariant/utils/utils.py +++ b/openvariant/utils/utils.py @@ -1,8 +1,25 @@ import re +import os +from appdirs import user_data_dir from fnmatch import fnmatch from os.path import basename +ENV_VAR = { + 'OPENVAR_PLUGIN': user_data_dir('openvariant', 'bbglab') +} + +def loadEnvironmentVariables() -> None: + """Load environment variable into the environment.""" + + missing_vars = set(ENV_VAR.keys()).difference(set(os.environ)) + + for env_var in missing_vars: + os.environ[env_var] = ENV_VAR[env_var] + os.makedirs(ENV_VAR[env_var], exist_ok=True) + + return + def check_extension(ext: str, path: str) -> bool: """Check if file matches with the annotation pattern""" return fnmatch(basename(path), ext) if ext[0] == '*' else re.match(ext, basename(path)) is not None diff --git a/requirements-docs.txt b/requirements-docs.txt index 5e4ed10..d9aabbb 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -42,7 +42,7 @@ pyparsing==3.0.9 pyrsistent==0.18.1 python-dateutil==2.8.2 pytz==2022.1 -PyYAML==6.0 +PyYAML==6.0.1 pyzmq==23.2.0 requests==2.28.1 ruamel.yaml==0.16.13 diff --git a/setup.py b/setup.py index c3a6fe4..0517345 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="open-variant", - version="0.7.6", + version="1.0.0", author="BBGLab - Barcelona Biomedical Genomics Lab", author_email='bbglab@irbbarcelona.org', description="OpenVariant provides different functionalities to read, parse and operate different multiple input " @@ -17,7 +17,7 @@ keywords='bioinformatics,openvariant,openvar,bbglab', packages=find_packages(exclude=["tests.*", "tests"]), include_package_data=True, - install_requires=['pyyaml', 'tqdm', 'click', 'pyliftover'], + install_requires=['pyyaml', 'tqdm', 'click', 'pyliftover', 'appdirs'], entry_points={ 'console_scripts': [ 'openvar = openvariant.commands.openvar:openvar', diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..1cbff9a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +from openvariant.utils.utils import loadEnvironmentVariables + +loadEnvironmentVariables() \ No newline at end of file