varlens package

Subpackages

Submodules

varlens.fusions module

Supplied fusion RNA -> Isovar evidence -> Topiary protein fragments.

This adapter does not discover fusions from BAMs or infer a coding frame from gene names. Isovar validates the supplied sequence, mappings, references and read observations, retaining every supported frame and unresolved outcome.

varlens.fusions.analyze_fusion(payload, *, alleles=(), epitope_lengths=(8, 9, 10, 11), min_fragments=2, predictor=None)[source]

Return a JSON-serializable reconstruction, fragments and predictions.

payload follows Isovar’s supplied-fusion input contract (fusion, references, reads, optional reference_names). The Sid fixture envelope fields note and original_records are preserved but not passed to Isovar as evidence. Unknown fields are rejected by Isovar.

All coding hypotheses, including ambiguous/partial-CDS hypotheses, become separately identified fragments. Their status is carried onto prediction rows; no hypothesis is selected as the true protein. No alleles/predictor means reconstruction only. predictor may be a configured TopiaryPredictor for a Python caller; otherwise supplied alleles select mhctools.NetMHCpan.

varlens.loci_util module

class varlens.loci_util.Loci(locus_iterator=(), contig_map=None, insertions=())[source]

Bases: object

intersects(locus)[source]
union(other)[source]
varlens.loci_util.add_args(parser)[source]
varlens.loci_util.load_from_args(args)[source]

Return a Loci object giving the loci specified on the command line.

If no loci-related arguments are specified, return None. This makes it possible to distinguish an empty set of loci, for example due to filters removing all loci, from the case where the user didn’t specify any arguments.

varlens.locus module

class varlens.locus.Locus(contig, start, end)[source]

Bases: Locus

A genomic interval in 0-indexed interbase coordinates.

See this blog post for a discussion on coordinate systems:

http://alternateallele.blogspot.com/2012/03/genome-coordinate-conventions.html

static from_inclusive_coordinates(contig, start, end=None)[source]

Given coordinates in 1-based coordinates that are inclusive on start and end, return a Locus instance. Locus instances are always 0-based “interbase” coordinates.

static from_interbase_coordinates(contig, start, end=None)[source]

Given coordinates in 0-based interbase coordinates, return a Locus instance.

property inclusive_end
property inclusive_start
static parse(string)[source]
property pileup_positions

Reference bases needed to query this interval (left anchor for insertions).

property position

If this locus spans a single base, this property gives that position. Otherwise, raises a ValueError.

property positions

A Python range object giving the bases included in this locus.

varlens.locus.chromosome_name_map(references)[source]

Resolve aliases to BAM references, giving exact names priority.

varlens.locus.normalize_contig(contig)[source]

Use Ensembl-style names, preserving alternate and unplaced contigs.

varlens.mhc_binding module

varlens.mhc_binding.binding_affinities(variants, alleles, epitope_lengths=(8, 9, 10, 11))[source]

Return each variant’s lowest mutant-peptide affinity (nM) and allele.

Variants without an affinity prediction have a missing affinity and allele. Topiary’s presentation scores are deliberately excluded from this summary.

varlens.mhc_binding.fragment_predictions(fragments, alleles=(), epitope_lengths=(8, 9, 10, 11), *, predictor=None)[source]

Predict target-overlapping peptides, retaining all fragment metadata.

Unlike the small-variant best-affinity summary, this returns Topiary’s full prediction rows, with score kinds, fragment/sample identity and evidence. Target overlap is not a claim of proteome-wide novelty.

varlens.read_source module

class varlens.read_source.ReadSource(name, filename, read_filters=[])[source]

Bases: object

index_if_needed()[source]
pileups(loci)[source]
read_passes_filters(read)[source]
reads(loci=None)[source]
varlens.read_source.alignment_key(pysam_alignment_record)[source]

Return the identifying attributes of a pysam.AlignedSegment instance. This is necessary since these objects do not support a useful notion of equality (they compare on identify by default).

varlens.read_source.read_key(pysam_alignment_record)[source]

Given a pysam.AlignedSegment instance, return the attributes identifying the read it comes from (not the alignment). There may be more than one alignment for a read, e.g. chimeric and secondary alignments.

varlens.reads_util module

varlens.reads_util.add_args(parser, positional=False)[source]

Extends a commandline argument parser with arguments for specifying read sources.

varlens.reads_util.field_contains(field_name, parsed_value, read)[source]
varlens.reads_util.flatten_header(header)[source]
varlens.reads_util.load_bam(filename, name=None, filters=[])[source]
varlens.reads_util.load_from_args(args)[source]

Given parsed commandline arguments, returns a list of ReadSource objects

varlens.sequence_context module

varlens.sequence_context.variant_context(reference_fasta, contig, inclusive_start, inclusive_end, alt, context_length)[source]

Retrieve the surronding reference region from a variant.

SNVs are canonicalized so the reference base is a pyrmidine (C/T). For indels the reverse complement will still be taken if the first base of the reference is not a pyrmidine, but since the reference will also be reversed, that doesn’t guarantee it will start with a pyrmidine.

Parameters:
reference_fastaFastaReference

reference sequence from pyfaidx package

contigstr

Chromosome of the variant

inclusive_startint

