diff --git a/pyjaspar_notebook.ipynb b/pyjaspar_notebook.ipynb index 4936958..fea716b 100644 --- a/pyjaspar_notebook.ipynb +++ b/pyjaspar_notebook.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 3, "metadata": { "scrolled": true }, @@ -75,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -437,7 +437,23 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "jdb_obj = jaspardb(release=\"JASPAR2026\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### similarity/correlation" + ] + }, + { + "cell_type": "code", + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -446,7 +462,7 @@ "0.6692418299461174" ] }, - "execution_count": 24, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -454,8 +470,8 @@ "source": [ "from pyjaspar.analysis import pearson_correlation, best_correlation\n", "\n", - "m1 = jdb.fetch_motif_by_id(\"MA0001.1\")\n", - "m2 = jdb.fetch_motif_by_id(\"MA0002.1\")\n", + "m1 = jdb_obj.fetch_motif_by_id(\"MA0001.1\")\n", + "m2 = jdb_obj.fetch_motif_by_id(\"MA0002.1\")\n", "\n", "# Column-wise Pearson correlation\n", "score = pearson_correlation(m1, m2)\n", @@ -465,6 +481,99 @@ "score" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Scan a sequence for motif occurrences" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Consensus motif: GCCACCAGGGGGCGC\n", + "8 hit(s) found\n", + "ScanHit(position=2, strand='+', score=-10.198715209960938, sequence='ACCAGGTGGCACTAG')\n", + "ScanHit(position=15, strand='+', score=8.533143997192383, sequence='AGCACCAGGTGGTAT')\n", + "ScanHit(position=16, strand='+', score=-13.91905689239502, sequence='GCACCAGGTGGTATC')\n" + ] + } + ], + "source": [ + "from pyjaspar.analysis import scan_sequence\n", + "\n", + "sequence = \"CCACCAGGTGGCACTAGCACCAGGTGGTATCTAGTGGACCTAGCATTGCTATTACGTCA\"\n", + "scan_target_motif = jdb_obj.fetch_motif_by_id(\"MA0139.2\")\n", + "print(\"Consensus motif: \", scan_target_motif.consensus)\n", + "\n", + "hits = scan_sequence(sequence, scan_target_motif, threshold=0.7)\n", + "\n", + "print(f\"{len(hits)} hit(s) found\")\n", + "for hit in hits[:3]:\n", + " print(hit)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Motif enrichment" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MA0174.1 Dbx TTTATTA\n", + "MA0247.3 tin TTCAAGTGG\n", + "MA2485.1 Duxbl1 TTAATCTAATCAA\n", + "\n", + " EnrichmentResult(motif_id='MA0174.1', motif_name='Dbx', fg_hits=5, bg_hits=0, fg_total=5, bg_total=5, fold_enrichment=inf, pvalue=np.float64(0.003968253968253969), qvalue=np.float64(0.011904761904761908))\n", + "\n", + " EnrichmentResult(motif_id='MA0247.3', motif_name='tin', fg_hits=0, bg_hits=0, fg_total=5, bg_total=5, fold_enrichment=1.0, pvalue=1.0, qvalue=1.0)\n", + "\n", + " EnrichmentResult(motif_id='MA2485.1', motif_name='Duxbl1', fg_hits=0, bg_hits=0, fg_total=5, bg_total=5, fold_enrichment=1.0, pvalue=1.0, qvalue=1.0)\n" + ] + } + ], + "source": [ + "from pyjaspar.analysis import motif_enrichment\n", + "\n", + "candidate_motifs = jdb_obj.fetch_motifs(tf_family=\"Homeo\", collection=None, all_versions=False)\n", + "for m in candidate_motifs:\n", + " print(m.matrix_id, m.name, m.consensus)\n", + "\n", + "foreground = [\n", + " \"GGCGATTTATTACGCG\",\n", + " \"ATGCATTTATTAGGCA\",\n", + " \"CGTATTTATTACGATA\",\n", + " \"TACGTTTATTAGCATG\",\n", + " \"GATCTTTATTACTGAC\",\n", + "]\n", + "background = [\n", + " \"GGCGACCCGGGACGCG\",\n", + " \"ATGCACCCGGGAGGCA\",\n", + " \"CGTACCCGGGACGATA\",\n", + " \"TACGCCCGGGAGCATG\",\n", + " \"GATCCCCGGGACTGAC\",\n", + "]\n", + "\n", + "results = motif_enrichment(foreground, background, motifs=candidate_motifs, threshold=0.9)\n", + "for r in results:\n", + " print(\"\\n\", r)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -474,7 +583,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -485,6 +594,18 @@ "14\n", "REST K562 6\n", "dict_keys(['CWM', 'PFM'])\n", + "Matrix(kind='PFM', values=array([[3.300e+02, 3.850e+02, 3.340e+02, 4.350e+02, 4.530e+02, 4.930e+02,\n", + " 5.300e+02, 2.060e+02, 6.000e+00, 2.020e+03, 0.000e+00, 0.000e+00,\n", + " 6.300e+01, 0.000e+00],\n", + " [6.990e+02, 7.880e+02, 6.870e+02, 6.960e+02, 6.680e+02, 3.890e+02,\n", + " 3.050e+02, 9.120e+02, 2.158e+03, 4.300e+01, 2.166e+03, 0.000e+00,\n", + " 2.600e+01, 2.000e+00],\n", + " [8.380e+02, 5.670e+02, 6.490e+02, 7.470e+02, 7.220e+02, 1.039e+03,\n", + " 1.193e+03, 6.240e+02, 2.000e+00, 2.900e+01, 0.000e+00, 2.167e+03,\n", + " 6.200e+01, 2.162e+03],\n", + " [3.000e+02, 4.270e+02, 4.970e+02, 2.890e+02, 3.240e+02, 2.460e+02,\n", + " 1.390e+02, 4.250e+02, 1.000e+00, 7.500e+01, 1.000e+00, 0.000e+00,\n", + " 2.016e+03, 3.000e+00]]))\n", " 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n", "A: -0.72 -0.49 -0.70 -0.32 -0.26 -0.14 -0.03 -1.39 -6.50 1.90 -inf -inf -3.10 -inf\n", "C: 0.37 0.54 0.34 0.36 0.30 -0.48 -0.83 0.75 1.99 -3.66 2.00 -inf -4.38 -8.08\n", @@ -527,17 +648,17 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "BP000001.1: REST (K562) (vertebrates)\n", - "BP000017.1: REST (K562) (vertebrates)\n", - "BP000063.1: REST (K562) (vertebrates)\n", - "BP000075.1: REST (K562) (vertebrates)\n" + "BP000001.1: REST (K562) (9606)\n", + "BP000017.1: REST (K562) (9606)\n", + "BP000063.1: REST (K562) (9606)\n", + "BP000075.1: REST (K562) (9606)\n" ] } ], @@ -545,15 +666,15 @@ "# Search profiles by TF name and combined filters\n", "models = jdb.dl.search_models(tf_name=\"REST\", cell_line=\"K562\")\n", "for m in models:\n", - " print(f\"{m.model_id}: {m.tf_name} ({m.cell_line}) ({p.tax_group})\")" + " print(f\"{m.model_id}: {m.tf_name} ({m.cell_line}) ({m.tax_id})\")" ] } ], "metadata": { "kernelspec": { - "display_name": "pyjaspar", + "display_name": "pyjaspar (oss)", "language": "python", - "name": "python3" + "name": "pyjaspar-oss" }, "language_info": { "codemirror_mode": { @@ -565,9 +686,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.19" + "version": "3.10.21" } }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file