Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 190 additions & 19 deletions BINF_TP5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyO0SUJI6kaczFcOh8NoKcqb",
"include_colab_link": true
"provenance": []
},
"kernelspec": {
"name": "python3",
Expand All @@ -16,16 +14,6 @@
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/pparutto/BINF2025_TP5/blob/main/BINF_TP5.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
Expand Down Expand Up @@ -68,13 +56,54 @@
{
"cell_type": "code",
"source": [
"print(\"votre fonction ici !!\")"
"def BWT(s):\n",
" s += \"$\"\n",
" perm = []\n",
" n = len(s)\n",
" for i in range(n):\n",
" perm.append((s[n-i:] + s[:n-i],i))\n",
" print(perm)\n",
"\n",
" tab = sorted(perm)\n",
" print(tab)\n",
"\n",
" seq = \"\"\n",
" indice = []\n",
" for s,i in tab:\n",
" seq += s[-1]\n",
" indice.append(i)\n",
" return seq, indice\n",
"\n",
"BWT(\"chien\")"
],
"metadata": {
"id": "D5zJsnmQnajj"
"id": "D5zJsnmQnajj",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "24b7c7d1-7eaf-40f1-c519-4ea874549f60"
},
"execution_count": null,
"outputs": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[('chien$', 0), ('$chien', 1), ('n$chie', 2), ('en$chi', 3), ('ien$ch', 4), ('hien$c', 5)]\n",
"[('$chien', 1), ('chien$', 0), ('en$chi', 3), ('hien$c', 5), ('ien$ch', 4), ('n$chie', 2)]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"('n$iche', [1, 0, 3, 5, 4, 2])"
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -135,13 +164,155 @@
{
"cell_type": "code",
"source": [
"print(\"Votre code ici !\")"
"def iBWT(t): #Don't work\n",
" tab = []\n",
" n = len(t)\n",
" for i in range(n):\n",
" tmp = []\n",
" for j in range(n):\n",
" word = \"\"\n",
" for k in range(i+1):\n",
" word += t[(k+j)%n]\n",
" tmp.append(word)\n",
" tab.append((tmp, sorted(tmp)))\n",
" return tab\n",
"\n",
"iBWT(\"n$iche\")"
],
"metadata": {
"id": "oH-bAVbgpOUe"
"id": "oH-bAVbgpOUe",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "c1bc8f68-07d6-4ea4-8c29-9353cc937af2"
},
"execution_count": null,
"outputs": []
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[(['n', '$', 'i', 'c', 'h', 'e'], ['$', 'c', 'e', 'h', 'i', 'n']),\n",
" (['n$', '$i', 'ic', 'ch', 'he', 'en'], ['$i', 'ch', 'en', 'he', 'ic', 'n$']),\n",
" (['n$i', '$ic', 'ich', 'che', 'hen', 'en$'],\n",
" ['$ic', 'che', 'en$', 'hen', 'ich', 'n$i']),\n",
" (['n$ic', '$ich', 'iche', 'chen', 'hen$', 'en$i'],\n",
" ['$ich', 'chen', 'en$i', 'hen$', 'iche', 'n$ic']),\n",
" (['n$ich', '$iche', 'ichen', 'chen$', 'hen$i', 'en$ic'],\n",
" ['$iche', 'chen$', 'en$ic', 'hen$i', 'ichen', 'n$ich']),\n",
" (['n$iche', '$ichen', 'ichen$', 'chen$i', 'hen$ic', 'en$ich'],\n",
" ['$ichen', 'chen$i', 'en$ich', 'hen$ic', 'ichen$', 'n$iche'])]"
]
},
"metadata": {},
"execution_count": 35
}
]
},
{
"cell_type": "code",
"source": [
"def iBWT3(s) -> str:\n",
" inverse = [char for char in s]\n",
" for i in range(len(s) - 1):\n",
" inverse.sort()\n",
" inverse = [s[j] + inverse[j] for j in range(len(s))]\n",
" print(inverse)\n",
" print(inverse)\n",
" return next(elt for elt in inverse if elt[-1] == '$')\n",
"iBWT3(\"n$iche\")"
],
"metadata": {
"id": "BwA537kFnlK3",
"outputId": "358a1db9-b232-4503-9311-f3285f6bc07a",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 142
}
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['n$', '$c', 'ie', 'ch', 'hi', 'en']\n",
"['n$c', '$ch', 'ien', 'chi', 'hie', 'en$']\n",
"['n$ch', '$chi', 'ien$', 'chie', 'hien', 'en$c']\n",
"['n$chi', '$chie', 'ien$c', 'chien', 'hien$', 'en$ch']\n",
"['n$chie', '$chien', 'ien$ch', 'chien$', 'hien$c', 'en$chi']\n",
"['n$chie', '$chien', 'ien$ch', 'chien$', 'hien$c', 'en$chi']\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'chien$'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 1
}
]
},
{
"cell_type": "code",
"source": [
"def iBWT2(t):\n",
" table = [\"\"] * len(t)\n",
"\n",
" for _ in range(len(t)):\n",
" table = [t[i] + table[i] for i in range(len(t))]\n",
" table.sort()\n",
" print(table)\n",
"\n",
" for s in table:\n",
" if s.endswith(\"$\"):\n",
" return s[:-1]\n",
" return \"\"\n",
"\n",
"iBWT2(\"n$iche\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 142
},
"id": "tXcgUA4ilNu0",
"outputId": "aeb4b385-0b87-4b76-b6e3-fea867f1b3ff"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['$', 'c', 'e', 'h', 'i', 'n']\n",
"['$c', 'ch', 'en', 'hi', 'ie', 'n$']\n",
"['$ch', 'chi', 'en$', 'hie', 'ien', 'n$c']\n",
"['$chi', 'chie', 'en$c', 'hien', 'ien$', 'n$ch']\n",
"['$chie', 'chien', 'en$ch', 'hien$', 'ien$c', 'n$chi']\n",
"['$chien', 'chien$', 'en$chi', 'hien$c', 'ien$ch', 'n$chie']\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'chien'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "markdown",
Expand Down