{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "FragMapper\n", "==========\n", "\n", "Maintained by Seth Veenbaas" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import rnavigate as rnav\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import data to RNAvigate and run Fragmapper analysis\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from rnavigate.examples import quinaxoline, linezolid, methyl\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above import statement is equivalent to running the following code from\n", "inside `/path/to/RNAvigate/rnavigate/examples/rrna_fragmap/`.\n", "\n", "```python\n", "# Reference structure data is shared between samples\n", "common_data = rnav.Sample(\n", " sample='6HA1 - LSU',\n", " sequence='6HA1_LSU.fasta',\n", " pdb={'pdb': '6HA1_LSU.pdb',\n", " 'sequence': 'sequence',\n", " 'chain': 'A'},\n", " ss='6HA1_LSU.json'\n", ")\n", "# Flip structure diagram along x and y axes\n", "common_data.data['ss'].data[\"X_coordinate\"] *= -1\n", "common_data.data['ss'].data[\"Y_coordinate\"] *= -1\n", "# Quinaxoline test sample\n", "quinoxiline = rnav.Sample(\n", " 'B. sub rRNA FragMaP: quinoxiline',\n", " inherit=common_data,\n", " shapemap='2_QN_DMSO_subtracted_LSU_profile.txt'\n", ")\n", "# Linezolid test sample\n", "lnz = rnav.Sample(\n", " 'B. sub rRNA FragMaP: linezolid',\n", " inherit=common_data,\n", " shapemap='2_ZLD_DMSO_subtracted_LSU_profile.txt'\n", ")\n", "# Methyl control sample\n", "met = rnav.Sample(\n", " 'B. sub rRNA FragMaP: methyl',\n", " inherit=common_data,\n", " shapemap='2_Methyl_DMSO_subtracted_LSU_profile.txt'\n", ")\n", "```\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run Fragmapper analysis and saving a FragMaP profile object\n", "# NOTE: Fragmapper requires 1 test sample and 1 control sample\n", "qn_fm = rnav.analysis.Fragmapper(quinaxoline, methyl)\n", "lnz_fm = rnav.analysis.Fragmapper(linezolid, methyl)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FragMaP scatter plots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Scatter plot with FragMaP profiles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# FragMapper.plot_scatter()\n", "print(lnz_fm.get_data(\"fragmap\").data.columns)\n", "fig, ax = lnz_fm.plot_scatter()\n", "fig, ax = qn_fm.plot_scatter()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Scatter plot with raw mutation rates" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# FragMaP_profile_object.plot_scatter()\n", "fig1, ax1 = lnz_fm.plot_scatter()\n", "fig2, ax2 = qn_fm.plot_scatter()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View FragMaP profile" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = rnav.plot_profile(\n", " samples=[lnz_fm],\n", " profile=\"fragmap\",\n", " region=[2000, 2700],\n", " sequence='shapemap',\n", " plot_error=False\n", " )\n", "ax = plot.axes[0, 0]\n", "ax.set(ylim=[-2, 10])\n", "ax.legend(['ZLD FragMaP Profile']);\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View raw sample data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = rnav.plot_skyline(\n", " samples=[lnz_fm],\n", " profile=\"fragmap\",\n", " columns=[\"Modified_rate_1\", \"Modified_rate_2\", \"Delta_rate\"],\n", " sequence=\"shapemap\",\n", " region=[2000, 2700],\n", " annotations=[\"fragmap_sites\"],\n", " annotations_mode='bar',\n", " plot_kwargs={\"subplot_kw\": {\"ylim\": (-0.01, 0.2)}},\n", " )\n", "\n", "plot.axes[0, 0].legend(\n", " [\"ZLD mutation rate\", \"methyl mutation rate\", \"delta rate\"]\n", " );\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## View FragMaP site annotation in secondary structure" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with rnav.styles.Settings({'ss': {'structure': {'linewidth': 2}}}):\n", " plot = rnav.plot_ss(\n", " [lnz_fm],\n", " profile='fragmap',\n", " structure='ss',\n", " colors={'structure': 'sequence',\n", " 'nucleotides': 'none',},\n", " bp_style='conventional',\n", " annotations=['fragmap_sites'],\n", " nt_ticks=100\n", " )\n" ] } ], "metadata": { "kernelspec": { "display_name": "rnavigate", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.13" }, "nbsphinx": { "execute": "never" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }