Difference between revisions of "CSC231 Homework 8 2017"

From dftwiki3
Jump to: navigation, search
(Starting Seed)
(Testing Your Program)
Line 83: Line 83:
 
==Testing Your Program==
 
==Testing Your Program==
 
<br />
 
<br />
I have made the executable version of the solution available.  It should already be in your PATH, so you don't need to copy it.
+
I have made the executable version of the solution available.  It should already be in your PATH, so you don't need to "getcopy" it.
To perform a batch test of your program against the solution, create two batch files. The first one is given below:
+
To perform a batch test of your program against the solution, first create a batch file using the code below, and call it '''testHw8_1.sh'''.
 
<br />
 
<br />
 
::<source lang="bash">
 
::<source lang="bash">
 
#! /bin/bash
 
#! /bin/bash
 +
# testHw8_1.sh
 
# Your name
 
# Your name
 
# Tests the hw8_1 program by feeding it different markers and DNA strings.
 
# Tests the hw8_1 program by feeding it different markers and DNA strings.
 
# The output is fed in "cat -v" which will display unprintable (junk) characters.
 
# The output is fed in "cat -v" which will display unprintable (junk) characters.
 +
 +
prog="./hw8_1"
  
 
echo AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
 
echo AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
./hw8_1 AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v  
+
$prog AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v  
  
 
echo AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
 
echo AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
./hw8_1 AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v
+
$prog AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v
  
 
echo AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT
 
echo AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT
./hw8_1 AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v
+
$prog AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v
  
 
echo AC TG ACACACACGGGGGGTGTGTGTG
 
echo AC TG ACACACACGGGGGGTGTGTGTG
./hw8_1 AC TG ACACACACGGGGGGTGTGTGTG | cat -v
+
$prog AC TG ACACACACGGGGGGTGTGTGTG | cat -v
  
 
echo AC TG TGACACACACGGGGGGTGTGTGTG
 
echo AC TG TGACACACACGGGGGGTGTGTGTG
./hw8_1 AC TG TGACACACACGGGGGGTGTGTGTG | cat -v
+
$prog AC TG TGACACACACGGGGGGTGTGTGTG | cat -v
 +
 
  
 
</source>
 
</source>
 +
<br />
 +
* Then copy this script file into another script file called '''testHw8_1sol.sh'''.
 +
 
 +
cp testHw8_1.sh  testHw8_1sol.sh
 +
 +
* Next, edit the second script and change the assignment into the $prog variable:
 +
 +
prog="hw8_1sol"
 +
 +
: (no dot dashes here!)
 +
* You now have two scripts that should output '''the exact same text''', if your program is correct.
 +
* You can go one more step toward being certain of the correctness of your output by using the '''diff''' command, as you did in  previous assignment.

Revision as of 14:14, 14 April 2017

Page under construction!

UnderConstruction.jpg




Problem #1: Programming in C


Write a C program that receives 3 DNA strings on the command line, one called marker1, one called marker2 and one called DNA, and which zaps the bases (characters) in DNA that sit between marker1 and marker2, replacing them with dashes.
Here are some examples of how the solution program operates:

231b@aurora ~ $ ./hw8_1 AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
ACCGGGGG-----------------TT
 
231b@aurora ~ $ ./hw8_1 AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
ACCGGGGGAGCCAAAGCTTTTTACCTT

231b@aurora ~ $ ./hw8_1 AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT
ACCGGGGGAGCCAAAGCTTTTTACCTT

231b@aurora ~ $ ./hw8_1 AC TG ACACACACGGGGGGTGTGTGTG
----------------TGTGTG

231b@aurora ~ $  ./hw8_1 AC TG TGACACACACGGGGGGTGTGTGTG
TG----------------TGTGTG


Notes
When the first or second markers are not found in the DNA, the program outputs the original DNA string.
When the first marker appears several time, the first occurrence is the one used.
When the second marker appears several times, its first occurrence after an occurrence of the first marker is used.
When found, the two markers are also zapped with dashes.


Starting Seed


Start with this skeleton program, and call it hw8_1.c.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void main( int argc, char *argv[] ) {
  char *marker1, *marker2, *DNA;
  char *fileName;

  if (argc < 4 ) {
    printf( "syntax: %s marker1 marker2 DNA\n", argv[0] );
    return;
  }

  marker1 = argv[1];
  marker2 = argv[2];
  DNA     = argv[3];
  
  //--- print the markers and DNA ---
  /* (for debugging purpose)
  printf( "Marker1 = %s\n", marker1 );
  printf( "Marker2 = %s\n", marker2 );
  if ( strlen( DNA ) > 80 )
    printf( "DNA     = %.*s...%s (%d bases)\n\n",
          10, DNA, DNA+((int)strlen(DNA)-10), 
	  (int) strlen( DNA) );
  else
    printf( "DNA     = %s\n\n", DNA );
  */

  //--- add your code below this point ---


}


You should uncomment the section print the markers and DNA" to see how the program gets the 3 strings.

Testing Your Program


I have made the executable version of the solution available. It should already be in your PATH, so you don't need to "getcopy" it. To perform a batch test of your program against the solution, first create a batch file using the code below, and call it testHw8_1.sh.

#! /bin/bash
# testHw8_1.sh
# Your name
# Tests the hw8_1 program by feeding it different markers and DNA strings.
# The output is fed in "cat -v" which will display unprintable (junk) characters.

prog="./hw8_1"

echo AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
$prog AGC ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v 

echo AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT
$prog AGCA ACC ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v

echo AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT
$prog AGC AT ACCGGGGGAGCCAAAGCTTTTTACCTT | cat -v

echo AC TG ACACACACGGGGGGTGTGTGTG
$prog AC TG ACACACACGGGGGGTGTGTGTG | cat -v

echo AC TG TGACACACACGGGGGGTGTGTGTG
$prog AC TG TGACACACACGGGGGGTGTGTGTG | cat -v


  • Then copy this script file into another script file called testHw8_1sol.sh.
cp testHw8_1.sh  testHw8_1sol.sh

  • Next, edit the second script and change the assignment into the $prog variable:
prog="hw8_1sol"

(no dot dashes here!)
  • You now have two scripts that should output the exact same text, if your program is correct.
  • You can go one more step toward being certain of the correctness of your output by using the diff command, as you did in previous assignment.