Skip to main content

Step 1: Get the template

The parsomics project has a template for protein annotation plugins, with all the boilerplate needed to get started with development. This template not only accelerates plugin development, but also helps with sticking to the conventions mentioned in the previous section.

Explanation

The parsomics plugin create command

The parsomics-cli includes a command that creates a local git repository with the template for developing protein annotation plugins. Simply run:

parsomics plugin create <tool-name> <plugin-directory>
tip

Whenever in doubt about using the parsomics-cli, remember you can append the --help option to any subcommand! For example:

parsomics --help
parsomics plugin --help
parsomics plugin create --help

Template source code files

You can browse all template files in the parsomics-plugin-template repository. The source code files (that is, the .py files) of the template are all inside a directory whose name starts with parsomics_plugin_. These files are:

File nameRole summary
validated_file.pyImplements a file validator, whose purpose is to distinguish between the files that should be processed (valid) from those that should not (invalid).
file_factory.pyImplements a file factory, which uses the file validator that was defined in validated_file.py to filter the files that should be processed, among all files inside a certain a directory.
parser.pyImplements a parser, which parses the data in a file and inserts it into the relational database.
processor.pyImplements a processor, tying file_factory.py and parser.py together. It lists all relevant files using the file factory, then creates a parser for each of these files.
populate.pyImplementes a populate function that creates a processor, for the options configured by the user.
plugin_initializer.pyInstantiates the object which is exported by the plugin and serves as an "entry point" to its functionalities.
__init__.pyInitializes the plugin's package.

The boilerplate code in these files is commented out with triple quotes. When creating a plugin, you must remove these triple quotes and edit the code within. Though, the template often generates exactly right code for some of these files, so all you need to do in these cases is removing the triple quotes.

Hands on

  1. Run the following command to generate the template for our parsomics-plugin-interpro plugin:

    parsomics plugin create "Interpro" .

    This command will create the directory ./parsomics-plugin-interpro, with all the files needed to get started with writing the plugin. This tutorial goes over each of these files.

  2. Notice the parsomics-plugin-interpro is already a git repository. Additionally, it already has some unstaged changes. Stage and commit all changes.

    tip

    Make a habit of committing frequently.