Skip to content
Snippets Groups Projects
Commit 67276f19 authored by Vermaat's avatar Vermaat
Browse files

Merge branch 'python-more'

parents 334a08d6 8eb997cf
No related branches found
No related tags found
No related merge requests found
......@@ -30,8 +30,9 @@ The top-level directory contains slides for the following lessons.
1. [Welcome](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/welcome.ipynb)
2. [Introduction to Python](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/python.ipynb)
3. [Version control with Git](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/git.ipynb)
4. [Working with NumPy arrays](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/numpy.ipynb)
5. [Plotting with matplotlib](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/matplotlib.ipynb)
4. [More Python Goodness](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/more-python.ipynb)
5. [Working with NumPy arrays](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/numpy.ipynb)
6. [Plotting with matplotlib](http://nbviewer.ipython.org/urls/raw.github.com/LUMC/programming-course/master/matplotlib.ipynb)
Note: These links are to one-page renderings on [IPython Notebook Viewer](http://nbviewer.ipython.org/), see below how to get the real slideshows.
......
File added
This diff is collapsed.
AGCTAG
TATCGTA
TGTAGAT
GAGATCGTAGATC
This diff is collapsed.
......@@ -2631,36 +2631,6 @@
"**Hint:** All elements in a set are unique."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: Analyse a repeat structure\n",
"===\n",
"\n",
"* Make a short tandem repeat that consists of three \"ACGT\" units and five \"TTATT\" units.\n",
"* Print all suffixes of the repeat structure."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: Analyse a repeat structure\n",
"===\n",
"\n",
"* Print all substrings of length 3.\n",
"* Print all unique substrings of length 3."
]
},
{
"cell_type": "markdown",
"metadata": {
......@@ -2679,78 +2649,6 @@
" 2 * (4 > 3)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 * 3 > 4"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"True"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 * (3 > 4)"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": [
"0"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 * (4 > 3)"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": [
"2"
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {
......
#!/usr/bin/env python
import sys
def calc_gc_percent(seq):
"""Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
The returned value is always <= 100.0
"""
at_count, gc_count = 0, 0
# Change input to all caps to allow for non-capital input
# sequence.
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
else:
raise ValueError(
"Unexpeced character found: {}. Only ACTGs "
"are allowed.".format(char))
# Corner case handling: empty input sequence.
try:
return gc_count * 100.0 / (gc_count + at_count)
except ZeroDivisionError:
return 0.0
if __name__ == '__main__':
input_seq = sys.argv[1]
print "The sequence '{}' has a %GC of {:.2f}".format(
input_seq, calc_gc_percent(input_seq))
#!/usr/bin/env python
"""
My sequence toolbox module.
"""
import argparse
def calc_gc_percent(seq):
"""Calculates the GC percentage of the given sequence.
Arguments:
- seq - the input sequence (string).
Returns:
- GC percentage (float).
The returned value is always <= 100.0
"""
at_count, gc_count = 0, 0
# change input to all caps to allow for non-capital input sequence
for char in seq.upper():
if char in ('A', 'T'):
at_count += 1
elif char in ('G', 'C'):
gc_count += 1
else:
raise ValueError("Invalid character found: {}".format(char))
# corner case handling: empty input sequence
try:
return (gc_count * 100.0) / (at_count + gc_count)
except ZeroDivisionError:
return 0.0
def _show_results(seq, seq_gc):
"""Prints the sequence and its GC content.
Arguments:
- seq - sequence to print (string).
- seq_gc - GC percentage (float).
Returns:
- None
"""
print "The sequence '{}' has a %GC of {:.2f}".format(seq, seq_gc)
if __name__ == '__main__':
# create our argument parser object
parser = argparse.ArgumentParser()
# add argument for input type
parser.add_argument('mode', type=str,
choices=['file', 'text'],
help="Input type of the script")
# add argument for the input value
parser.add_argument('value', type=str,
help="Input value of the script")
# do the actual parsing
args = parser.parse_args()
if args.mode == 'file':
try:
f = open(args.value, 'r')
for line in f:
seq = line.strip()
gc = calc_gc_percent(seq)
_show_results(seq, gc)
finally:
f.close()
else:
_show_results(args.value, calc_gc_percent(args.value))
/*
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
*/
@font-face {
font-family: "Computer Modern";
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');
}
div.cell{
width:800px;
margin-left:16% !important;
margin-right:auto;
}
h1 {
font-family: Helvetica, serif;
}
h4{
margin-top:12px;
margin-bottom: 3px;
}
div.text_cell_render{
font-family: Computer Modern, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
line-height: 145%;
font-size: 130%;
width:800px;
margin-left:auto;
margin-right:auto;
}
.CodeMirror{
font-family: "Source Code Pro", source-code-pro,Consolas, monospace;
}
.prompt{
display: None;
}
.text_cell_render h5 {
font-weight: 300;
font-size: 22pt;
color: #4057A1;
font-style: italic;
margin-bottom: .5em;
margin-top: 0.5em;
display: block;
}
.warning{
color: rgb( 240, 20, 20 )
}
/*
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
*/
@font-face {
font-family: "Computer Modern";
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');
}
div.cell{
/*width:800px;
margin-left:16% !important;*/
margin-right:auto;
}
h1 {
font-family: Helvetica, serif;
}
h4{
margin-top:12px;
margin-bottom: 3px;
}
div.text_cell_render{
font-family: Computer Modern, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
line-height: 145%;
font-size: 130%;
/*width:800px;*/
margin-left:auto;
margin-right:auto;
}
.CodeMirror{
font-family: "Source Code Pro", source-code-pro,Consolas, monospace;
}
.prompt{
display: None;
}
.text_cell_render h5 {
font-weight: 300;
font-size: 22pt;
color: #4057A1;
font-style: italic;
margin-bottom: .5em;
margin-top: 0.5em;
display: block;
}
.warning{
color: rgb( 240, 20, 20 )
}
// https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
MathJax.Hub.Config({
TeX: {
extensions: ["AMSmath.js"]
},
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
},
displayAlign: 'center', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 4}}
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment