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
68 changes: 58 additions & 10 deletions BINF2025_TP4.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": "ABX9TyOkaYHMV5kAI2JXjqDKbiVa",
"include_colab_link": true
"provenance": []
},
"kernelspec": {
"name": "python3",
Expand All @@ -19,8 +17,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/pparutto/BINF2025_TP4/blob/main/BINF2025_TP4.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
Expand Down Expand Up @@ -60,7 +57,7 @@
"metadata": {
"id": "A8LhiAAeP9u-"
},
"execution_count": null,
"execution_count": 1,
"outputs": []
},
{
Expand All @@ -75,6 +72,8 @@
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"\n",
"def read_fasta(fname):\n",
" #Read a fasta file with multiple entries.\n",
" #Returns a list of sequences.\n",
Expand Down Expand Up @@ -123,7 +122,7 @@
"metadata": {
"id": "30qlDWTmQ47E"
},
"execution_count": null,
"execution_count": 3,
"outputs": []
},
{
Expand Down Expand Up @@ -184,12 +183,20 @@
{
"cell_type": "code",
"source": [
"#Votre code ici"
"def mark_columns(A: list, alpha: float) -> list :\n",
" marked = []\n",
" for i in range(len(A)) :\n",
" count = 0\n",
" for char in len(A[i]) :\n",
" count += char == \"-\"\n",
" if count / len(A[i]) < alpha :\n",
" marked.append(i)\n",
" return marked"
],
"metadata": {
"id": "ikf5pcUtRYvV"
},
"execution_count": null,
"execution_count": 4,
"outputs": []
},
{
Expand Down Expand Up @@ -222,7 +229,48 @@
{
"cell_type": "code",
"source": [
"#Votre code ici"
"def build_HMM(A: list, mark: list) :\n",
" # Step 1: init matrixes\n",
" N = len(mark)\n",
" T = np.ones(shape=(N+1, 9))\n",
" eM = np.ones(shape=(N+1, 20))\n",
" eI = np.ones(shape=(N+1, 20))\n",
" T[:,0] = 0\n",
" T[:,T.shape[1] - 1] = 0\n",
" eM[:,0] = 0\n",
"\n",
" # Step 2: fill matrixes\n",
" pi = []\n",
" for k in range(1, len(A)) :\n",
" for l in range(1, len(A[k])):\n",
" if l in mark :\n",
" if A[k][l] == \"-\" :\n",
" pi[l] = \"D\"\n",
" else :\n",
" pi[l] = \"M\"\n",
" else :\n",
" if A[k][l] == \"-\" :\n",
" pi[l] = \"0\"\n",
" else :\n",
" pi[l] = \"I\"\n",
"\n",
" l0 = 0\n",
" while l0 < len(pi) and A[k][l0] == \"-\" :\n",
" l0 += 1\n",
" if l0 == len(pi) :\n",
" eI[0][A[k][l0]]\n",
" T[0][M] += A[k][l0]\n",
"\n",
" u = 0\n",
" for l in range(l0, len(pi)) :\n",
" if l in mark :\n",
" u += 1\n",
" elif pi[l] == \"0\" :\n",
" continue\n",
" elif pi[l] == \"M\" and A[k][l] != \"-\" :\n",
" eM[u][A[k][l]] += 1\n",
" elif pi[l] == \"I\" and A[k][l] != \"-\" :\n",
" eI[u][A[k][l]] += 1"
],
"metadata": {
"id": "Y3TXPqNhTwNo"
Expand Down