hapsburg.hmm_inference ====================== .. py:module:: hapsburg.hmm_inference .. autoapi-nested-parse:: Main Inference Class for HMM. Wrapper for Inerence of Posterior. @ Author: Harald Ringbauer, 2019, All rights reserved Classes ------- .. autoapisummary:: hapsburg.hmm_inference.HMM_Analyze Functions --------- .. autoapisummary:: hapsburg.hmm_inference.prep_3x3matrix hapsburg.hmm_inference.exponentiate_r hapsburg.hmm_inference.print_memory_usage Module Contents --------------- .. py:class:: HMM_Analyze(folder='./Simulated/Example0/', t_model='model', e_model='haploid', p_model='SardHDF5', post_model='Standard', output=True, save=True, cython=True, manual_load=False, lowmem=False, save_fp=True, start=-np.inf, end=np.inf) Bases: :py:obj:`object` Analyze Class for HMMs. This is the main Class, all specific Inference schemes inherit from it and overwrite functions. Contains objects as field for pre-processing, transition as well as emission probabilities. Contains most Parameters (but some of them like the output folders are decided by pre-processing subclass) .. py:attribute:: folder :value: '' .. py:attribute:: output :value: True .. py:attribute:: save :value: True .. py:attribute:: save_fp :value: True .. py:attribute:: n_ref :value: 20 .. py:attribute:: sanity_checks :value: True .. py:attribute:: ref_states :value: [] .. py:attribute:: ob_stat :value: [] .. py:attribute:: pCon :value: [] .. py:attribute:: lowmem :value: False .. py:attribute:: overhang :value: 0 .. py:attribute:: r_map :value: [] .. py:attribute:: pos :value: [] .. py:attribute:: v_path :value: [] .. py:attribute:: posterior :value: [] .. py:attribute:: iid :value: '' .. py:attribute:: ch :value: 0 .. py:attribute:: start .. py:attribute:: end .. py:attribute:: fwd_bkwd :value: 0 .. py:attribute:: e_model :value: 'haploid' .. py:attribute:: t_model :value: 'model' .. py:attribute:: p_model :value: 'SardHDF5' .. py:attribute:: post_model :value: 'Standard' .. py:method:: load_objects(iid='', ch=0, c=0.0) Load all the required Objects in right order .. py:method:: load_secondary_objects(c=0.0) Load all secondary objects (but not the pre-processing one) .. py:method:: load_data(iid='', ch=0) Load the External Data .. py:method:: load_emission_model(c=0.0, pCon=[]) Method to load an Emission Model .. py:method:: load_transition_model() Load the Transition Model .. py:method:: load_preprocessing_model(conPop=[]) .. py:method:: load_postprocessing_model() .. py:method:: prepare_rmap(cm=False, min_gap=1e-10, max_gap=0.05) Return the recombination map [in Morgan] Input: Map Positions [l] Return: Rec. Distance Array [l] cm: Whether input is in centimorgan or morgan min_cap: Minimum Gap between Loci .. py:method:: pre_compute_transition_matrix(t, r_vec, n_ref) Precompute and return the full transition Matrix t full Transition Matrix [k,k]. NO LOG STATE r_vec Map Length of Jumps [l] .. py:method:: calc_posterior(save=True, full=False, in_val=0.0001) Calculate the poserior for each path FULL: Wether to return fwd, bwd as well as tot_ll (Mode for postprocessing) in_val: The Initial Probability to copy from one Ind. .. py:method:: calc_posterior_lowmem(save=True, full=False, in_val=0.0001) same functionality as calc_posterior, but a low-memory implmentation. The emission matrix is not pre-computed, but calculated for each marker on the fly the reference panel is stored in the most compact format possible (aka one bit per allele) .. py:method:: compute_tot_neg_likelihood(c, in_val=0.0001) Calculate the poserior for each path in_val: The Initial Probability to copy from one Ind. .. py:method:: optimze_ll_transition_param(roh_trans_params) Calculate and return the log likelihoods for Transitions Parameters roh_trans_params [m] .. py:method:: optimize_ll_contamination_BFGS(init_c) Find MLE of contamination rate by L-BFGS-B. .. py:method:: optimize_ll_contamANDerr(init_c, init_err) .. py:method:: post_processing(save=True) Do the Postprocessing of ROH Blocks Parameters: See in Postprocessing .. py:method:: mmr_call(windowSize=0.001, save=True) Calculate Maximal Match Rate .. py:function:: prep_3x3matrix(t, n_ref) Prepares the grouped 3x3 Matrix (3rd State: Everything in OTHER ROH State) .. py:function:: exponentiate_r(rates, rec_v) Calculates exponentiation of the rates matrix with rec_v rates: 2D Matrix. rec_v: Array of length l .. py:function:: print_memory_usage() Print the current Memory Usage in mB