{ "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)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"" ] }, { "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 \"math/rand\"\n", "st = \"ACGT\"\n", "string(st[rand.Intn(len(st))]) // generating a random nucleotide" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "T" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "string(st[rand.Intn(len(st))]) // 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": [ "string(st[rand.Intn(len(st))]) // repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "T" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "string(st[rand.Intn(len(st))]) // repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "C" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "string(st[rand.Intn(len(st))]) // repeated invocations might yield different nucleotides" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "GCAAAGTGCAGTCCGTGAGTTTAGTCATTCACTCGCGGTC" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// make random nucleotide string by concatenating random nucleotides\n", "import \"bytes\"\n", "var b bytes.Buffer\n", "for i := 0; i < 40; i++ {\n", " b.WriteByte(st[rand.Intn(len(st))])\n", "}\n", "st = b.String()\n", "st" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CA" ] }, "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": [ "GCA" ] }, "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": [ "GCA" ] }, "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": [ { "ename": "ERROR", "evalue": "repl.go:1:5: negative slice index: -3 == Expr{Type: int, Value: -3}", "output_type": "error", "traceback": [ "repl.go:1:5: negative slice index: -3 == Expr{Type: int, Value: -3}" ] } ], "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": "Go", "language": "go", "name": "gophernotes" }, "language_info": { "codemirror_mode": "", "file_extension": ".go", "mimetype": "", "name": "go", "nbconvert_exporter": "", "pygments_lexer": "", "version": "go1.11" } }, "nbformat": 4, "nbformat_minor": 2 }