Created
February 12, 2016 13:28
-
-
Save Swarchal/a2da6a604b8397c85171 to your computer and use it in GitHub Desktop.
overlap graphs
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": [ | |
"Overlap graphs\n", | |
"===============" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"using FastaIO\n", | |
"\n", | |
"dat = readfasta(\"/home/scott/Dropbox/rosalind/rosalind_grph.txt\");" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"overlap (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function overlap(x::AbstractString, y::AbstractString, k::Int)\n", | |
" x[end-(k-1):end] == y[1:k]\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"154x2 Array{Any,2}:\n", | |
" \"Rosalind_4684\" \"Rosalind_2924\"\n", | |
" \"Rosalind_5744\" \"Rosalind_4684\"\n", | |
" \"Rosalind_6212\" \"Rosalind_4684\"\n", | |
" \"Rosalind_5078\" \"Rosalind_4684\"\n", | |
" \"Rosalind_3280\" \"Rosalind_4684\"\n", | |
" \"Rosalind_8941\" \"Rosalind_0064\"\n", | |
" \"Rosalind_8941\" \"Rosalind_7021\"\n", | |
" \"Rosalind_8941\" \"Rosalind_9890\"\n", | |
" \"Rosalind_3053\" \"Rosalind_8941\"\n", | |
" \"Rosalind_5527\" \"Rosalind_8941\"\n", | |
" \"Rosalind_2924\" \"Rosalind_7411\"\n", | |
" \"Rosalind_6407\" \"Rosalind_2924\"\n", | |
" \"Rosalind_2924\" \"Rosalind_5188\"\n", | |
" ⋮ \n", | |
" \"Rosalind_7735\" \"Rosalind_7153\"\n", | |
" \"Rosalind_9378\" \"Rosalind_7153\"\n", | |
" \"Rosalind_0139\" \"Rosalind_8451\"\n", | |
" \"Rosalind_6755\" \"Rosalind_8700\"\n", | |
" \"Rosalind_5459\" \"Rosalind_5078\"\n", | |
" \"Rosalind_8700\" \"Rosalind_5710\"\n", | |
" \"Rosalind_7621\" \"Rosalind_5136\"\n", | |
" \"Rosalind_7621\" \"Rosalind_3280\"\n", | |
" \"Rosalind_5188\" \"Rosalind_5710\"\n", | |
" \"Rosalind_0139\" \"Rosalind_4494\"\n", | |
" \"Rosalind_2574\" \"Rosalind_0388\"\n", | |
" \"Rosalind_5709\" \"Rosalind_5459\"" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function adj(data, k)\n", | |
" \n", | |
" out = []\n", | |
" \n", | |
" for x in combinations(data, 2)\n", | |
" \n", | |
" str_x = x[1][2]\n", | |
" str_y = x[2][2]\n", | |
" \n", | |
" if overlap(str_x, str_y, k)\n", | |
" push!(out, x[1][1], x[2][1])\n", | |
" end\n", | |
" \n", | |
" if overlap(str_y, str_x, k)\n", | |
" push!(out, x[2][1], x[1][1])\n", | |
" end \n", | |
" end\n", | |
" \n", | |
" # eurgh\n", | |
" out = transpose(reshape(out, 2, Int(length(out)/2)))\n", | |
" return out\n", | |
"end\n", | |
"\n", | |
"adj(dat, 3)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Check that reshaping the array preserves the order" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"10x2 Array{Int32,2}:\n", | |
" 1 2\n", | |
" 3 4\n", | |
" 5 6\n", | |
" 7 8\n", | |
" 9 10\n", | |
" 11 12\n", | |
" 13 14\n", | |
" 15 16\n", | |
" 17 18\n", | |
" 19 20" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"test = Array(1:20)\n", | |
"transpose(reshape(test, 2, 10))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.4.2", | |
"language": "julia", | |
"name": "julia-0.4" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.4.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment