lorals package

Submodules

lorals.annotate module

class lorals.annotate.AnnotatedStat(chrom: str, position: int, ref: str, alt: str, ref_count: int, alt_count: int, other_count: int, ref_indel: int, alt_indel: int, name: Optional[str] = None)

Bases: AllelicStat, GenoVar

HEADER: Tuple[str, ...] = ('contig', 'position', 'variantID', 'refAllele', 'altAllele', 'refCount', 'altCount', 'totalCount', 'refIndelCount', 'altIndelCount', 'otherBases', 'rawDepth', 'GENOTYPE', 'GENE_ID', 'GENOTYPE_WARNING', 'BLACKLIST', 'MULTI_MAPPING', 'OTHER_ALLELE_WARNING', 'HIGH_INDEL_WARNING', 'NULL_RATIO', 'BINOM_P', 'BINOM_P_ADJUSTED')
other_threshold: float = 0.8
indel_threshold: float = 0.2
property gene: str

Gene name for this annotated stat

property blacklisted: bool
property warning: bool
property multi_mapping: bool
property null_ratio: float
property pvalue: float
property qvalue: float
property ref_ratio

Reference Ratio

property all_ratio

All ratio

property indel_ratio

Indel ratio

property other_warning

Other allele warning

property indel_warning

High indel warning

lorals.annotate.annotate_bed(stats: Iterable[AnnotatedStat], bedfile: str) Tuple[str, ...]
lorals.annotate.annotate_genes(stats: Iterable[AnnotatedStat], bedfile: str) Tuple[AnnotatedStat, ...]
lorals.annotate.annotate_genotypes(stats: Iterable[AnnotatedStat], vcffile: str) Tuple[AnnotatedStat, ...]
lorals.annotate.bias_stats(stats: Iterable[AnnotatedStat], method: str, coverage: int) Dict[str, Real]

lorals.ase module

ASE-specific utilties

class lorals.ase.AllelicStat(chrom: str, position: int, ref: str, alt: str, ref_count: int, alt_count: int, other_count: int, ref_indel: int, alt_indel: int, name: Optional[str] = None)

Bases: Bpileup

HEADER: Tuple[str, ...] = ('contig', 'position', 'variantID', 'refAllele', 'altAllele', 'refCount', 'altCount', 'totalCount', 'refIndelCount', 'altIndelCount', 'otherBases', 'rawDepth')
classmethod fromstring(string: str, sep: str = '\t') AllelicStat
classmethod frombpileup(var: Bpileup, ref_count: int, alt_count: int, other_count: int, ref_indel: int, alt_indel: int) AllelicStat
print_bpileup() str

Print this AllelicStat as if it was a Bpileup

property ref_count

Counts for reference allele

property alt_count

Counts for alternate allele

property other_count

Counts for other alleles

property ref_indel

Reference indel counts

property alt_indel

Alternate indel counts

property total_count

Total counts

property depth

Total depth

lorals.ase.allelic_stats(var: Bpileup, bamfile: str, window: int = 5, match_threshold: int = 8) AllelicStat

lorals.ase.filter_stats(stats: Iterable[AllelicStat], total_coverage: int = 10, allelic_coverage: int = 5, proportion_match: int = 0.8, proportion_indel: int = 0.8) Tuple[AllelicStat, ...]

Filter ase stats

lorals.asts module

ASTS-specific utilities

lorals.asts.bam_to_bed(bamfile: str, save: bool = False) BedTool

Convert a BAM file to a BED file

lorals.asts.bed_intersect(afile: str, bfile: str, ofile: Optional[str] = None, **kwargs: Optional) BedTool

Intersect two bedfiles

lorals.asts.deduplicate_bpileup(bpileup: str) DataFrame

Deduplicate a BED file

lorals.asts.vcf_bpileup(vcffile: str, pileup: Optional[str] = None) str

Create a BED-like pileup from a VCF file

lorals.cigar module

class lorals.cigar.Cigar(tuples: Iterable[Tuple[int, int]])

Bases: object

blah

oper_map: Dict[int, str] = {0: 'M', 1: 'I', 2: 'D', 3: 'N', 4: 'S', 5: 'H', 6: 'P', 7: '=', 8: 'X', 9: 'B'}

