r/dailyprogrammer • u/jnazario 2 0 • Mar 25 '15
[2015-03-25] Challenge #207 [Intermediate] Bioinformatics 2: DNA Restriction Enzymes
Continuing with our bioinformatics theme today. If you like these sorts of problems, I encourage you to check out Project Rosalind (their site seems back up): http://rosalind.info/
Description
Restriction enzymes are DNA-cutting enzymes found in bacteria (and harvested from them for use). Because they cut within the molecule, they are often called restriction endonucleases. In order to be able to sequence DNA, it is first necessary to cut it into smaller fragments. For precise molecular biology work, what is needed is a way to cleave the DNA molecule at a few specifically-located sites so that a small set of homogeneous fragments are produced. The tools for this are the restriction endonucleases. The rarer the site it recognizes, the smaller the number of pieces produced by a given restriction endonuclease.
For more information on how these enzymes work, including a great visualization of how they cut, have a look here: http://users.rcn.com/jkimball.ma.ultranet/BiologyPages/R/RestrictionEnzymes.html
These enzymes can cleave the DNA at a site that leaves both strands the same length. This is called a "blunt" end because of this and can be visualized like this:
5'-GG +CC-3'
3'-CC GG-5'
Other DNA restriction enzymes cleave the ends at different lengths, although it's symmetrical about the central axis. These are called "sticky" ends, and here's a simple visualization of one of those cuts:
5'-ATCTGACT + GATGCGTATGCT-3'
3'-TAGACTGACTACG CATACGA-5'
In both cases the two strands are cut at a point of symmetry (the upper and lower strands are symmetrical if rotated).
Today your challenge is to write a program that can recognize the locations where various enzymes will cut DNA.
Input
You'll be given a list of DNA restriction enzymes and their recognition site and where the cut occurs. The input will be structured as enzyme name, if the enzyme makes a "sticky" or "blunt" end cut, the DNA recognition sequence and the position of the cut marked with a caret ("^"). For the sticky ends, you should assume the mirror image of the complementary strand gets the same cut, leaving one of the strands to overhang (hence it's "sticky").
BamHI sticky G^GATCC
HaeIII blunt GG^CC
HindIII sticky A^AGCTT
Then you'll be given a DNA sequence and be asked to cut it with the listed enzymes. For sake of convenience, the DNA sequence is broken into blocks of 10 bases at a time and in lengths of 6 blocks per row. You should merge these together and drop the first column of digits.
This sequence was taken from the genome of Enterobacteria phage phiX174 sensu lato http://www.genome.jp/dbget-bin/www_bget?refseq+NC_001422 and modified for this challenge.
1 gagttttatc gcttccatga cgcagaagtt aacactttcg gatatttctg atgagtcgaa
61 aaattatctt gataaagcag gaattactac tgcttgttta cgaattaaat cgaagtggac
121 tgctggcgga aaatgagaaa attcgaccta tccttgcgca gctcgagaag ctcttacttt
181 gcgacctttc gccatcaact aacgattctg tcaaaaactg acgcgttgga tgaggagaag
241 tggcttaata tgcttggcac gttcgtcaag gactggttta gatatgagtc acattttgtt
301 catggtagag attctcttgt tgacatttta aaagagcgtg gattactatc tgagtccgat
361 gctgttcaac cactaatagg taagaaatca tgagtcaagt tactgaacaa tccgtacgtt
421 tccagaccgc tttggcctct attaagctta ttcaggcttc tgccgttttg gatttaaccg
481 aagatgattt cgattttctg acgagtaaca aagtttggat ccctactgac cgctctcgtg
541 ctcgtcgctg cgttgaggct tgcgtttatg gtacgctgga ctttgtggga taccctcgct
601 ttcctgctcc tgttgagttt attgctgccg tcaaagctta ttatgttcat cccgtcaaca
661 ttcaaacggc ctgtctcatc atggaaggcg ctgaatttac ggaaaacatt attaatggcg
721 tcgagcgtcc ggttaaagcc gctgaattgt tcgcgtttac cttgcgtgta cgcgcaggaa
781 acactgacgt tcttactgac gcagaagaaa acgtgcgtca aaaattacgt gcggaaggag
841 tgatgtaatg tctaaaggta aaaaacgttc tggcgctcgc cctggtcgtc cgcagccgtt
Output
Your program should emit the name of the enzyme, the cut positions for that enzyme, and the contextualized cut. For the above the solution would be:
BamHI 517 agttt[g gatcc]ctactg
HaeIII 435 gcttt[gg cc]tctattaa
HaeIII 669 caaac[gg cc]tgtctcat
HindIII 444 ctatt[a agctt]attcag
HindIII 634 cgtca[a agctt]attatg
Bonus
Write some code that identifies any and all symmetrical points along the DNA sequence where an enzyme (not just the three listed) could cut. These should be even-length palindromes between 4 and 10 bases long.
Notes
If you have your own idea for a challenge, submit it to /r/DailyProgrammer_Ideas, and there's a good chance we'll post it.
2
u/Teekayz Mar 25 '15 edited Mar 25 '15
Is the output for HindIII meant to be:
HindIII 445 tatt[a agct
t]tattHindIII 635 ccgtca[a agct
t]tattOr is the BamHI example incorrect as it cuts off the 'c' at the end of the cut? I also have the same issue as /u/franza73 understanding the number of bases before/after the cut
2
u/Godd2 Mar 25 '15
Small typo. Be sure to use a backslash to escape the caret.
("\^") becomes ("^").
2
u/Godd2 Mar 25 '15 edited Mar 25 '15
Here's mine in Ruby:
I had to make a couple assumptions since I didn't know what you meant by "contextualized cut", so I just have it grab a random number of nucleotides before and after the cut.
Also, I didn't understand the indexing of your output. is it the index at the cut or just before? Or does it depend on if the cut is sticky vs blunt? I assumed the given output was a typo of some sort (probably a false assumption on my part), so my output doesn't match yours:
Also, is it a mistake that I got an additional cut point? Or was there some reason I shouldn't have grabbed it?
I'm not sure I completely understood the bonus, but here is my attempt:
and the bonus output:
1
u/jnazario 2 0 Mar 25 '15
my solution in scala:
looks like my hand determined results were off by one, and i missed one:
updated the text
5
u/Edward_H Mar 25 '15
It's been too long since I've done one of these challenges.
Here's a solution in COBOL, albeit with a few differences: it requires the number of enzymes before receiving them as input, reads the DNA genome from dna.txt, and outputs the cuts in the order they occur in the genome.
1
u/franza73 Mar 25 '15 edited Mar 25 '15
It's not clear to me what 'contextualized cut' means. Is there any logic behind the number of bases printed before and after the pattern on
BamHI 517 aagttt[g gatc]cctactgac
HaeIII 435 accgcttt[gg cc]tctatta
HindIII 445 tatt[a agctt]att
HindIII 635 ccgtca[a agctt]att
?
1
u/gfixler Mar 25 '15
What do the 5' and 3' bits on the ends mean?
2
u/franza73 Mar 25 '15 edited Mar 26 '15
Perl solution.
The output of this program is:
The bonus can be generated by the following snippet:
2
u/Robonukkah Mar 25 '15
Okay, here's my solution to the bonus in Python. It picks out all strands which are symmetric with their compliment strand.
Here's my output for the example (please note the indexes are incorrect for the example output HaeIII and HindIII)
2
u/adrian17 1 4 Mar 25 '15
Python 3, no bonus:
Output is slightly different but I think it's correct:
1
u/NoobOfProgramming Mar 25 '15
This isn't exactly the challenge, but i think it's close enough.
1
u/krismaz 0 1 Mar 25 '15 edited Mar 25 '15
In Nim, no bonus
Why would anyone make the findAll method of a regex module not return the match indices?
1
u/[deleted] Mar 26 '15
Powershell. The indices are a bit off, not sure why.
1
u/og_king_jah Mar 27 '15 edited Mar 28 '15
F# solution with the bonus.
1
u/whonut 1 0 Mar 29 '15
I really don't understand what this notation means. Can anyone enlighten me?
1
u/SleepyHarry 1 0 Mar 31 '15 edited Mar 31 '15
First pass:
Python 2.7
0
u/[deleted] Mar 25 '15
[deleted] — view deleted comment