Advertisement
makispaiktis

Codecademy - Open Exercise (pAequor DNA - Pronunciation)

Dec 23rd, 2019 (edited)
2,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Project Goals
  2. Context: You’re part of a research team that has found a new mysterious organism at the bottom of the ocean near hydrothermal vents. Your team names the organism, Pila aequor (P. aequor), and finds that it is only comprised of 15 DNA bases. The small DNA samples and frequency at which it mutates due to the hydrothermal vents make P. aequor an interesting specimen to study. However, P. aequor cannot survive above sea level and locating P. aequor in the deep sea is difficult and expensive. Your job is to create objects that simulate the DNA of P. aequor for your research team to study.
  3.  
  4. As you progress through the steps, use the terminal and console.log() statements to check the output of your loops and functions.
  5.  
  6.  
  7. Prerequisites
  8. 1.
  9. In order to complete this project, you should have completed the first few sections of Introduction to JavaScript (through Learn JavaScript: Objects).
  10.  
  11. Project Requirements
  12. 2.
  13. Look over the starter code. There are two helper functions: returnRandBase() and mockUpStrand().
  14.  
  15. DNA is comprised of four bases (Adenine, Thymine, Cytosine, and Guanine). When returnRandBase() is called, it will randomly select a base and return the base ('A','T','C', or 'G').
  16.  
  17. mockUpStrand() is used to generate an array containing 15 bases to represent a single DNA strand with 15 bases.
  18.  
  19. You’ll use these helper functions later to create your objects that represent P. aequor.
  20.  
  21. 3.
  22. Since you need to create multiple objects, create a factory function pAequorFactory() that has two parameters:
  23.  
  24. The first parameter is number (no two organisms should have the same number).
  25. The second parameter is an array of 15 DNA bases.
  26. pAequorFactor() should return an object that contains the properties specimenNum and dna that correspond to the parameters provided.
  27.  
  28. You’ll also add more methods to this returned object in the later steps.
  29.  
  30. Visit the factory functions exercise for a refresher. This forum post also explains the use case for factory functions.
  31.  
  32. You can test pAequorFactory() by calling it with the arguments: 1 and mockUpStrand(). Check to see that the returned object contains the requested two properties: specimenNum and dna. You can also provide a specific strand of DNA rather than providing a randomized strand using mockUpStrand().
  33.  
  34. 4.
  35. Your team wants you to simulate P. aequor‘s high rate of mutation (change in its DNA).
  36.  
  37. To simulate a mutation, in pAequorFactory()‘s returned object, add the method .mutate().
  38.  
  39. .mutate() is responsible for randomly selecting a base in the object’s dna property and changing the current base to a different base. Then .mutate() will return the object’s dna.
  40.  
  41. For example, if the randomly selected base is the 1st base and it is 'A', the base must be changed to 'T', 'C', or 'G'. But it cannot be 'A' again.
  42.  
  43. returnRandBase() contains a method for selecting a random element in an array using Math.floor() and Math.random().
  44.  
  45. You can also use returnRandBase() to generate a random base, but make sure that the current base and the generated base are not the same.
  46.  
  47. You can test this method by creating an instance of pAequor and checking that its .dna changes after calling .mutate() on itself.
  48.  
  49. 5.
  50. Your research team wants to be able to compare the DNA sequences of different P. aequor. You’ll have to add a new method (.compareDNA()) to the returned object of the factory function.
  51.  
  52. .compareDNA() has one parameter, another pAequor object.
  53.  
  54. The behavior of .compareDNA() is to compare the current pAequor‘s .dna with the passed in pAequor‘s .dna and compute how many bases are identical and in the same locations. .compareDNA() does not return anything, but prints a message that states the percentage of DNA the two objects have in common — use the .specimenNum to identify which pAequor objects are being compared.
  55.  
  56. For example:
  57.  
  58. ex1 = ['A', 'C', 'T', 'G']
  59. ex2 = ['C', 'A', 'T', 'T']
  60. ex1 and ex2 only have the 3rd element in common ('T') and therefore, have 25% (1/4) of their DNA in common. The resulting message would read something along the lines of: specimen #1 and specimen #2 have 25% DNA in common.
  61.  
  62. You’re adding this method inside the return object of the factory function like .newMethod() below:
  63.  
  64. const sampleFactory = () => {
  65.   return {
  66.     newMethod() {
  67.     }
  68.   }
  69. }
  70. There are many ways to create this method, most involve iterating through both arrays at the same time and comparing the elements with the same indices.
  71.  
  72. To calculate the percentage, take the number of identical bases, divided by the total number of bases and multiply the result by 100. You can use a method like .toFixed() to limit the number of decimal places seen.
  73.  
  74. Remember to check your method by creating two instances of pAequor and comparing their DNA.
  75.  
  76. 6.
  77. P. aequor have a likelier chance of survival if their DNA is made up of at least 60% 'C' or 'G' bases.
  78.  
  79. In the returned object of pAequorFactory(), add another method .willLikelySurvive().
  80.  
  81. .willLikelySurvive() returns true if the object’s .dna array contains at least 60% 'C' or 'G' bases. Otherwise, .willLikelySurvive() returns false.
  82.  
  83. 7.
  84. With the factory function set up, your team requests that you create 30 instances of pAequor that can survive in their natural environment. Store these instances in an array for your team to study later.
  85.  
  86. Remember, you only want to add the instance to the array if .willLikelySurvive() returns true for that instance.
  87.  
  88. Project Extensions & Solution
  89. 8.
  90. Great work! If you’d like, you can compare your project to our solution code. Your solution might not look exactly like ours, and that’s okay! The most important thing is to get the correct answers for now.
  91.  
  92. 9.
  93. If you’d like to challenge yourself further, you could consider the following:
  94.  
  95. Create a .complementStrand() method to the factory function’s object that returns the complementary DNA strand. The rules are that 'A's match with 'T's and vice versa. Also, 'C's match with 'G's and vice versa. (Check the hint for more details)
  96. Use the .compareDNA() to find the two most related instances of pAequor.
  97. DNA sequences are found in nature as double-stranded structures (helices). The rules are that 'A' bases bind with 'T' bases (and vice versa) and 'C' bases bind with 'G' bases (and vice versa).
  98.  
  99. Suppose we have two strands of DNA, we’ll call them strand1 and strand2. If the strand1’s first base is an 'A', then the strand2’s opposing base is a 'T'. If the second spot of strand1 is a 'C', then strand2’s opposing base is a 'G'.
  100.  
  101. To show this as part of your code, if a .dna sequence is:
  102.  
  103. [ 'T', 'A', 'C', 'A', 'G', 'A', 'T', 'A', 'C', 'G', 'A', 'C', 'G', 'A', 'T' ]
  104. Then .complementStrand() should return:
  105.  
  106. [ 'A', 'T', 'G', 'T', 'C', 'T', 'A', 'T', 'G', 'C', 'T', 'G', 'C', 'T', 'A' ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement