--- /dev/null
+{
+ "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