Skip to content

Commit

Permalink
Merge pull request #31 from popsim-consortium/petrelharp-patch-1
Browse files Browse the repository at this point in the history
missing `import numpy as np` and other things
  • Loading branch information
andrewkern authored Jul 6, 2024
2 parents 893d351 + 0d2aba9 commit d918141
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions intro_stdpopsim_SMBE2024/Intro_stdpopsim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,32 @@
"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,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.simplefilter(\"ignore\", category=stdpopsim.SLiMScalingFactorWarning)\n",
"warnings.simplefilter(\"ignore\", category=stdpopsim.UnspecifiedSLiMWarning)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -533,6 +559,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",
Expand Down Expand Up @@ -667,7 +694,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",
Expand Down Expand Up @@ -1101,7 +1128,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"
]
},
{
Expand Down Expand Up @@ -1148,6 +1177,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",
Expand All @@ -1164,7 +1195,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",
Expand Down Expand Up @@ -1358,7 +1393,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d918141

Please sign in to comment.