most of the end-of-workshop materials
authorC. Titus Brown <titus@idyll.org>
Sat, 17 Nov 2012 15:27:18 +0000 (07:27 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 1 Nov 2013 04:07:51 +0000 (21:07 -0700)
W. Trevor King: I dropped everything from the original 2c73710 except
for the python/testing-with-nose.ipynb addition.

Conflicts:
_static/14.html
_static/15.html
_static/16.html
index.rst
notes/day2.txt

python/testing-with-nose.ipynb [new file with mode: 0644]

diff --git a/python/testing-with-nose.ipynb b/python/testing-with-nose.ipynb
new file mode 100644 (file)
index 0000000..5dbe383
--- /dev/null
@@ -0,0 +1,205 @@
+{
+ "metadata": {
+  "name": "testing-with-nose"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "%%file calc_gc.py\n",
+      "def calc_gc(sequence):\n",
+      "    sequence = sequence.upper()\n",
+      "    n = sequence.count('T') + sequence.count('A')\n",
+      "    m = sequence.count('G') + sequence.count('C')\n",
+      "    if n + m == 0:\n",
+      "        return 0.\n",
+      "    return float(m) / float(n + m)\n",
+      "\n",
+      "def test_1():\n",
+      "    result = round(calc_gc('ATGGCAT'), 2)\n",
+      "    print 'hello, this is a test; the value of result is', result\n",
+      "    assert result == 0.43\n",
+      "    \n",
+      "def test_2():\n",
+      "    result = round(calc_gc('NATGC'), 2)\n",
+      "    assert result == 0.5, result\n",
+      "    \n",
+      "def test_3():\n",
+      "    result = round(calc_gc('natgc'), 2)\n",
+      "    assert result == 0.5, result\n"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Overwriting calc_gc.py"
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "\n"
+       ]
+      }
+     ],
+     "prompt_number": 42
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!nosetests calc_gc.py"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "...\r\n",
+        "----------------------------------------------------------------------\r\n",
+        "Ran 3 tests in 0.001s\r\n",
+        "\r\n",
+        "OK\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 43
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "%%file gc-of-seqs.py\n",
+      "import sys\n",
+      "import screed\n",
+      "import calc_gc\n",
+      "\n",
+      "filename = sys.argv[1]\n",
+      "total_gc = []\n",
+      "for record in screed.open(filename):\n",
+      "    gc = calc_gc.calc_gc(record.sequence)\n",
+      "    total_gc.append(gc)\n",
+      "    \n",
+      "print sum(total_gc) / float(len(total_gc))"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Writing gc-of-seqs.py"
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "\n"
+       ]
+      }
+     ],
+     "prompt_number": 44
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!python gc-of-seqs.py 25k.fq.gz"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "0.607911191366\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 47
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "%%file test_gc_script.py\n",
+      "import subprocess\n",
+      "\n",
+      "correct_output = \"0.607911191366\\n\"\n",
+      "\n",
+      "def test_run():\n",
+      "    p = subprocess.Popen('python gc-of-seqs.py 25k.fq.gz', shell=True, stdout=subprocess.PIPE)\n",
+      "    (stdout, stderr) = p.communicate()\n",
+      "    assert stdout == correct_output\n",
+      "    \n"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "Overwriting test_gc_script.py"
+       ]
+      },
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "\n"
+       ]
+      }
+     ],
+     "prompt_number": 52
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "!nosetests test_gc_script.py"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        ".\r\n",
+        "----------------------------------------------------------------------\r\n",
+        "Ran 1 test in 0.969s\r\n",
+        "\r\n",
+        "OK\r\n"
+       ]
+      }
+     ],
+     "prompt_number": 53
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
\ No newline at end of file