[SOLVED] C CS1132 Fall 2019 Assignment 1 (due 9/19 Thursday 11:59pm)

$25

File Name: C_CS1132_Fall_2019_Assignment_1_(due_9/19_Thursday_11:59pm).zip
File Size: 555.78 KB

5/5 - (1 vote)

CS1132 Fall 2019 Assignment 1 (due 9/19 Thursday 11:59pm)
Adhere to the Code of Academic Integrity. You may discuss background issues and general strategies with others and seek help from course staff, but the implementations that you submit must be your own. In particular, you may discuss general ideas with others but you may not work out the detailed solutions with others. It is never OK for you to see or hear another students code and it is never OK to copy code from published/Internet sources. If you feel that you cannot complete the assignment on you own, seek help from the course staff.
When submitting your assignment, follow the instructions summarized in Section 3 of this document.
1 Simple Genetic Mutations (i) Random integer generator
Do not use the break or continue statement in any homework or test in CS1132.
Using the help command, learn about the rand, ceil, fix, and floor functions. After reading
brief description, implement a random integer generator using those functions only. Implement the following function:
function result = myRandInt(startInt,endInt)
% Returns an integer from startInt to endInt, inclusive, with equal probability.
% If startInt > endInt, set startInt as the upper bound and endInt as the lower
% bound.
% startInt, endInt, and result are each an integer.
(ii) Mutating a single gene in DNA
A nucleic acid sequence in a DNA can be written as an ordered list using a four-letter alphabet: A (adenine), C (cytosine), G (guanine), and T (thymine). Here, we simulate a simple random DNA mutation that works as follows. 1) A position within the sequence is picked randomly and 2) the corresponding letter is mutated to one of the four letters with equal probability (i.e. 0.25). Notice that there can be cases where the picked letter does not change. By making effective use of function myRandInt from the previous problem, implement the following function:
function [new_dna, pos] = mutate(dna)
% Mutate a single entry within dna.
% dna is a 1d-array of integers in [1..4] representing a DNA sequence;
%1, 2, 3, and 4 in dna indicate A, C, G, and T, respectively.
% new_dna stores the mutated sequence; it is dna with at most 1 entry changed.
% pos is the index at which the mutation occurred, pos is an index of dna.
Example: one possible set of output from mutate([3,1,2,3,4]) is new dna = [3,3,2,3,4] and pos = 2.
1
their
Remember what it means to implement a function: write code according to the specification. Following specifications is not a choice; it is a requirement. Code that does not follow specifications is incorrect. Your function file must have the exact function header given here, including the name of the function as well as the names and order of the parameters. Correspondingly the file name must be myRandInt.m. Copy the entire function comment given above into your function filenotice that the comment must explain all the parameters.

(iii) Printing the sequence
Since the letter at the picked position can mutate into the same letter leading to no visible change, it would help to have a function that prints the sequence while indicating the position at which the mutation actually occurred. Implement the following function:
function printDNA(dna, pos)
% Neatly print the DNA sequence represented by dna using actual letters,
% A instead of 1, C instead of 2, G instead of 3, and T instead of 4.
% The letter at index pos must be put within parentheses.
% dna is a 1d-array with integers in [1..4] and pos is an index of dna.
Example: printDNA([3,1,2,3,4], 3) should print GA(C)GT.
Hint: You can print a line of text one character at a time with fprintf, using the newline character,
,
only at the end of the line. Consider the following code fragment:
fprintf(H)
fprintf(e)
fprintf(llo)
fprintf(
)
The printed text would be the same as the output of fprintf(Hello
). (iv) Multiple mutations
Write a script multipleMutations to display the outcomes of the first 10 mutations. Make effective use of functions mutate and printDNA from the previous problems. The DNA sequence after each mutation must be printed with the actual letters (A, C, G, and T), while highlighting the position at which the mutation has just occurred with parentheses. Below are several lines of example output:
No. DNA
1 AT(G)CTTCG
2 ATGC(A)TCG
3 ATGCAT(C)G
4 AT(G)CATCG
5 ATGCATC(T)
6 (G)TGCATCT
You may use any initial DNA sequence of length 8 in your script.
(v) Counting silent mutations
Modify your script multipleMutations such that mutations stop if two consecutive mutations do not change the sequence, or after 10 mutations, whichever occurs first. Use the same print format as shown above. Save this file as sequence.m.
(vi) Estimating probabilities
In this final problem, you will use simulation to estimate the probabilities of some events, making effective use of mutate. In an experiment, we define a mutation set to be 3 mutations on a DNA sequence with a length of at least 8. Multiple mutation sets will be applied to the sequence. With each mutation set we want to detect these events:
Event A: all three mutations change the sequence.
Event B: at least one mutation occurs at the first position of the sequence.
Event C: two consecutive mutations both result in the letter G (at the positions of mutation).
2

Write two functions that simulate n mutation sets applied to a sequence dna. One function estimates the probability of A B (A or B happening) and the other estimates the probability of A C (both A and C happening). The probability of an event is estimated as the number of occurrences of that event divided by the number of trials. Implement the following two functions:
function p = AorB(dna, n)
% p is the probability of event A or event B occurring when executing a
% mutation set (3 mutations) on the initial sequence dna.
% dna is a 1d array of integers in [1..4]; length of dna is >= 8.
% n is the integer number of trials, n>0.
function p = AandC(dna, n)
% p is the probability of both event A and event C occurring when executing
% a mutation set (3 mutations) on the initial sequence dna.
% dna is a 1d array of integers in [1..4]; length of dna is >= 8.
% n is the integer number of trials, n>0.
2 Self-check list
The following is a list of the minimum necessary criteria that your assignment must meet in order to be considered satisfactory. Failure to satisfy any of these conditions will result in an immediate request to resubmit your assignment. Save yourself and the graders time and effort by going over it before submitting your assignment for the first time. Although all these criteria are necessary, meeting all of them might still not be sufficient to consider your submission satisfactory. We cannot list everything that could be possibly wrong with any particular assignment!

3
1.
2.
Comment your code! Make sure your functions are properly commented, regarding function purpose and input/output parameters.
Suppress all unnecessary output by placing semicolons (;) appropriately. At the same time, make sure that all output that your program intentionally produces is formatted in a user-friendly way.
Make sure your functions names are exactly the ones we have specified, including case.
Check that the number and order of input and output parameters for each of the functions match
exactly the specifications we have given.
Test each one of your functions independently, whenever possible, or write short scripts to test them.
Check that your scripts do not crash (i.e., end unexpectedly with an error message) or run into infinite loops. Check your script several times in a row. Before each test run, type the commands clear all; close all; to delete all variables in the workspace and close all figure windows.
Submission instructions
Upload files myRandInt.m, mutate.m, printDNA.m, multipleMutations.m, sequence.m, AorB.m, and AandC.m to CMS in the submission area corresponding to Assignment 1 in CMS before the deadline. Late submission is accepted up to 24 hours after the deadline with a 10% penalty.
After grading: If you resubmit the assignment, upload your corrected files and be sure to select the Regrade Request option.
3

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] C CS1132 Fall 2019 Assignment 1 (due 9/19 Thursday 11:59pm)
$25