.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ASW/ASW_three_pulses.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_ASW_ASW_three_pulses.py: ASW inference - Three pulses model ================================== This example implements inference for the ASW population under a three pulses model of admixture, using the tracts package. Inference is performed using autosomal and X chromosome data, allowing for the specification of sex-biased admixture. To implement this example, we use the following driver file: .. code-block:: yaml samples: directory: ./TrioPhased/ individual_names: [ "NA19625","NA19700","NA19701","NA19703","NA19704","NA19707","NA19711","NA19712","NA19713","NA19818","NA19819", "NA19834","NA19835","NA19900","NA19901","NA19904","NA19908","NA19909","NA19913","NA19914","NA19916","NA19917", "NA19920","NA19921","NA19922","NA19923","NA19982","NA19984","NA20126","NA20127","NA20274","NA20276","NA20278", "NA20281","NA20282","NA20287","NA20289","NA20291","NA20294","NA20296","NA20298","NA20299","NA20314","NA20317", "NA20318","NA20320","NA20321","NA20332","NA20334","NA20339","NA20340","NA20342","NA20346","NA20348","NA20351", "NA20355","NA20356","NA20357","NA20359","NA20362","NA20412"] male_names : [ "NA19700","NA19703","NA19711","NA19818","NA19834","NA19900","NA19904","NA19908","NA19916","NA19920", "NA19922","NA19982","NA19984","NA20126","NA20278","NA20281","NA20291","NA20298","NA20318","NA20340", "NA20342","NA20346","NA20348","NA20351","NA20356","NA20362"] #see Readme_dataprocessing.md for how this was generated filename_format: "{name}_{label}_final.bed" labels: [A, B] #If this field is omitted, 'A' and 'B' will be used by default chromosomes: 1-22 #The chromosomes to use for analysis. Can be specified as a list or a range allosomes: [X] output_filename_format: "ASW_test_output_{label}" log_filename: 'ASW_three_pulses.log' output_directory: ./output_three_pulses/ verbose_log: 1 verbose_screen: 30 log_scale : True start_params: t1: 10 REUR: 0.8 RAFR: 0.9 REUR2: 0.2 t2: 5 t3: 3 REUR_sex_bias: 0.1 REUR2_sex_bias: 0.1 RAFR_sex_bias: 0.1 repetitions: 3 seed: 100 maximum_iterations: 1000 unknown_labels_for_smoothing: ["UNK", "centromere","miscall"] # segments with these labels will be smoother over, that is, will be filled with neighbouring ancestries up to their midpoints. exclude_tracts_below_cm: 2 npts : 50 #fix_parameters_from_ancestry_proportions: ['REUR2', 'RAFR', 'REUR2_sex_bias', 'RAFR_sex_bias'] output_directory: ./output_three_pulses/ ad_model_autosomes: M ad_model_allosomes: DC Complete results from this analysis are saved in the output directory specified in the driver file. Below, we display the optimal parameters estimated from this analysis, as well as the plots illustrating the inferred tract length distributions, compared to the observed histograms, for every source population and chromosome type (autosomes and X chromosome). Optimal parameters ------------------ .. csv-table:: Estimated optimal parameters :file: output_three_pulses/ASW_test_output_optimal_parameters.txt :header-rows: 1 :delim: tab Tract length histograms ----------------------- Autosomal admixture ^^^^^^^^^^^^^^^^^^^ .. image:: output_three_pulses/ASW_test_output_autosomes_all_populations.png :width: 700px :alt: African ancestry tract histogram X chromosome admixture in females ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: output_three_pulses/ASW_test_output_female_allosomes_all_populations.png :width: 700px :alt: European ancestry tract histogram X chromosome admixture in males ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: output_three_pulses/ASW_test_output_male_allosomes_all_populations.png :width: 700px :alt: Native American ancestry tract histogram .. GENERATED FROM PYTHON SOURCE LINES 96-114 .. rst-class:: sphx-glr-script-out .. code-block:: none ------------------------------------------------------------------------------------------------ Running tracts 2.0 with driver file: ASW_three_pulses.yaml Reading data, demographic model and driver specifications... ------------------------------------------------------------------------------------------------ excluding_tracts_below set to 2.0 cM. Ancestries: ['EUR', 'NAT', 'AFR'] Data autosome proportions: [0.19578862 0.03825495 0.76595643] Data allosome proportions: [0.16839124 0.03818939 0.79341937] Model parameters : ['REUR', 'REUR_sex_bias', 't1', 'RAFR', 'RAFR_sex_bias', 't2', 'REUR2', 'REUR2_sex_bias', 't3'] Multiple starting parameters were generated. These will be converted to optimizer units and used for multiple optimization runs. Run | Starting parameters --------------------------------------------------- 1 | [0.8, 0.1, 9.867, 0.9, 0.1, 6.789, 0.2, 0.1, 3.064] 2 | [0.8, 0.1, 9.854, 0.9, 0.1, 6.8, 0.2, 0.1, 2.506] 3 | [0.8, 0.1, 11.99, 0.9, 0.1, 5.966, 0.2, 0.1, 3.074] --------------------------------------------------- Optimization run #1 ----------------------------------------------------------------------------------------- Admixture is modelled with the M model for autosomes and with the DC model for allosomes. Optimization is performed in two steps. Step 1 : Optimizing autosomal likelihood over parameters ['REUR', 't1', 'RAFR', 't2', 'REUR2', 't3']. Iter. Log-likelihood Model parameters Transmission ----------------------------------------------------------------------------------------- 30 , -1215.63 , array([ 0.797778 , 0 , 9.96533 , 0.891678 , 0 , 6.94546 , 0.198058 , 0 , 3.68714 ]), Autosomes 60 , -889.862 , array([ 0.796526 , 0 , 9.58264 , 0.885576 , 0 , 7.3138 , 0.190549 , 0 , 4.30489 ]), Autosomes 90 , -763.181 , array([ 0.786673 , 0 , 9.03934 , 0.880502 , 0 , 7.57498 , 0.166511 , 0 , 4.80616 ]), Autosomes 120 , -727.807 , array([ 0.786846 , 0 , 8.85361 , 0.878754 , 0 , 7.64575 , 0.15868 , 0 , 4.89178 ]), Autosomes 150 , -714.745 , array([ 0.785267 , 0 , 8.84535 , 0.878385 , 0 , 7.67761 , 0.154349 , 0 , 4.94699 ]), Autosomes 180 , -703.543 , array([ 0.783706 , 0 , 8.8365 , 0.877875 , 0 , 7.68805 , 0.150951 , 0 , 4.99474 ]), Autosomes Step 1 completed. ---------------------------------------------------------------------------------------------------------------------------- Step 2 : Optimizing autosomal + allosomal likelihood over parameters : ['REUR_sex_bias', 'RAFR_sex_bias', 'REUR2_sex_bias']. Non-sex-bias parameters fixed at values from previous optimization step. Iter. Log-likelihood Model parameters Transmission ---------------------------------------------------------------------------------------------------------------------------- 210 , -216.981 , array([ 0.783637 , -0.00231255 , 8.837 , 0.87784 , -0.0096321 , 7.68785 , 0.150934 , -0.00136707 , 4.99366 ]), Female allosomes 210 , -96.5433 , array([ 0.783637 , -0.00231255 , 8.837 , 0.87784 , -0.0096321 , 7.68785 , 0.150934 , -0.00136707 , 4.99366 ]), Male allosomes 210 , -703.203 , array([ 0.783637 , -0.00231255 , 8.837 , 0.87784 , -0.0096321 , 7.68785 , 0.150934 , -0.00136707 , 4.99366 ]), Autosomes Step 2 completed. ---------------------------------------------------------------------------------------------------------------------------- Optimization run #2 ----------------------------------------------------------------------------------------- Admixture is modelled with the M model for autosomes and with the DC model for allosomes. Optimization is performed in two steps. Step 1 : Optimizing autosomal likelihood over parameters ['REUR', 't1', 'RAFR', 't2', 'REUR2', 't3']. Iter. Log-likelihood Model parameters Transmission ----------------------------------------------------------------------------------------- 30 , -1536.14 , array([ 0.798213 , 0 , 10.1199 , 0.8867 , 0 , 6.93854 , 0.197798 , 0 , 2.91645 ]), Autosomes 60 , -983.654 , array([ 0.797388 , 0 , 10.0798 , 0.874671 , 0 , 7.69938 , 0.18867 , 0 , 3.3935 ]), Autosomes 90 , -811.131 , array([ 0.79505 , 0 , 9.23515 , 0.863564 , 0 , 7.95468 , 0.166934 , 0 , 3.96751 ]), Autosomes 120 , -779.995 , array([ 0.79503 , 0 , 9.17526 , 0.863572 , 0 , 8.03091 , 0.161757 , 0 , 4.02618 ]), Autosomes Step 1 completed. ---------------------------------------------------------------------------------------------------------------------------- Step 2 : Optimizing autosomal + allosomal likelihood over parameters : ['REUR_sex_bias', 'RAFR_sex_bias', 'REUR2_sex_bias']. Non-sex-bias parameters fixed at values from previous optimization step. Iter. Log-likelihood Model parameters Transmission ---------------------------------------------------------------------------------------------------------------------------- 150 , -215.644 , array([ 0.795049 , -0.00515769 , 9.17703 , 0.863557 , -0.031601 , 8.03271 , 0.16174 , -0.014531 , 4.02589 ]), Female allosomes 150 , -97.6737 , array([ 0.795049 , -0.00515769 , 9.17703 , 0.863557 , -0.031601 , 8.03271 , 0.16174 , -0.014531 , 4.02589 ]), Male allosomes 150 , -779.494 , array([ 0.795049 , -0.00515769 , 9.17703 , 0.863557 , -0.031601 , 8.03271 , 0.16174 , -0.014531 , 4.02589 ]), Autosomes Step 2 completed. ---------------------------------------------------------------------------------------------------------------------------- Optimization run #3 ----------------------------------------------------------------------------------------- Admixture is modelled with the M model for autosomes and with the DC model for allosomes. Optimization is performed in two steps. Step 1 : Optimizing autosomal likelihood over parameters ['REUR', 't1', 'RAFR', 't2', 'REUR2', 't3']. Iter. Log-likelihood Model parameters Transmission ----------------------------------------------------------------------------------------- 30 , -1344.44 , array([ 0.797258 , 0 , 12.0966 , 0.893864 , 0 , 6.61638 , 0.198304 , 0 , 3.49862 ]), Autosomes 60 , -995.334 , array([ 0.792664 , 0 , 11.3806 , 0.882393 , 0 , 6.81238 , 0.188567 , 0 , 4.27351 ]), Autosomes 90 , -821.322 , array([ 0.782795 , 0 , 10.2064 , 0.878202 , 0 , 6.96528 , 0.172819 , 0 , 5.07204 ]), Autosomes 120 , -737.571 , array([ 0.780019 , 0 , 9.62516 , 0.8825 , 0 , 7.1452 , 0.158982 , 0 , 5.38853 ]), Autosomes 150 , -673.49 , array([ 0.774047 , 0 , 8.65556 , 0.884256 , 0 , 7.20062 , 0.147654 , 0 , 5.66046 ]), Autosomes 180 , -667.882 , array([ 0.773252 , 0 , 8.63872 , 0.884272 , 0 , 7.23006 , 0.145465 , 0 , 5.66193 ]), Autosomes 210 , -666.834 , array([ 0.772967 , 0 , 8.63523 , 0.884189 , 0 , 7.2254 , 0.145051 , 0 , 5.66488 ]), Autosomes Step 1 completed. ---------------------------------------------------------------------------------------------------------------------------- Step 2 : Optimizing autosomal + allosomal likelihood over parameters : ['REUR_sex_bias', 'RAFR_sex_bias', 'REUR2_sex_bias']. Non-sex-bias parameters fixed at values from previous optimization step. Iter. Log-likelihood Model parameters Transmission ---------------------------------------------------------------------------------------------------------------------------- 240 , -213.38 , array([ 0.772912 , 0.000273909, 8.63475 , 0.884193 , -0.0038701 , 7.22641 , 0.144932 , 2.96945e-05, 5.66628 ]), Female allosomes 240 , -96.1323 , array([ 0.772912 , 0.000273909, 8.63475 , 0.884193 , -0.0038701 , 7.22641 , 0.144932 , 2.96945e-05, 5.66628 ]), Male allosomes 240 , -666.538 , array([ 0.772912 , 0.000273909, 8.63475 , 0.884193 , -0.0038701 , 7.22641 , 0.144932 , 2.96945e-05, 5.66628 ]), Autosomes Step 2 completed. ---------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------- Results from multiple optimization runs with different starting parameters: ------------------------------------- Run | LogLik | Found parameters ------------------------------------- 1 | -1016.24 | [0.7836, -0.003939, 8.837, 0.8778, -0.03301, 7.688, 0.1509, -0.004883, 4.994] 2 | -1092.78 | [0.795, -0.005173, 9.177, 0.8636, -0.03263, 8.033, 0.1617, -0.01536, 4.026] 3 | -976.034 | [0.7729, 0.0002587, 8.635, 0.8842, -0.004675, 7.226, 0.1449, 2.945e-05, 5.666] ------------------------------------- Final parameters and corresponding likelihood: --------------------------------------------------------------------------------------------------------------------------------------- LogLik | REUR REUR_sex_bias t1 RAFR RAFR_sex_bias t2 REUR2 REUR2_sex_bias t3 --------------------------------------------------------------------------------------------------------------------------------------- -976.034 | 0.7729 0.0002587 8.635 0.8842 -0.004675 7.226 0.1449 2.945e-05 5.666 --------------------------------------------------------------------------------------------------------------------------------------- Results saved to : ./output_three_pulses/ {'destination_dir': PosixPath('/home/runner/work/tracts/tracts/docs/source/auto_examples/ASW/output_three_pulses'), 'table_file': PosixPath('/home/runner/work/tracts/tracts/docs/source/auto_examples/ASW/output_three_pulses/ASW_test_output_optimal_parameters.txt')} | .. code-block:: Python import sys from pathlib import Path sys.path.append('.') from tracts.driver import run_tracts script_path = Path(sys.argv[0]).resolve() driver_filename = "ASW_three_pulses.yaml" run_tracts(driver_filename = driver_filename, script_dir = script_path) # Don't run the code below: for documentation purposes only. from tracts.doc_utils import prepare_example_outputs_for_docs prepare_example_outputs_for_docs("output_three_pulses") .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 43.189 seconds) .. _sphx_glr_download_auto_examples_ASW_ASW_three_pulses.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ASW_three_pulses.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ASW_three_pulses.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ASW_three_pulses.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_