Created
August 26, 2014 20:55
-
-
Save sheenamt/97286ea893dfbc5e7cc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Code Review:\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<img src=\"files/sally-code-review.png\">" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Many options about who/when/how that we should discuss as a group" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"unittesting:" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Here's an example function that reformats the tumor types entered into the LIS. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"TUMOR_TYPES = {'liver', 'lung', 'all', 'aml', 'bladder', 'brain', 'unknown primary', 'unknown'}\n", | |
"\n", | |
"def fix_tumor_type(tumor_type, tumors=TUMOR_TYPES):\n", | |
" \"\"\"Normalize `tumor_type`, discarding entries not in `tumors`.\n", | |
" \"\"\"\n", | |
" tumor_type = tumor_type.lower().strip()\n", | |
" return tumor_type if tumor_type in tumors else None" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Here's how many of us would test our function:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"lis_tumors = {'liver', 'Lung', 'ALL', 'AML', 'bladder', 'armesis'}\n", | |
"\n", | |
"for tumor in lis_tumors:\n", | |
" print \"{} becomes {}\" .format(tumor, fix_tumor_type(tumor))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"ALL becomes all\n", | |
"AML becomes aml\n", | |
"bladder becomes bladder\n", | |
"Lung becomes lung\n", | |
"liver becomes liver\n", | |
"armesis becomes None\n" | |
] | |
} | |
], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"A class is created to test the function instead. This scripts is part of the genetics_db package, in the annotation.py script. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import unittest\n", | |
"import sys\n", | |
"\n", | |
"class TestAnnotation(unittest.TestCase):\n", | |
" def testFixTumorType(self):\n", | |
" self.assertEqual(fix_tumor_type('Aml'), 'aml')\n", | |
" self.assertEqual(fix_tumor_type('Lung'), 'lung')\n", | |
" self.assertEqual(fix_tumor_type('Cancel, see detail'), None)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 59 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"suite = unittest.TestLoader().loadTestsFromTestCase( TestAnnotation )\n", | |
"unittest.TextTestRunner(verbosity=2,stream=sys.stderr).run( suite )" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": [ | |
"testFixTumorType (__main__.TestAnnotation) ... " | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": [ | |
"ok\n", | |
"\n", | |
"----------------------------------------------------------------------\n", | |
"Ran 1 test in 0.001s\n", | |
"\n", | |
"OK\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 67, | |
"text": [ | |
"<unittest.runner.TextTestResult run=1 errors=0 failures=0>" | |
] | |
} | |
], | |
"prompt_number": 67 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"virtualenv:" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"You can create a virtualenv for development easily:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"virtualenv new_project" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"To begin using the virtual environment, it needs to be activated:\n", | |
"You can then begin installing any new modules without affecting the system default Python or other virtual environments.\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"source new_project/bin/activate" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"If you are done working in the virtual environment for the moment, you can deactivate it:\n", | |
"This puts you back to the system's default Python interpreter with all its installed libraries." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"deactivate" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"To delete a virtual environment, just delete its folder." | |
] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment