Skip to main content

FASTGenomics python helper

Project description

pypi-shield travis-shield docs-shield

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_directory/"
data_dir = "data_directory/"
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 content is according to the FASTGenomics standard. For example, if you make a mistake in the manifest.json 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(
            expr=fg.input["expression_matrix"],
            gene_meta=fg.input["genes"],
            cell_meta=fg.input["cells"],
        )

# write AnnData
anndata.write(
        adata,
        expr=fg.output["expression_matrix"],
        gene_meta=fg.output["genes_output"],
        cell_meta=fg.output["cells_output"],
    )

In the read the cell_metadata and gene_metadata are optional, in the write all the outputs 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 interpreted manifest.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 the summary.md rendering.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastgenomics-2.0.7.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastgenomics-2.0.7-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file fastgenomics-2.0.7.tar.gz.

File metadata

  • Download URL: fastgenomics-2.0.7.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.18.4

File hashes

Hashes for fastgenomics-2.0.7.tar.gz
Algorithm Hash digest
SHA256 8b05b90626ff8ad73ccf4f8aec246a8388ce03ce292d8d2b2d2c8976f679aaaf
MD5 63ee682a7c842493a241d8a2ca9e0e0b
BLAKE2b-256 5dc854e501720f7d03287310ce49074166bd1be06ad3422ab3c0d860b6307d62

See more details on using hashes here.

File details

Details for the file fastgenomics-2.0.7-py3-none-any.whl.

File metadata

  • Download URL: fastgenomics-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.18.4

File hashes

Hashes for fastgenomics-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b97fdc3e00d776b32084e2124bb993a416c12ed5d99b19716fbf0ca35fe985e8
MD5 fa7cf02dfd9755771eec581f6942fbb5
BLAKE2b-256 0831d93a6ed7a02dfb43499cf750b5c44cbca2ef9187bf415a859f764bcad8fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page