SDK

This page describes the software development kit (SDK) for PyPGx.

utils

Exceptions:

AlleleNotFoundError

Raise if specified allele is not present in the allele table.

BundleNotFoundError

Raise if the given path to the pypgx-bundle directory does not exist.

GeneNotFoundError

Raise if specified gene is not present in the gene table.

IncorrectMetadataError

Raised when specified metadata is incorrect.

IncorrectSemanticTypeError

Raised when specified semantic type is incorrect.

NotTargetGeneError

Raise if specified gene is not one of the target genes.

PhenotypeNotFoundError

Raise if specified phenotype is not present in the phenotype table.

SemanticTypeNotFoundError

Raised when specified semantic type is not supported.

VariantNotFoundError

Raise if specified variant is not present in the variant table.

Classes:

Archive(metadata, data)

Class for storing various data.

Functions:

add_cn_samples(target, source, samples)

Add the copy number data of specified samples.

compare_metadata(key, *archives)

Raise IncorrectMetadataError if two or more archives have different values for specified metadata key.

get_bundle_path()

Return the path to the pypgx-bundle directory.

parse_pharmvar(fn)

Parse PharmVar gene data.

simulate_copy_number(target, source, sample, sv)

Simuluate copy number by adding noise to the data of an existing sample.

zipdir(dir, output)

Create a ZIP archive of a directory.

exception pypgx.sdk.utils.AlleleNotFoundError[source]

Raise if specified allele is not present in the allele table.

class pypgx.sdk.utils.Archive(metadata, data)[source]

Class for storing various data.

Parameters
  • metadata (dict) – List of metadata lines.

  • data (data, results, or model) – Data, results, or model.

Methods:

check_metadata(key, value)

Raise IncorrectMetadataError if the archive does not have specified pair of key and value.

check_type(semantic_types)

Raise IncorrectSemanticTypeError if the archive does not have specified semantic type(s).

copy_metadata()

dict : Copy of the metadata.

from_file(fn)

Construct Archive from a ZIP file.

to_file(fn)

Create a ZIP file for the Archive.

Attributes:

type

Semantic type.

check_metadata(key, value)[source]

Raise IncorrectMetadataError if the archive does not have specified pair of key and value.

check_type(semantic_types)[source]

Raise IncorrectSemanticTypeError if the archive does not have specified semantic type(s).

Parameters

semantic_types (str or list) – One or more semantic types.

copy_metadata()[source]

dict : Copy of the metadata.

classmethod from_file(fn)[source]

Construct Archive from a ZIP file.

Parameters

fn (str) – ZIP file.

to_file(fn)[source]

Create a ZIP file for the Archive.

Parameters

fn (str) – ZIP file.

property type

Semantic type.

Type

str

exception pypgx.sdk.utils.BundleNotFoundError[source]

Raise if the given path to the pypgx-bundle directory does not exist.

exception pypgx.sdk.utils.GeneNotFoundError[source]

Raise if specified gene is not present in the gene table.

exception pypgx.sdk.utils.IncorrectMetadataError[source]

Raised when specified metadata is incorrect.

exception pypgx.sdk.utils.IncorrectSemanticTypeError[source]

Raised when specified semantic type is incorrect.

exception pypgx.sdk.utils.NotTargetGeneError[source]

Raise if specified gene is not one of the target genes.

exception pypgx.sdk.utils.PhenotypeNotFoundError[source]

Raise if specified phenotype is not present in the phenotype table.

exception pypgx.sdk.utils.SemanticTypeNotFoundError[source]

Raised when specified semantic type is not supported.

exception pypgx.sdk.utils.VariantNotFoundError[source]

Raise if specified variant is not present in the variant table.

pypgx.sdk.utils.add_cn_samples(target, source, samples)[source]

Add the copy number data of specified samples.

Parameters
  • target (str) – Target archive file with the semantic type CovFrame[CopyNumber].

  • source (str) – Source archive file with the semantic type CovFrame[CopyNumber].

  • samples (str or list, optional) – Specify which samples should be included for analysis by providing a text file (.txt, .tsv, .csv, or .list) containing one sample per line. Alternatively, you can provide a list of samples.

Returns

Target archive the semantic type CovFrame[CopyNumber] with new samples appended.

Return type

pypgx.Archive

pypgx.sdk.utils.compare_metadata(key, *archives)[source]

Raise IncorrectMetadataError if two or more archives have different values for specified metadata key.

pypgx.sdk.utils.get_bundle_path()[source]

Return the path to the pypgx-bundle directory.

This function utilizes the PYPGX_BUNDLE environment variable to ascertain the filesystem location of the pypgx-bundle directory. In cases where the environment variable is not defined, the function defaults to the user’s home directory.

pypgx.sdk.utils.parse_pharmvar(fn)[source]

Parse PharmVar gene data.

Parameters

fn (str) – Gene data directory.

pypgx.sdk.utils.simulate_copy_number(target, source, sample, sv, n=3, mu=0, sigma=0.05)[source]

Simuluate copy number by adding noise to the data of an existing sample.

The method will generate simulated samples by introducing noise to an existing sample in the source archive and then append those to the target archive.

Parameters
  • target (str) – Target archive file with the semantic type CovFrame[CopyNumber].

  • source (str) – Source archive file with the semantic type CovFrame[CopyNumber].

  • sample (str) – Name of the sample.

  • sv (str) – Name of the SV.

  • n (int, default: 1) – Number of samples to simulate. Must be non-negative.

  • mu (float, default: 0) – Mean (“centre”) of the distribution.

  • sigma (float, default: 0.05) – Standard deviation (spread or “width”) of the distribution. Must be non-negative.

Returns

Target archive the semantic type CovFrame[CopyNumber] with simultated samples appended.

Return type

pypgx.Archive

pypgx.sdk.utils.zipdir(dir, output)[source]

Create a ZIP archive of a directory.

Parameters
  • dir (str) – Input directory.

  • output (str) – Output file.