FASTGenomics python helper
Project description
About
This python module handles all common interfaces of your application to the FASTGenomics runtime:
- Input/Output of files
- Parameters
and provides some convenience functions.
Examples
A basic interaction through the fastgenomics
module looks looks this
from fastgenomics.process import FGProcess
app_dir = "/app"
data_dir = "/fastgenomics"
fg = FGProcess(app_dir, data_dir)
# access a parameter
fg.parameters["some_parameter"]
# access an input/ouput file
fg.input["some_input_file.txt"].path
fg.output["some_output_file.txt"].path
Consistency checks
The constructor of FGProcess
will check if all the necessary files
exist and validate if their contents is according to the FASTGenomics
standard. For example, if you make a mistake in the manifest.json
of the app you will get a relevant error when calling FGProcess
.
Reading & Writing AnnData
You can also easily load an AnnData object with
from fastgenomics.external import anndata
# read AnnData
adata = anndata.read_data(
fg, expr="expression_table", cell_metadata="cell_metadata", gene_metadata="gene_metadata")
# write AnnData
anndata.write_data(
fg, adata,
expr="expression_table", cell_metadata="cell_metadata", gene_metadata="gene_metadata")
(in the read_data
the cell_metadata
and gene_metadata
are
optional, in the write_data
all the output names are optional).
note This functionality is kept in a separate submodule, to keep the dependency on scanpy optional.
Parameter checks
Aside from accessing the parameters you can also use the following
function to validate if a parameter fulfills some arbitrary
constraints. The code below raises a ValueError
when
some_parameter
is not larger then zero.
fg.parametres.check(
"some_parameter",
lambda x: x > 0,
'Parameter "some_parameter" must be larger then 0.')
Writing the summary with a jinja2 template
FASTGenomics requires an app to output a summary.md
file, this file
is typically generated using a jinja2
template. This module provides the
following utility function for generating a summary file.
fg.summary.template = "path_to_the_tempalte/summary.md.j2"
fg.summary.write(some_value=1, some_other_value=2)
This generates a summary.md
file in
"[data_dir]/summary/summary.md"
based on the template in
fg.summary.template
passing some_value=1
and some_other_value=2
to the template engine.
Note: The fg.summary.write
function appends a ###
-level section
with the parameter values, with which the app was run.
Internals
The module encapsulates most of its functionality in a single class
FGProcess(app_dir, data_dir)
that is constructed from two paths:
app_dir
, where all the necessary app-related files are (most
importantly, the manifest.json
) and data_dir
, which points to the
directory structure provided by FASTGenomics. The class FGProcess
has the following attributes
app
: contains the interpretedmanifest.json
and the locations of app-related files.parameters
: facilitates the access to parameters provided by the FASTGenomics runtime.input
,output
: represents the input and output files provide by the FASTGenomics runtime.summary
: handles thesummary.md
rendering.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastgenomics-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 500c0883893b5423fa474740981099ca35dd9db3617423fef16d9427862a3755 |
|
MD5 | a3940c1ea95788e71d42329412da39d7 |
|
BLAKE2b-256 | ff904cf2c98b2808fc92e17c1a94b4aa20ed7e955fb373d980ae8d6adf77f0e4 |