Suppose we are interested in studying a DNA sequence which consists of four base
ID: 3936536 • Letter: S
Question
Suppose we are interested in studying a DNA sequence which consists of four bases: A, C, G, and T. For example: TGCGTGCTACCACATCATGCAGTTTTCAAAGAAGAAAGCTCACCACAAA. Write a function of the form setupRandDNASeq(int n, char dna) which creates a random string of length Din. Write a function of the form int getBaseCount (char dina[], char base), where DNAstr is a DNA string and base is a single character The function returns how many times base occurs in the string. For example, in the above string. "T" occurs 10 times. Write a function called void getAlIBaseCounts(char dna[], int baseCountArray[]) that computes the statistics of how many fanes each have occurs m DMAstr. Here, baseCountArray[] will be a -dimensional array containing the counts for A, C, G and T. Write a function called printStats (char dna, int baseCountArray []) that takes in the DNA string and the 4-dimensional array of base counts and prints the percentages to the screen in the following format: Write a function of the form void blankOut (char dna[], char base, char dotStr[]) which given a DNA string creates a new string by blanking out (convert to.) (any character other than the specified base. For example, suppose base - "T", then the follow tag string will be created. dna: TGCGTGCTACCACATCATOCAGTTTTCAAAGAAGAAACCCTCACCACAAA dot Str: A. .A. A. .A... A...AAA. AA. AAA...A.. A.AAA Write a function called void displayAllBlankOut {char dna[]) which displays all 4 blank out strings. We talked about the follow mg string functions that are available m C (as long as you include string.h); int strlen(char str[]) void strepy {char strl[], char str 2 []) void strcat {char strl [], str2 []) Write your own versions of these functions, for example int paul_strlen(int char strr[]).Explanation / Answer
Here is the functions for the first 4 functions:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void setupRandDNASeq(int n, char dna[])
{
for(int i = 0; i < n; i++)
{
int x = rand() % 4;
if(x == 0)
dna[i] = 'A';
else if(x == 1)
dna[i] = 'C';
else if(x == 2)
dna[i] = 'G';
else
dna[i] = 'T';
}
dna[n] = '';
}
int getBaseCount(char dna[], char base)
{
int count = 0;
for(int i = 0; i < strlen(dna); i++)
if(dna[i] == base)
count++;
return count;
}
void getAllBaseCounts(char dna[], int baseCountArray[])
{
for(int i = 0; i < 4; i++)
baseCountArray[i] = 0;
for(int i = 0; i < strlen(dna); i++)
if(dna[i] == 'A')
baseCountArray[0]++;
else if(dna[i] == 'C')
baseCountArray[1]++;
else if(dna[i] == 'G')
baseCountArray[2]++;
else
baseCountArray[3]++;
}
void printStats(char dna[], int baseCountArray[])
{
getAllBaseCounts(dna, baseCountArray);
printf("Sequence: %s", dna);
printf("Length: %lu ", strlen(dna));
printf("Base Statistics A: %.1f ", baseCountArray[0] / (float)strlen(dna));
printf("C: %.1f ", baseCountArray[1] / (float)strlen(dna));
printf("G: %.1f ", baseCountArray[2] / (float)strlen(dna));
printf("T: %.1f ", baseCountArray[3] / (float)strlen(dna));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.