Skip to content

Commit

Permalink
Merge pull request #44 from sanjaynagi/move-ag3-af1-17-05-24
Browse files Browse the repository at this point in the history
move ag3/af1 to after species selection
  • Loading branch information
sanjaynagi committed May 24, 2024
2 parents 0298543 + 5767f68 commit 7646a80
Show file tree
Hide file tree
Showing 4 changed files with 656 additions and 44 deletions.
18 changes: 10 additions & 8 deletions AnoPrimer/AnoPrimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
from matplotlib import patches
from plotly.subplots import make_subplots

ag3 = malariagen_data.Ag3(url="gs://vo_agam_release/", pre=True)
af1 = malariagen_data.Af1(url="gs://vo_afun_release/", pre=True)


def retrieve_data_resource(species):
assert species in [
"gambiae_sl",
"funestus",
], f"species {species} not recognised, please use 'gambiae_sl' or 'funestus'"
if species == "gambiae_sl":
data_resource = ag3
data_resource = malariagen_data.Ag3(url="gs://vo_agam_release/", pre=True)
elif species == "funestus":
data_resource = af1
data_resource = malariagen_data.Af1(url="gs://vo_afun_release/", pre=True)
return data_resource


Expand Down Expand Up @@ -605,7 +602,9 @@ def plot_primer_locs(
# plot the legend
plt.legend(handles=handles, loc=legend_loc)
if out_dir:
fig.savefig(f"{out_dir}/{assay_name}_primer_locs.png", dpi=300)
fig.savefig(
f"{out_dir}/{assay_name}_primer_locs.png", dpi=300, bbox_inches="tight"
)


def gget_blat_genome(primer_df, assay_type, assembly="anoGam3"):
Expand Down Expand Up @@ -1256,21 +1255,24 @@ def check_my_oligo(
contig = contig.replace("chr", "")
region_span = f"{contig}:{start}-{end}"
print("plotting frequencies in ag3 data")

fig = plot_sequence_frequencies(
data_resource=malariagen_data.Ag3(url="gs://vo_agam_release/", pre=True),
region=region_span,
sample_sets=sample_sets,
sample_query=sample_query,
width=width,
height=height,
)
return fig


def plot_sequence_frequencies(
region, sample_sets=None, sample_query=None, width=700, height=400
data_resource, region, sample_sets=None, sample_query=None, width=700, height=400
):
"""Retrieve frequencies"""

snps = ag3.snp_calls(
snps = data_resource.snp_calls(
region=region, sample_sets=sample_sets, sample_query=sample_query
)
ref_alt_arr = snps["variant_allele"].compute().values.astype(str)
Expand Down
1 change: 1 addition & 0 deletions docs/AnoPrimer-docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ parts:
chapters:
- file: notebooks/api
- file: notebooks/notebooks
- file: notebooks/data_access
- file: notebooks/troubleshooting_contributing
60 changes: 38 additions & 22 deletions notebooks/AnoPrimer-long.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/sanjaynagi/AgamPrimer/blob/main/notebooks/AgamPrimer-long.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/sanjaynagi/AnoPrimer/blob/main/notebooks/AnoPrimer-long.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand All @@ -25,24 +25,40 @@
"outputs": [],
"source": [
"# First, install some packages we require\n",
"! pip install AgamPrimer -q "
"! pip install AnoPrimer -q "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "528ae85d",
"metadata": {
"id": "528ae85d"
},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'AnoPrimer'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Import libraries \u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mAnoPrimer\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmalariagen_data\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mprimer3\u001b[39;00m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'AnoPrimer'"
]
}
],
"source": [
"# Import libraries \n",
"import AgamPrimer\n",
"import AnoPrimer\n",
"import malariagen_data\n",
"import primer3\n",
"import pandas as pd\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"import google.auth\n",
"\n",
"credentials, project = google.auth.default()"
]
},
{
Expand All @@ -53,11 +69,11 @@
"id": "47bde61a"
},
"source": [
"##**[AgamPrimer](https://github.com/sanjaynagi/AgamPrimer): Primer design considering genomic variation in *Anopheles gambiae* s.l and *Anopheles funestus*** \n",
"##**[AnoPrimer](https://github.com/sanjaynagi/AnoPrimer): Primer design considering genomic variation in *Anopheles gambiae* s.l and *Anopheles funestus*** \n",
"**Author**: [Sanjay Curtis Nagi](https://sanjaynagi.github.io/) \n",
"**Email**: sanjay.nagi@lstmed.ac.uk \n",
"\n",
"Welcome to the AgamPrimer notebook. This is the long version of the notebook which designs primers in steps. Alternatively, there is a all-in-one function in a [short version of the notebook](https://colab.research.google.com/github/sanjaynagi/AgamPrimer/blob/main/notebooks/AgamPrimer-short.ipynb).\n",
"Welcome to the AnoPrimer notebook. This is the long version of the notebook which designs primers in steps. Alternatively, there is a all-in-one function in a [short version of the notebook](https://colab.research.google.com/github/sanjaynagi/AnoPrimer/blob/main/notebooks/AnoPrimer-short.ipynb).\n",
"\n",
"We would like to design primers for PCR applications, such as genotyping or gene expression (qPCR). However, single nucleotide polymorphisms (SNPs) in primer binding sites can result in differences or failures in PCR amplification, referred to as null alleles. \n",
"\n",
Expand Down Expand Up @@ -128,9 +144,9 @@
},
"outputs": [],
"source": [
"data_resource = AgamPrimer.retrieve_data_resource(species)\n",
"data_resource = AnoPrimer.retrieve_data_resource(species)\n",
"# Connect to the malariagen_data ag3 API\n",
"contig, target = AgamPrimer.check_and_split_target(species=species, target=primer_target, assay_type=assay_type)\n",
"contig, target = AnoPrimer.check_and_split_target(species=species, target=primer_target, assay_type=assay_type)\n",
"genome_seq = data_resource.genome_sequence(region=contig)\n",
"print(f\"Our genome sequence for {contig} is {genome_seq.shape[0]} bp long\")"
]
Expand All @@ -143,7 +159,7 @@
"id": "144a37ce"
},
"source": [
"Now we need to extract the bit of sequence we need. We will use functions in the [AgamPrimer](https://pypi.org/project/AgamPrimer/) package."
"Now we need to extract the bit of sequence we need. We will use functions in the [AnoPrimer](https://pypi.org/project/AnoPrimer/) package."
]
},
{
Expand All @@ -159,7 +175,7 @@
},
"outputs": [],
"source": [
"target_sequence, gdna_pos, seq_parameters = AgamPrimer.prepare_sequence(\n",
"target_sequence, gdna_pos, seq_parameters = AnoPrimer.prepare_sequence(\n",
" species=species,\n",
" target=target,\n",
" assay_type=assay_type,\n",
Expand Down Expand Up @@ -236,7 +252,7 @@
" # In the same format as above \n",
" }\n",
"\n",
"primer_parameters = AgamPrimer.primer_params(primer_parameters=primer_parameters, assay_type=assay_type, n_primer_pairs=n_primer_pairs, amplicon_size_range=amplicon_size_range) ## adds some parameters depending on assay type"
"primer_parameters = AnoPrimer.primer_params(primer_parameters=primer_parameters, assay_type=assay_type, n_primer_pairs=n_primer_pairs, amplicon_size_range=amplicon_size_range) ## adds some parameters depending on assay type"
]
},
{
Expand Down Expand Up @@ -285,7 +301,7 @@
},
"outputs": [],
"source": [
"AgamPrimer.primer3_run_statistics(primer_dict, assay_type)"
"AnoPrimer.primer3_run_statistics(primer_dict, assay_type)"
]
},
{
Expand All @@ -312,7 +328,7 @@
},
"outputs": [],
"source": [
"primer_df = AgamPrimer.primer3_to_pandas(primer_dict=primer_dict, assay_type=assay_type)\n",
"primer_df = AnoPrimer.primer3_to_pandas(primer_dict=primer_dict, assay_type=assay_type)\n",
"primer_df"
]
},
Expand Down Expand Up @@ -474,7 +490,7 @@
},
"outputs": [],
"source": [
"results_dict = AgamPrimer.plot_primer_snp_frequencies(\n",
"results_dict = AnoPrimer.plot_primer_snp_frequencies(\n",
" species=species,\n",
" primer_df=primer_df,\n",
" gdna_pos=gdna_pos,\n",
Expand Down Expand Up @@ -511,7 +527,7 @@
},
"outputs": [],
"source": [
"AgamPrimer.plot_primer_locs(\n",
"AnoPrimer.plot_primer_locs(\n",
" species=species,\n",
" primer_df=primer_df, \n",
" primer_res_dict=results_dict,\n",
Expand Down Expand Up @@ -567,7 +583,7 @@
"outputs": [],
"source": [
"if species == 'gambiae_sl':\n",
" blat_result_df = AgamPrimer.gget_blat_genome(\n",
" blat_result_df = AnoPrimer.gget_blat_genome(\n",
" primer_df, \n",
" assay_type, \n",
" assembly='anoGam3'\n",
Expand Down Expand Up @@ -596,7 +612,7 @@
"outputs": [],
"source": [
"#view help for function\n",
"AgamPrimer.designPrimers?"
"AnoPrimer.designPrimers?"
]
},
{
Expand All @@ -613,7 +629,7 @@
},
"outputs": [],
"source": [
"# primer_df, blat_df = AgamPrimer.designPrimers(\n",
"# primer_df, blat_df = AnoPrimer.designPrimers(\n",
"# species=species,\n",
"# assay_type='gDNA primers + probe',\n",
"# target='X:2422652' ,\n",
Expand Down Expand Up @@ -651,7 +667,7 @@
"\n",
"####**Future development**\n",
"\n",
"Any contributions or suggestions on how we can improve this notebook are more than welcome. Please [email](mailto:sanjay.nagi@lstmed.ac.uk) or log an [issue on github](https://github.com/sanjaynagi/primerDesignAg/issues). This notebook and source code for AgamPrimer are located here - https://github.com/sanjaynagi/AgamPrimer/ \n",
"Any contributions or suggestions on how we can improve this notebook are more than welcome. Please [email](mailto:sanjay.nagi@lstmed.ac.uk) or log an [issue on github](https://github.com/sanjaynagi/primerDesignAg/issues). This notebook and source code for AnoPrimer are located here - https://github.com/sanjaynagi/AnoPrimer/ \n",
"\n",
"\\\n",
"####**References**\n",
Expand Down Expand Up @@ -684,7 +700,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.13 (default, Mar 29 2022, 02:18:16) \n[GCC 7.5.0]"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit 7646a80

Please sign in to comment.