{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "# see Dropbox/bmes.ahmet/README.txt for instructions on using bmes.ahmet\n",
    "import sys,os; sys.path.append(os.environ['BMESAHMETDIR']); import bmes\n",
    "bmes.pipinstall('Bio','biopython')\n",
    "sys.path.append(os.environ['BMESAHMETDIR']+'/binf'); import binf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test swalign Local Alignment Algorithm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'score': 14.0, 'align': ['ANRA', 'ANNA'], 'ident': 75.0}\n",
      "14.0\n",
      "75.0\n"
     ]
    }
   ],
   "source": [
    "print(binf.swalign('ANRA','HANNAH'))\n",
    "print(binf.swalign('ANRA','HANNAH',scoreonly=True))\n",
    "print(binf.swalign('ANRA','HANNAH',identonly=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'score': 16.0, 'align': ['ASGYD', 'AS-YD'], 'ident': 80.0}\n",
      "16.0\n",
      "80.0\n"
     ]
    }
   ],
   "source": [
    "print(binf.swalign( 'ASGYD' , 'ASYD'))\n",
    "print(binf.swalign( 'ASGYD' , 'ASYD' ,scoreonly=True))\n",
    "print(binf.swalign( 'ASGYD' , 'ASYD' ,identonly=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'score': 23.0, 'align': ['PAGMASGYD', 'P-GKAS-YD'], 'ident': 66.66666666666666}\n",
      "23.0\n",
      "66.66666666666666\n"
     ]
    }
   ],
   "source": [
    "print(binf.swalign( 'VSPAGMASGYD' , 'IPGKASYD'))\n",
    "print(binf.swalign( 'VSPAGMASGYD' , 'IPGKASYD' ,scoreonly=True))\n",
    "print(binf.swalign( 'VSPAGMASGYD' , 'IPGKASYD' ,identonly=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'score': 23.0, 'align': ['AWGHE', 'AW-HE'], 'ident': 80.0}\n",
      "23.0\n",
      "80.0\n"
     ]
    }
   ],
   "source": [
    "print(binf.swalign( 'HEAGAWGHEE' , 'PAWHEAE'))\n",
    "print(binf.swalign( 'HEAGAWGHEE' , 'PAWHEAE',scoreonly=True ))\n",
    "print(binf.swalign( 'HEAGAWGHEE' , 'PAWHEAE',identonly=True ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score: 2883.0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style='white-space: pre;'>MWGFWLLLFWGFSGTHRWGMTTLAILGQRLNGVNECQDTTTCPAYATCTDTTESYYCTCKQGFLPSNGQTNFQGPGVECQDVNECLRSDSPCGSNSVCTNIPGRARCSCLSGFSSSAGGSWILGSPGHFLCTDVDECLTIGICPKNSNCSNSVGSYSCTCQSGFVSNGSTCEDEDECVTRNACPEHATCHNTLGSYYCTCNEGLEFSGGGPMFQGLEESCEDVDECSRNSTLCGPSFICINTLGSYSCSCPAGFSLSTFQIPGHPADGNCTDIDECDDICPSNSSCTNTLGSYFCTCHPGFASSNGQLNFTDQEVTCEDIDECTQDPFRCGRNSSCTNVPGSYNCSCLPDFRMDPGGSQAHGNFTCKRIPFKCKEDLIPKSEQIEQCQAGQGRNLDYTSFCTFVNATFTILDNTCENKSAPVSLQSAATSVSLMLEQASTWFEFSREETSTLGTILLETVESTMLAALLTPSGNASQTIRTEYLEIESKVINEECNEENVSINLKARGDKMDVGCFIIKESESTGTPGVAFVSFAHMDSVLDERFFEDGQA----S-WKLRMNSHVVGGTVTGERKEDFSKPIVYTLQHIQPKQKSERSICVSWNTDVEDGRWTPSGCETVEASETHTVCSCNRMTNLAIIMASGELTMEFSLYIISYVGTVISLVCLALAIATFLLFRAVQNHNTYLHLHLCVCLFLAKILFLTGIDKTDNQTACAIIAGFLHYLFLACFFWMLVEAVMLFLMVRNLKVVNYFSSRNIKMLHLCAFGYGLPVVVVIISATVHPWGYGMHNRCWLNTETGFIWSFLGPVCMIITINSALLAWTLWVLRQKLCSVNSEVSKLKDTRLLTFKAIAQIFILGCSWVLGIFQIGPLASIMAYLFTTINSLQGAFIFLIHCLLNRQVRDEYRKLLTRKTDLSSHSQTSGILLSSMPSTSKTG\n",
       "MRGFNLLLFWGCCVMHSWEGHIRPTRKPNTKG-NNCRDSTLCPAYATCTNTVDSYYCACKQGFLSSNGQNHFKDPGVRCKDIDECSQSPQPCGPNSSCKNLSGRYKCSCLDGFSSPTGNDWVPGKPGNFSCTDINECLTSSVCPEHSDCVNSMGSYSCSCQVGFISRNSTCEDVDECADPRACPEHATCNNTVGN-Y-SC------------F------------C--N-----PGF---E---S-S-S---G-HLS-FQ--GLKA--SCEDIDECTEMCPINSTCTNTPGSYFCTCHPGFAPSNGQLNFTDQGVECRDIDECRQDPSTCGPNSICTNALGSYSCGCIAGFHPNPEGSQKDGNFSCQRVLFKCKEDVIPDNKQIQQCQEGTAVKPAYVSFCAQINNIFSVLDKVCENKTTVVSLKNTTESFVPVLKQISTWTKFTKEETSSLATVFLESVESMTLASFWKPSANITPAVRTEYLDIESKVINKECSEENVTLDLVAKGDKMKIGCSTIEESESTETTGVAFVSFVGMESVLNERFFKDHQAPLTTSEIKLKMNSRVVGGIMTGEKKDGFSDPIIYTLENIQPKQKFERPICVSWSTDVKGGRWTSFGCVILEASETYTICSCNQMANLAVIMASGELTMDFSLYIISHVGIIISLVCLVLAIATFLLCRSIRNHNTYLHLHLCVCLLLAKTLFLAGIHKTDNKMGCAIIAGFLHYLFLACFFWMLVEAVILFLMVRNLKVVNYFSSRNIKMLHICAFGYGLPMLVVVISASVQPQGYGMHNRCWLNTETGFIWSFLGPVCTVIVINSLLLTWTLWILRQRLSSVNAEVSTLKDTRLLTFKAFAQLFILGCSWVLGIFQIGPVAGVMAYLFTIINSLQGAFIFLIHCLLNGQVREEYKRWITGKTKPSSQSQTSRILLSSMPSASKTG</pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "r = binf.swalign(str(binf.sample_ratptn().seq),str(binf.sample_humanptn().seq),gap=-8)\n",
    "print('Score: '+str(r['score']))\n",
    "#print(\"\\n\".join([r['align'][0][0:100],r['align'][1][0:100]]))\n",
    "\n",
    "from IPython.core.display import display, HTML\n",
    "display(HTML(\"<pre style='white-space: pre;'>\"+\"\\n\".join(r['align'])+\"</pre>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
