{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'A'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'A'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'ACGT'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'ACGT'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "st = 'ACGT'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(st) # getting the length of a string" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "''" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'' # empty string (epsilon)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len('')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import random\n", "random.choice('ACGT') # generating a random nucleotide" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.choice('ACGT') # repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'T'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.choice('ACGT') # repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'A'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.choice('ACGT') # repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'G'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.choice('ACGT') # repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GTCACATAATGCTGTAGATTAAGCGAGAAGACCTTAGGTC'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# now I'll make a random nucleotide string by concatenating random nucleotides\n", "st = ''.join([random.choice('ACGT') for _ in range(40)])\n", "st" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'TC'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st[1:3] # substring, starting at position 1 and extending up to but not including position 3\n", "# note that the first position is numbered 0" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GTC'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st[0:3] # prefix of length 3" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GTC'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st[:3] # another way of getting the prefix of length 3" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GTC'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st[len(st)-3:len(st)] # suffix of length 3" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GTC'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st[-3:] # another way of getting the suffix of length 3" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "st1, st2 = 'CAT', 'ATAC'" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'CAT'" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st1" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'ATAC'" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st2" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'CATATAC'" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st1 + st2 # concatenation of 2 strings" ] } ], "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.6.2" } }, "nbformat": 4, "nbformat_minor": 1 }