From 516397a817cc5fc1a299cef53efbdbf7d19a047d Mon Sep 17 00:00:00 2001 From: Peter Ralph Date: Sat, 6 Jul 2024 11:09:41 -0700 Subject: [PATCH 1/3] missing `import numpy as np` --- intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb index 58391cf..e12738b 100644 --- a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb +++ b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb @@ -533,6 +533,7 @@ "metadata": {}, "outputs": [], "source": [ + "import numpy as np\n", "contig = species.get_contig(\"chr6\", left=0, right=100000)\n", "# make the DFE apply to the entire contig \n", "contig.add_dfe(intervals=np.array([[0, int(contig.length)]]), DFE=dfe)\n", From f957138ae084b3778947f6f464fe56a155ab2986 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 6 Jul 2024 12:00:28 -0700 Subject: [PATCH 2/3] a few more things --- .../Intro_stdpopsim.ipynb | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb index e12738b..6aff1e7 100644 --- a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb +++ b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb @@ -370,6 +370,17 @@ "ts = engine.simulate(model, contig, samples, slim_scaling_factor=100, seed=1)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import warnings\n", + "warnings.simplefilter(\"ignore\", category=stdpopsim.SLiMScalingFactorWarning)\n", + "warnings.simplefilter(\"ignore\", category=stdpopsim.UnspecifiedSLiMWarning)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -668,7 +679,7 @@ "samples = #fill me!\n", "\n", "\n", - "contig = species.get_contig(\"\", length_multiplier=0.1) #fill me!\n", + "contig = species.get_contig(\"\", length_multiplier=0.001) #fill me!\n", "dfe = species.get_dfe(\"\") #fill me!\n", "exons = species.get_annotations(\"\") #fill me!\n", "exon_intervals = exons.get_chromosome_annotations(\"\") #fill me!\n", @@ -1102,7 +1113,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "now we're ready to do PCA. we'll do the decomposition and then plot, note that allel requires a flattened version of the genotype array above that codes individual genotypes as 0/1/2 according to the number of reference alleles" + "now we're ready to do PCA. we'll do the decomposition and then plot, note that allel requires a flattened version of the genotype array above that codes individual genotypes as 0/1/2 according to the number of reference alleles\n", + "\n", + "note: if you get an error here, you may need to re-run the simulation and try again" ] }, { @@ -1149,6 +1162,8 @@ "import stdpopsim\n", "from progressbar import ProgressBar #This is just to get a progress bar\n", "\n", + "import warnings\n", + "\n", "species = stdpopsim.get_species(\"HomSap\")\n", "model = species.get_demographic_model('OutOfAfrica_3G09')\n", "samples = {\"YRI\": 10, \"CHB\": 10, \"CEU\": 10}\n", @@ -1165,7 +1180,11 @@ "pi_list = []\n", "pbar = ProgressBar() #This is just to get a progress bar\n", "for i in pbar(range(n)):\n", - " ts = engine.simulate(model, contig, samples, slim_scaling_factor=20, slim_burn_in=10)\n", + " with warnings.catch_warnings():\n", + " warnings.simplefilter(\"ignore\", category=stdpopsim.SLiMScalingFactorWarning)\n", + " warnings.simplefilter(\"ignore\", category=stdpopsim.UnspecifiedSLiMWarning)\n", + " warnings.simplefilter(\"ignore\", category=UserWarning)\n", + " ts = engine.simulate(model, contig, samples, slim_scaling_factor=20, slim_burn_in=10)\n", " sample_list = make_sample_list(ts)\n", " pi_list.append(ts.diversity(sample_sets=sample_list))\n", "print('Done simulating {} replicates!'.format(n))\n", From 0d2aba958d76612473ec48698c86c77c37aad797 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 6 Jul 2024 12:05:04 -0700 Subject: [PATCH 3/3] . --- intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb index 6aff1e7..359fcbd 100644 --- a/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb +++ b/intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb @@ -370,6 +370,21 @@ "ts = engine.simulate(model, contig, samples, slim_scaling_factor=100, seed=1)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We're getting a lot of warnings. Don't ignore these!\n", + "At least, don't ignore them until you figure out why they are happening.\n", + "Some of these are because we're using approximations to make the simulations go extra fast;\n", + "the warnings are telling us that the approximations are approximate - so: beware!\n", + "If you're just using these for development (like us) then no worries.\n", + "But, if you use them for production, make sure to evaluate whether the approximations\n", + "are affecting your results!\n", + "\n", + "This will turn off these warnings below:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -1378,7 +1393,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.12.4" } }, "nbformat": 4,