Ejemplo n.º 1
0
  // constructor
  public TQuery(String[] args) {
    try {
      long startTime = System.currentTimeMillis();
      processArgs(args);

      queryIndex = new QueryIndex(this);
      queryLoader = new QueryLoader(this);

      // print some stats on building the engine
      String diffTime =
          Num.formatNumberOneFraction(((double) (System.currentTimeMillis() - startTime)) / 1000);
      int numFiles = vcfDataFiles.length + bedDataFiles.length + mafDataFiles.length;
      System.err.println("\n" + diffTime + " Sec to build using " + IO.memory() + " of RAM");
      System.err.println("\t" + numFiles + "\tData sources loaded");
      System.err.println("\t" + dataSources.getRecordsLoaded() + "\tRecords indexed");
      System.err.println("\t" + dataSources.getRecordsSkipped() + "\tRecords skipped\n");

      // print summary of available filters
      System.err.println(dataSources.fetchSummary());

      queryFilesFromCmdLine();

      // release file handles
      queryLoader.closeTabixReaders();

    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("\nProblem with executing the TQuery!");
    }
  }
Ejemplo n.º 2
0
  /**
   * Makes a stair step heat map from an array of windows in bar format. One per chromosome. Don't
   * forget to set the barDirectory and score Index!!!!!!!
   */
  public void makeStairStepBarFiles() {
    // make bar parser
    BarParser bp = new BarParser();
    bp.setZipCompress(true);
    HashMap<String, String> tagVals = new HashMap<String, String>();
    tagVals.put(BarParser.GRAPH_TYPE_TAG, BarParser.GRAPH_TYPE_STAIRSTEP);
    tagVals.put(BarParser.GRAPH_TYPE_COLOR_TAG, "#FF00FF"); // fusha
    tagVals.put(BarParser.SOURCE_TAG, bedFile.toString());

    // for each chromosome
    System.out.print("Printing... ");
    Iterator<String> it = bedLinesHash.keySet().iterator();
    while (it.hasNext()) {
      chromosome = it.next();
      System.out.print(chromosome + " ");
      windows = bedLinesHash.get(chromosome);
      // add blocks
      assembleBlocks();
      // balance by adding max or min at zero base
      balanceValues();
      // write bar file
      File barFile = new File(barDirectory, chromosome + ".bar");
      bp.writeBarFile(
          barFile,
          chromosome,
          genomeVersion,
          '.',
          Num.arrayListOfIntegerToInts(bases),
          Num.arrayListOfFloatToArray(values),
          tagVals);
      // clear ArrayLists
      bases.clear();
      values.clear();
    }
    System.out.println();
  }
  /**
   * Chr\tPos\tRef\tAlt\tName\tSampleNames\tRefAltCounts\tTotalRef\tTotalAlt\tSampleGCScores\tFDR\tLog2Rto\tBadHetCall?
   */
  public String toString(boolean skipGeneral) {
    StringBuilder sb = new StringBuilder();
    if (skipGeneral == false) {
      sb.append(chromosome);
      sb.append("\t");
      sb.append(position);
      sb.append("\t");
      sb.append(reference);
      sb.append("\t");
      sb.append(alternate);
      sb.append("\t");
      sb.append(name);
      sb.append("\t");
    }
    int numRef = 0;
    int numAlt = 0;
    if (sampleName != null) {
      // sampleNames
      String sampleNames = Misc.stringArrayListToString(sampleName, ",");
      sb.append(sampleNames);
      sb.append("\t");

      // ref/alt counts
      int[] refAltCounts = getRefAltCounts(gatcnCounts.get(0));
      sb.append(refAltCounts[0]);
      sb.append("_");
      sb.append(refAltCounts[1]);
      numRef += refAltCounts[0];
      numAlt += refAltCounts[1];
      for (int i = 1; i < gatcnCounts.size(); i++) {
        sb.append(",");
        refAltCounts = getRefAltCounts(gatcnCounts.get(i));
        sb.append(refAltCounts[0]);
        sb.append("_");
        sb.append(refAltCounts[1]);
        numRef += refAltCounts[0];
        numAlt += refAltCounts[1];
      }
      sb.append("\t");
      // totals
      sb.append(numRef);
      sb.append("\t");
      sb.append(numAlt);
      sb.append("\t");

      // sample scores
      float[] s = Num.arrayListOfFloatToArray(sampleGCScore);
      String scores = Misc.floatArrayToString(s, ",");
      sb.append(scores);
      sb.append("\t");
      // fdr
      sb.append(fdr);
      sb.append("\t");
      // log2Rto
      sb.append(log2Ratio);
      // bad het call?
      if ((numRef + numAlt != 0) && (numRef == 0 || numAlt == 0)) sb.append("\ttrue");
      else sb.append("\tfalse");
      // gene names?
      if (geneNames != null) {
        sb.append("\t");
        sb.append(Misc.stringArrayListToString(geneNames, ","));
      }
    }
    return sb.toString();
  }
 public boolean passMinCoverage(int minimumReadCoverage) {
   for (int i = 0; i < gatcnCounts.size(); i++) {
     if (Num.sumIntArray(gatcnCounts.get(i)) >= minimumReadCoverage) return true;
   }
   return false;
 }