start of the variant in 1-based inclusive coordinates

inclusive_endint

end of the variant in 1-based inclusive coordinates

altstring

alt sequence

context_lengthint

number of bases on either side of the variant to return

Returns:
A tuple of (5’, mutation, 3’) where

5’ - bases immediately 5 prime to the mutation

3’ - bases immediately 3 prime to the mutation

mutation - the ref sequence followed by a > character followed by the

the alt sequence

varlens.support module

varlens.support.allele_support_df(loci, sources)[source]

Returns a DataFrame of allele counts for all given loci in the read sources

varlens.support.allele_support_rows(loci, sources)[source]
varlens.support.variant_support(variants, allele_support_df, ignore_missing=False)[source]

Collect the read evidence support for the given variants.

Parameters:
variantsiterable of varcode.Variant
allele_support_dfdataframe

Allele support dataframe, as output by the varlens-allele-support tool. It should have columns: source, contig, interbase_start, interbase_end, allele, and count (the number of supporting reads).

ignore_missingboolean

If True, variants with no allele counts have zero depth. Otherwise missing counts raise ValueError.

Returns:
pandas.DataFrame

Rows are variants; columns have two named levels, measurement and source. Metrics are num_alt, num_ref, num_other, total_depth, alt_fraction, and any_alt_fraction. For example, frame["num_alt"] selects all sources’ alternate-read counts.

varlens.util module

class varlens.util.PrefixedArgumentParser(wrapped, prefix)[source]

Bases: object

add_argument(name, *args, **kwargs)[source]
varlens.util.drop_prefix(strings)[source]

Removes common prefix from a collection of strings

varlens.util.expand(value, arg_name, input_name, length)[source]
varlens.util.remove_prefix_from_parsed_args(args, prefix)[source]

varlens.variant_includes module

class varlens.variant_includes.Context(reference, context_num_bases)[source]

Bases: Includeable

static add_args(parser)[source]
columns = ['context_5_prime', 'context_3_prime', 'context_mutation']
classmethod from_args(args)[source]
name = 'variant sequence context'
process_chunk(df)[source]
static requested(args)[source]
string_columns = ['context_5_prime', 'context_3_prime', 'context_mutation']
class varlens.variant_includes.Effect[source]

Bases: Includeable

static add_args(parser)[source]
columns = ['effect', 'effect_candidates']
name = 'variant effect annotations'
process_chunk(df)[source]
static requested(args)[source]
string_columns = ['effect', 'effect_candidates']
class varlens.variant_includes.Gene[source]

Bases: Includeable

static add_args(parser)[source]
columns = ['gene']
name = 'gene annotations'
process_chunk(df)[source]
static requested(args)[source]
string_columns = ['gene']
class varlens.variant_includes.Includeable[source]

Bases: object

columns = None
compute(df, chunk_rows=None)[source]
float_columns = ()
classmethod from_args(args)[source]
process_chunk(df)[source]
string_columns = ()
class varlens.variant_includes.MHCBindingAffinity(hla=None, hla_dataframe=None, donor_to_hla=None)[source]

Bases: Includeable

static add_args(parser)[source]
columns = ['binding_affinity', 'binding_allele']
float_columns = ['binding_affinity']
classmethod from_args(args)[source]
name = 'MHC binding affinity'
noncoding_effects = {"3' UTR", "5' UTR", 'intergenic', 'intronic', 'non-coding-transcript', 'silent'}
process_chunk(df)[source]
static requested(args)[source]
string_columns = ['binding_allele']
static string_to_hla_alleles(s)[source]
class varlens.variant_includes.ReadEvidence(read_sources=None, read_sources_df=None, column_format='{source}_count_{allele_group}', survive_errors=False)[source]

Bases: Includeable

classmethod add_args(parser)[source]
column_name(source, allele_group)[source]
Parameters:
sourcestring

name of the ReadSource

allele_groupstring

one of: num_ref, num_alt, total_depth

Returns:
column namestring
default_column_format = '{source}_count_{allele_group}'
classmethod from_args(args)[source]
name = 'read evidence'
process_chunk(df)[source]
static read_source_names(read_sources=None, read_sources_df=None)[source]
static requested(args)[source]
set_columns()[source]

varlens.variants_util module

varlens.variants_util.add_args(parser, positional=False)[source]
varlens.variants_util.dataframe_row_to_variant(row)[source]
varlens.variants_util.dataframe_to_variants(df)[source]
varlens.variants_util.load_as_dataframe(filename, loader=None, name=None, genome=None, max_variants=None, only_passing=True, metadata_column_prefix='')[source]
varlens.variants_util.load_csv(filename, genome=None)[source]
varlens.variants_util.load_from_args_as_dataframe(args)[source]

Given parsed variant-loading arguments, return a pandas DataFrame.

If no variant loading arguments are specified, return None.

varlens.variants_util.require_small_variants(variants, operation)[source]
varlens.variants_util.variant_loci(variant)[source]

Small-variant interval, or each known SV breakpoint as a single base.

varlens.variants_util.variants_to_dataframe(variants, metadata=None, metadata_column_prefix='', source=None, structural_records=None)[source]

varlens.version module

varlens.version.print_name_and_version()[source]
varlens.version.print_version()[source]

Module contents