Suppose we are interested in studying a DNA sequence which consists of four base
ID: 3935584 • Letter: S
Question
Suppose we are interested in studying a DNA sequence which consists of four bases: A, C, G and T. For example: TGCGTGCTACCACATCATGCAGTTTTCAAAG AAGAAAGCCTCACCACAAA. Write a function of the form setupRandDNASeq (int n, char dna) which creates a random string of length Dim. Write a function of the form int getBaseCount(char dna[], 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 getAllBaseCounts (char dna[], int baseCountArray[]) that computes the statistics of how many times each base occurs in DNAstr. Here, baseCountArray [] will be a 4-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: Sequence: TGCGTGCTACCACATCATGCAGTTTTCAAAGAAGAAAGCCTCACCACAAA Length: 50 Base Statistics A: 26.4 C: 44.1 G: 34.8 T: 13.6 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 following string will be created. dna: TGCGTGCTACCACATCATGCAGTTTTCAAAGAAGAAAGCCTCACCACAAA dotStr: ......A..A.A..A...A....AAA.AA.AAA.....A..A.AAA Write a function called void displayAllBlanfcOut (char dna []} which displays all 4 blank out strings.Explanation / Answer
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int getBaseCount(char dna[],char base)
{
int length,count=0,i;
length=strlen(dna);
for(i=0;i<length;i++)
{
if(dna[i]==base)
{
count++;
}
}
return count;
}
void getAllBaseCounts(char dna[],int baseCountArray[])
{
int length,i;
length=strlen(dna);
for(i=0;i<length;i++)
{
if(dna[i]=='A')
{
baseCountArray[0]++;
}
if(dna[i]=='C')
{
baseCountArray[1]++;
}
if(dna[i]=='G')
{
baseCountArray[2]++;
}
if(dna[i]=='T')
{
baseCountArray[3]++;
}
}
printf("Base Count for bases A,C,G,T are %d %d %d %d ",baseCountArray[0],baseCountArray[1],baseCountArray[2],baseCountArray[3]);
}
void blankOut(char dna[],char base,char dotStr[])
{
int length,i;
length=strlen(dna);
for(i=0;i<length;i++)
{
if(dna[i]!=base)
{
dotStr[i]='.';
}
else
{
dotStr[i]=dna[i];
}
}
dotStr[i]='';
printf("%s ",dotStr);
}
void displayAllBlankOut(char dna[])
{
int length,i;
length=strlen(dna);
for(i=0;i<length;i++)
{
printf("%c",'.');
}
printf(" ");
}
void printStats(char dna[],int baseCountArray[] )
{
int length,i;
length=strlen(dna);
printf("Sequence: %s ",dna);
printf("Length: %d ",length);
printf("Base Statistics ");
printf("A: %f ",((float)baseCountArray[0]/(float)length)*100);
printf("C: %f ",((float)baseCountArray[1]/(float)length)*100);
printf("G: %f ",((float)baseCountArray[2]/(float)length)*100);
printf("T: %f ",((float)baseCountArray[3]/(float)length)*100);
}
void setupRandDNASeq(int n,char dna[])
{
int count_A = rand() % n;
int remain=n;
remain = remain-count_A;
int count_C = rand() % remain;
remain = remain-count_C;
int count_G = rand() % remain;
remain = remain-count_G;
int count_T = remain,i=0;
while(count_A>0)
{
dna[i]='A';
count_A--;
i++;
}
while(count_C>0)
{
dna[i]='C';
count_C--;
i++;
}
while(count_G>0)
{
dna[i]='G';
count_G--;
i++;
}
while(count_T>0)
{
dna[i]='T';
count_T--;
i++;
}
dna[i]='';
printf("%s",dna);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
char input_dna[100],dotStar[100],count;
int baseCount[4]={};
int length;
scanf("%d",&length);
setupRandDNASeq(length,input_dna);
count = getBaseCount(input_dna,'A');
printf("%d ",count);
blankOut(input_dna,'A',dotStar);
displayAllBlankOut(input_dna);
getAllBaseCounts(input_dna,baseCount);
printStats(input_dna,baseCount);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.