lorals.fancy_logging module

Make logging fancy again

class lorals.fancy_logging.StrippedFormatter(*args, **kwargs)

Bases: Formatter

A formatter where all ANSI formatting is removed

format(record: LogRecord) str

Strip ANSI formatting from log messages

class lorals.fancy_logging.ColoredFormatter(*args, **kwargs)

Bases: Formatter

A colorized formatter for logging

format(record: LogRecord) str

Colorize log messages

lorals.fancy_logging.fmttime(start: float, n: int = 3) float

lorals.features module

class lorals.features.Bpileup(chrom: str, position: int, ref: str, alt: str, name: Optional[str] = None)

Bases: object

A BED-like pileup

The BED-like pileup stores variant information that also allows easy translation to a BED-like file. This allows variants to be worked on via genomic arithmetic

static default_id(chrom: str, position: int, ref: str, alt: str) str

Create a default variant ID

Parameters:
  • chrom (str) – Chromomosome or contig of the variant

  • position (int) – Position of the variant

  • ref (str) – Reference allele

  • alt (str) – Alternate alleles separated by commas

Returns:

The variant ID as ‘%(chrom)s_%(position)s_%(ref)s_%(alt)s’

Return type:

str

classmethod frominterval(interval: Interval) Bpileup

Create a Bpileup from an Interval

bed(default: bool = False) str

Format this Bpileup to a bed4 format

Parameters:

default (bool) – If True, uses the default ID as generated by Bpileup.default_id

Returns:

A string with the information in a BED4 format

Return type:

str

property chrom

Chromsome of this variant

property position

Position of this variant

property dummy

Dummy starting position

property ref

Reference allele

property alt

Alternate variant(s)

property alts

Alternate variant(s) as a string

property name

Variant name/ID

property default

Standardized default ID

lorals.features.iter_var(df: DataFrame) Iterable[Bpileup]

Yield Bpileups from a data frame

lorals.features.write_bed(bpileups: Iterable[Bpileup], default: bool = False, ofile: Optional[str] = None) str

lorals.maths module

lorals.maths.median(x: Iterable[Real]) Real

Calculate the median >>> median([1, 2, 3]) 2 >>> median([4, 3, 4, 1, 2]) 3

lorals.maths.percentile(x: Iterable[Real], probs: Union[Real, Iterable[Real]]) Union[Real, Tuple[Real, ...]]

Calculate a percentile >>> percentile(x = (15, 20, 35, 40, 50), probs = 40) 29.0 >>> percentile(x = (15, 20, 35, 40, 50), probs = (5, 40, 95)) (16.0, 29.0, 48.0)

lorals.maths.pvalue_adjust(pvalues: Iterable[float]) Tuple[float, ...]

Adjust p-values using the Benjamin-Hochberg method Basically, it’s like R’s p.adjust(method = ‘fdr’) >>> x = tuple(map(lambda x: round(x, 1), tuple(x * 0.1 for x in range(0, 10)))) >>> pvalue_adjust(x) (0.0, 0.5, 0.6666666666666667, 0.75, 0.8, 0.8333333333333334, 0.8571428571428571, 0.875, 0.888888888888889, 0.9)

lorals.scripts module

Command-line scripts included in LoRALS

lorals.utils module

Some utility functions

lorals.utils.dictsearch(d: Dict[str, Iterable], query: Any) str

Search a dictionary ‘d’ by value ‘query’

lorals.utils.find_open(filename: str) Callable

Figure out which version of open (open vs gzip.open) to use

Standard open cannot handle gzipped files easily. To get around this, this function will return either the gzip.open function if the filename ends in “.gz” or the open function otherwise

Parameters:

filename (str) – A file to find the correct open for

Returns:

An function capable of opening the file described by filename

Return type:

function

lorals.utils.fullpath(path: str) str

Find the full path to a file or directory

lorals.utils.unpack(collection: Iterable) Tuple

Unpack a series of nested lists, sets, or tuples

lorals.utils.where(name: str, flags: int = 1) str
lorals.utils.window(position: int, size: int) slice

Make a window slice

Module contents