//Anton Dubrau
//comp202, summer 2010, ass5 solutions

import java.io.*;
import java.util.*;

//DNA string stores a bit of dna string, with an associated species
//allows computing the edit distance between DNA Strings, as a measure of similarity

class DNAString{
  private String dna, species;
  
  //constructor taking a file name
  //removes white space and converts dna string to lower case
  public DNAString(String filename){
    try {
      //open file for reading, and build scanner
      FileReader f = new FileReader(filename);
      Scanner scan = new Scanner(f);

      //get species
      species = scan.nextLine();

      //get string
      dna = "";
      while (scan.hasNext()){
        dna += scan.nextLine();
      }

      //convert to lower case, and remove any non gtac characters
      dna = StringUtils.filter(dna.toLowerCase(),"gtac");
    } catch (Exception e){
      System.out.println("Encountered exception "+e+" when tryingo to read: "+filename);
    }
  }

  //constructor just taking the data
  public DNAString(String species,String dnaString){
    this.species = species;
    dna = dnaString;
  }

  //to string method - returns String representation of object
  public String toString(){
    return species+": "+dna;
  }

  //returns the species of the String
  public String getSpecies(){
    return species;
  }

  //returns the DNA String
  public String getDna(){
    return dna;
  }

  //returns the edit distance of the given dna string to this' dna string as an integer
  public int getMutations(DNAString other){
    return StringUtils.getDistance(dna,other.dna);
  }


  //main - reads a dna sequence and spits it out as a dna string
  //with spaces and some capital letters
  public static void main(String[] args){
    //read dna string from file
    DNAString dna1 = new DNAString(args[0]);
    
    //spit out dna string on terminal, with some added formatting sugar
    String t = dna1.species+"\n\n";
    String dna = dna1.dna+"     ";
    for (int i = 0; i < dna1.dna.length(); i += 4 ){
      t += dna.toUpperCase().charAt(i);
      t += dna.charAt(i+1);
      t += dna.charAt(i+2);
      t += dna.charAt(i+3) + " ";
      if ((i+4) % 64 == 0) t += '\n';
    }

    System.out.println(t);
  }
}


