dna01.txt c coding, gcc compiler Bonus. DNA Subsequence A DNA sequence is a sequ
ID: 3777014 • Letter: D
Question
dna01.txt
c coding, gcc compiler
Bonus. DNA Subsequence A DNA sequence is a sequence of some combination of the characters A (adenine), C (cytosine), G (guanine), and T mine) which correspond to the four nucleobases that make up DNA. Given a long DNA sequence, its often necessary to compute the number of instances of a certain subsequence. For this exercise, you will develop a program that processes a DNA sequence from a file and, given a subequence S, searches the DNA sequence and counts the number of times s appears. As an example, consider the following sequence: GGAAGTAG CAGGCCGCATGC TTGGAGGTAAAGTTCAT GGTTCCCTGGCCC If we were to search for the subsequence GTA, it appears twice. You will write a program (place your source in a file named dnaSearch.c) that takes, as command line inputs, an input file name and a valid DNA (sub)sequence. That is it should be callable from the command line as: ./dnaSearch dna01.txt GTA GTA appears 2 timesExplanation / Answer
#include<stdio.h>
#include <string.h>
#include <malloc.h>
int main( int argc, char *argv[] ) {
char str[100],sub[10],string[1][100];
int i=0, j, l, l1, l2,count=0;
char dest[100] = { 0 };
if( argc == 3 ) {
printf(" ");
}
else if( argc > 3 ) {
printf("Too many arguments supplied. ");
}
else {
printf("One argument expected. ");
}
FILE *file = fopen( argv[1], "r" );
if ( file == 0 )
{
printf( "Could not open file " );
}
else
{
fscanf( file, "%s", str);
//printf("File Content: %s ", str);
fclose( file );
}
printf( "substring to search:%s ", argv[2] );
strcpy(sub,argv[2]);
l1 = strlen(str);
l2 = strlen(sub);
while (i< l1) {
strncpy(dest, str+(i), l2);
i++;
if(strcmp(dest,sub) == 0){
count++;
}
}
printf("%s occurs %d times ", sub, count);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.