public void convertToSqt(int runSearchId, String outputFile) throws IOException {

    try {
      outFile = new BufferedWriter(new FileWriter(outputFile));

      SQTRunSearchDAO searchDao = DAOFactory.instance().getSqtRunSearchDAO();
      SQTRunSearch runSearch = searchDao.loadRunSearch(runSearchId);
      if (runSearch == null) {
        System.err.println("No run search found with id: " + runSearchId);
        return;
      }

      int searchDatabaseId = getSearchDatabaseId(runSearch.getSearchId());

      printSqtHeader(runSearch);
      outFile.write("\n");
      SearchFileFormat origFileType = runSearch.getSearchFileFormat();
      if (origFileType == SearchFileFormat.SQT_SEQ) {
        printSequestSQTData(runSearch, searchDatabaseId, outFile);
      } else if (origFileType == SearchFileFormat.SQT_PLUCID) {
        // TODO
      }

      outFile.flush();
    } finally {
      if (outFile != null) outFile.close();
    }
  }
  private void printSequestSQTData(
      SQTRunSearch runSearch, int searchDatabaseId, BufferedWriter outFile) throws IOException {

    List<MsResidueModification> dynaResidueModsDb =
        getDynaResidueModsForSearch(runSearch.getSearchId());

    SQTSearchScanDAO scanDao = DAOFactory.instance().getSqtSpectrumDAO();

    SequestSearchResultDAO resultDao = DAOFactory.instance().getSequestResultDAO();
    List<Integer> resultIds = resultDao.loadResultIdsForRunSearch(runSearch.getId());
    int currCharge = -1;
    int currScanId = -1;
    SearchScan currScan = null;
    for (Integer resultId : resultIds) {
      SequestSearchResult result = resultDao.load(resultId);
      if (result.getScanId() != currScanId || result.getCharge() != currCharge) {
        if (currScan != null) {
          outFile.write(currScan.toString());
          outFile.write("\n");
        }
        currScanId = result.getScanId();
        currCharge = result.getCharge();
        SQTSearchScan scanDb =
            scanDao.load(runSearch.getId(), currScanId, currCharge, result.getObservedMass());
        currScan = makeScanResult(scanDb);
      }
      List<MsResidueModificationIn> dynaResidueMods = new ArrayList<MsResidueModificationIn>();
      for (MsResidueModification modDb : dynaResidueModsDb) {
        dynaResidueMods.add(modDb);
      }
      SequestResult peptResult = new SequestResult();
      peptResult.setResultPeptide(result.getResultPeptide());
      SequestResultData data = result.getSequestResultData();
      peptResult.setCharge(result.getCharge());
      peptResult.setObservedMass(result.getObservedMass());
      peptResult.setDeltaCN(data.getDeltaCN());
      peptResult.setCalculatedMass(data.getCalculatedMass());
      peptResult.setMatchingIons(data.getMatchingIons());
      peptResult.setPredictedIons(data.getPredictedIons());
      peptResult.setOriginalPeptideSequence(
          reconstructSequestPeptideSequence(runSearch.getSearchId(), result));
      peptResult.setScanNumber(currScan.getScanNumber());
      peptResult.setSp(data.getSp());
      peptResult.setSpRank(data.getSpRank());
      peptResult.setValidationStatus(result.getValidationStatus().getStatusChar());
      peptResult.setxCorr(data.getxCorr());
      peptResult.setxCorrRank(data.getxCorrRank());
      peptResult.setEvalue(data.getEvalue());

      List<MsSearchResultProtein> proteins = getProteinsForResultId(resultId);
      for (MsSearchResultProtein pr : proteins) {
        peptResult.addMatchingLocus(pr.getAccession(), null);
      }
      // currScan.addPeptideResult(peptResult);
    }
    // print the last one
    if (currScan != null) {
      outFile.write(currScan.toString());
      outFile.write("\n");
    }
  }