Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Last active February 4, 2016 21:09
Show Gist options
  • Select an option

  • Save Swarchal/8338c80ec4c93a540f00 to your computer and use it in GitHub Desktop.

Select an option

Save Swarchal/8338c80ec4c93a540f00 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Locating Restriction sites\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 \t4\n",
"9 \t4\n",
"21 \t4\n",
"64 \t4\n",
"79 \t4\n",
"100 \t4\n",
"124 \t4\n",
"135 \t4\n",
"152 \t4\n",
"164 \t4\n",
"166 \t4\n",
"173 \t4\n",
"181 \t4\n",
"187 \t4\n",
"203 \t4\n",
"213 \t4\n",
"233 \t4\n",
"245 \t4\n",
"283 \t4\n",
"301 \t4\n",
"307 \t4\n",
"311 \t4\n",
"355 \t4\n",
"356 \t4\n",
"365 \t4\n",
"377 \t4\n",
"400 \t4\n",
"403 \t4\n",
"406 \t4\n",
"417 \t4\n",
"438 \t4\n",
"443 \t4\n",
"458 \t4\n",
"476 \t4\n",
"486 \t4\n",
"498 \t4\n",
"506 \t4\n",
"580 \t4\n",
"594 \t4\n",
"597 \t4\n",
"605 \t4\n",
"618 \t4\n",
"629 \t4\n",
"633 \t4\n",
"670 \t4\n",
"678 \t4\n",
"683 \t4\n",
"688 \t4\n",
"741 \t4\n",
"750 \t4\n",
"757 \t4\n",
"774 \t4\n",
"805 \t4\n",
"244 \t6\n",
"310 \t6\n",
"376 \t6\n",
"399 \t6\n",
"402 \t6\n",
"405 \t6\n",
"416 \t6\n",
"475 \t6\n",
"497 \t6\n",
"593 \t6\n",
"596 \t6\n",
"604 \t6\n",
"617 \t6\n",
"773 \t6\n",
"401 \t8\n",
"616 \t8\n",
"400 \t10\n",
"399 \t12\n"
]
}
],
"source": [
"from fasta import FASTA\n",
"from complement_dna import complement\n",
"\n",
"x = FASTA('/home/scott/Downloads/rosalind_revp.txt')\n",
"\n",
"# create function called window\n",
"def window(x, f = 4, c = 12):\n",
" \n",
" # determine possible sizes of windows (even numbers only)\n",
"\tn_ = xrange(f, c + 1)\n",
"\tn_even = [w for w in n_ if w % 2 == 0]\n",
" \n",
" # loop through possible window sizes\n",
"\tfor n in n_even:\n",
" # sliding window along sequence of size n\n",
"\t\tfor i in range(0, len(x) - n + 1): \n",
"\t\t\tout = x[i:i + n]\n",
" # if first half of window == complement of second half\n",
"\t\t\tif out[:len(out) / 2] == complement(out[len(out) / 2:])[::-1]:\n",
" # return position and size of current window\n",
"\t\t\t\tprint i + 1, '\\t', n\n",
"\n",
"window(x)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment