/**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {

    MassiveTblastnPicorna mbxp = new MassiveTblastnPicorna();

    List<String> subjectGI =
        mbxp.getSubjectGI(
            new File("/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/separateByProt/queriesGI"));

    Map<String, String> genomes =
        mbxp.loadGenomes(
            subjectGI, new File("/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/PICORNAVIRIDAE.fas"));

    File tmp_fasta = new File("/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/separateByProt/tmp.fas");

    File tmp_db = new File("/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/separateByProt/tmp");

    PrintStream out =
        new PrintStream(
            "/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/separateByProt/tblastn.results");

    List<File> pssms = new ArrayList<File>();

    for (int i = 1; i < 12; i++) {

      String number = String.format("%02d", i);

      pssms.add(
          new File(
              "/home/javier/Dropbox/Posdoc/PICORNAVIRIDAE/separateByProt/ORF" + number + ".pssm"));
    }

    for (String string : subjectGI) {
      // Iterate over each genome

      String genome_sequence = genomes.get(string);

      mbxp.exportTmpFasta(genome_sequence, string, tmp_fasta);

      mbxp.makeblastdb(tmp_fasta, tmp_db);

      for (int i = 0; i < 11; i++) {
        // Iterate over each protein
        File orf_pssm = pssms.get(i);

        BlastResult result = mbxp.performTBlastn(orf_pssm, tmp_db);

        if (result != null) {

          String out_seq;

          int beginIndex = Math.min(result.getSubjectStart(), result.getSubjectEnd());

          int endIndex = Math.max(result.getSubjectStart(), result.getSubjectEnd());

          out_seq = genome_sequence.substring(beginIndex - 1, endIndex);

          if (result.getSubjectStart() > result.getSubjectEnd()) {

            out_seq = Complementary.reverseComplementary(out_seq);
          }

          out.println(">" + string + "|ORF" + String.format("%02d", i + 1));

          out.println(out_seq);
        }
      }

      System.out.println("Genome " + string + " Done.");
    }

    out.close();
  }