Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CS121 A'11: Virtual Southern Blot
- *
- * java SouthernBlot <sequence file name> <restriction enzyme> <probe file name>
- *
- * Hannah Provenza 388257
- *
- */
- public class SouthernBlot {
- /* genFilm:
- * String sequence: the sequence to be examined
- * String enzyme: the restriction enzyme
- * String probe: the probe to be matched
- *
- * returns a film represented a boolean array in which the ith
- * element is true if there is a restriction fragment with
- * log(size) equal to i that is the complement of the probe.
- */
- public static boolean[] genFilm(String s, String enzyme, String probe) {
- s = s.toUpperCase();
- enzyme = enzyme.toUpperCase();
- probe = probe.toUpperCase();
- String[] fragments = restrictFragments(s, enzyme);
- Utility.gelElectrophoresis(fragments);
- String probeReversed = convertProbe(probe);
- int k = ((int)Math.log10(fragments[0].length()) + 1);
- boolean[] film = new boolean[k];
- // gelElectrophoresis has LONGEST string first, so we're going to count DOWN on film, where longest is last, and UP on fragments, where longest is first.
- int c = k - 1; // c is the index of film
- /*while (c >= 0){
- // Establish a count up through fragments.
- for (int x = 0; x < fragments.length; x++){
- // Establish a count up through fragments[x].
- for (int y = 0; y < fragments[x].length(); y++){
- // Change the boolean for film
- if (enzymeMatchAt(fragments[x], probeReversed, y)){
- film[c] = true;
- break;
- }
- }
- // Establish a condition for changing the count through film.
- if (fragments[x+1].length() < Math.pow(10, c+1)){ //if the next fragment is small enough to fit into the next smallest film slot, proceed to the next film slot.
- c--;
- }
- if (x+1 >= fragments.length){
- return film;
- }
- }
- }
- return film;
- */
- for (int x = 0; x < fragments.length; x++) {
- for (int y = 0; y < fragments[x].length(); y++) {
- if (enzymeMatchAt(fragments[x], probeReversed, y)) {
- film[(int)Math.log10(fragments[x].length())] = true;
- }
- }
- }
- return film;
- }
- /* drawFilm: draw a picture of the film with the largest fragments
- * at the top and the smallest at the bottom. Each element in
- * the film will be represented by colored rectangle, RED for
- * slots where the corresponding element in the film is true and
- * BLACK otherwise.
- */
- public static void drawFilm(boolean[] film) {
- // YOUR CODE GOES HERE
- }
- // YOUR AUXILIARY FUNCTIONS GO HERE
- public static boolean enzymeMatchAt(String s, String enzyme, int start){
- if (s.length() - start < enzyme.length())
- return false;
- for (int i = 0; i < enzyme.length(); i++){
- if (s.charAt(start+i) != enzyme.charAt(i)){
- return false;
- }
- }
- return true;
- }
- public static String[] restrictFragments(String s, String enzyme){
- int a = Utility.countOccurrences(s, enzyme);
- String fragments[] = new String[a+1]; //This will return an array that may be too big in the case that the last few characters in the fragment are the enzyme, but that shouldn't have any consequences for the program.
- for (int y = 0; y < a+1; y++){
- fragments[y] = "";
- }
- int b = 0; // b tracks the slot in fragments
- int i = 0; // i tracks progress through s
- while (i < s.length()){
- if (enzymeMatchAt(s, enzyme, i)){
- fragments[b] = fragments[b] + enzyme;
- b++;
- i = i + enzyme.length();
- } else {
- fragments[b] = fragments[b] + s.charAt(i);
- i++;
- }
- }
- return fragments;
- }
- public static String convertProbe(String probe){
- String probeReversed = "";
- int i = 0;
- while(i < probe.length()){
- if (probe.charAt(i) == 'A'){
- probeReversed = probeReversed + 'T';
- } else {
- if (probe.charAt(i) == 'T'){
- probeReversed = probeReversed + 'A';
- }
- }
- if (probe.charAt(i) == 'C'){
- probeReversed = probeReversed + 'G';
- } else {
- if (probe.charAt(i) == 'G'){
- probeReversed = probeReversed + 'C';
- }
- }
- i++;
- }
- return probeReversed;
- }
- public static void main(String[] args) {
- if (args.length != 3) {
- System.err.println("usage: java SouthernBlot <sequence file name> <restriction enzyme> <probe file name>");
- System.exit(0);
- }
- String sequence = Utility.readSequence(args[0]);
- String enzyme = args[1].toUpperCase();
- String probe = Utility.readSequence(args[2]);
- boolean[] film = genFilm(sequence, enzyme, probe);
- drawFilm(film);
- }
- }
Add Comment
Please, Sign In to add comment