Last active
January 26, 2016 19:27
-
-
Save Swarchal/27bcccd5271db755e242 to your computer and use it in GitHub Desktop.
puzzle club 3: Calculating GC content
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Computing GC content\n", | |
"---------------------\n", | |
"\n", | |
"Return the string with the highest GC content and the percentage GC content" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Rosalind_0409 \n", | |
"52.4144869215\n" | |
] | |
} | |
], | |
"source": [ | |
"from __future__ import division\n", | |
"from Bio import SeqIO\n", | |
"\n", | |
"file = '/home/scott/Downloads/rosalind_gc.txt'\n", | |
"fasta_file = SeqIO.parse(open(file), 'fasta')\n", | |
"with open(file):\n", | |
"\tmax_value = None\n", | |
"\tfor fasta in fasta_file:\n", | |
"\t\tname, s = fasta.id, str(fasta.seq)\n", | |
"\t\tcontent = ((s.count('G') + s.count('C')) / len(s)) * 100\n", | |
"\t\tif content > max_value: max_name, max_value = name, content \n", | |
" \n", | |
"print max_name, '\\n', max_value" | |
] | |
} | |
], | |
"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