Skip to content

Commit

Permalink
removed some blank lines, added some indenting that should help with …
Browse files Browse the repository at this point in the history
…copy paste
  • Loading branch information
BenLangmead committed Aug 23, 2015
1 parent eedde3e commit c7e1f06
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions 2.01_BoyerMoore.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@
" \"\"\" Use Z algorithm (Gusfield theorem 1.4.1) to preprocess s \"\"\"\n",
" assert len(s) > 1\n",
" z = [len(s)] + [0] * (len(s)-1)\n",
"\n",
" # Initial comparison of s[1:] with prefix\n",
" for i in range(1, len(s)):\n",
" if s[i] == s[i-1]:\n",
" z[1] += 1\n",
" else:\n",
" break\n",
" \n",
" r, l = 0, 0\n",
" if z[1] > 0:\n",
" r, l = z[1], 1\n",
" \n",
" for k in range(2, len(s)):\n",
" assert z[k] == 0\n",
" if k > r:\n",
Expand Down Expand Up @@ -79,7 +76,6 @@
" i = len(p) - n[j]\n",
" if i < len(p):\n",
" lp[i] = j + 1\n",
"\n",
" return lp\n",
"\n",
"\n",
Expand Down Expand Up @@ -151,25 +147,22 @@
" def __init__(self, p, alphabet='ACGT'):\n",
" self.p = p\n",
" self.alphabet = alphabet\n",
"\n",
" # Create map from alphabet characters to integers\n",
" self.amap = {}\n",
" for i in range(len(self.alphabet)):\n",
" self.amap[self.alphabet[i]] = i\n",
"\n",
" # Make bad character rule table\n",
" self.bad_char = dense_bad_char_tab(p, self.amap)\n",
"\n",
" # Create good suffix rule table\n",
" _, self.big_l, self.small_l_prime = good_suffix_table(p)\n",
"\n",
" \n",
" def bad_character_rule(self, i, c):\n",
" \"\"\" Return # skips given by bad character rule at offset i \"\"\"\n",
" assert c in self.amap\n",
" ci = self.amap[c]\n",
" assert i > (self.bad_char[i][ci]-1)\n",
" return i - (self.bad_char[i][ci]-1)\n",
"\n",
" \n",
" def good_suffix_rule(self, i):\n",
" \"\"\" Given a mismatch at offset i, return amount to shift\n",
" as determined by (weak) good suffix rule. \"\"\"\n",
Expand All @@ -181,7 +174,7 @@
" if self.big_l[i] > 0:\n",
" return length - self.big_l[i]\n",
" return length - self.small_l_prime[i]\n",
"\n",
" \n",
" def match_skip(self):\n",
" \"\"\" Return amount to shift in case where P matches T \"\"\"\n",
" return len(self.small_l_prime) - self.small_l_prime[1]"
Expand Down

0 comments on commit c7e1f06

Please sign in to comment.