{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# define a new sequence\n", "seq = 'ACGT'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# define a new sequence\n", "seq = \"ACGT\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'C'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get a character from a string\n", "seq[1]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# get the length of a sequence\n", "len(seq)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# empty string (epsilon)\n", "e = ''" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(e)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AACCGGTT\n" ] } ], "source": [ "# concatenation\n", "seq1 = 'AACC'\n", "seq2 = 'GGTT'\n", "print(seq1 + seq2)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ACGT\n" ] } ], "source": [ "seqs = ['A', 'C', 'G', 'T']\n", "print(''.join(seqs))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'T'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# generate a random nucleotide\n", "import random\n", "random.choice('ACGT')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TCAATTCCAT\n" ] } ], "source": [ "# generate a random sequence\n", "seq = ''\n", "for _ in range(10):\n", " seq += random.choice('ACGT')\n", "print(seq)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GATCACCGAC\n" ] } ], "source": [ "# another way to generate a random sequence\n", "seq = ''.join([random.choice('ACGT') for _ in range(10)])\n", "print(seq)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'AT'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# get a substring\n", "seq[1:3]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'GAT'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# get a prefix\n", "seq[:3]" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'GAC'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# get a suffix\n", "seq[7:]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'GAC'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# another way to get a suffix\n", "seq[-3:]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }