Exemple #1
0
  public void wirteChainsIntoAGffFile(
      ArrayList<Double> PDScores, String blockId, String pathToChainsDir, double scoreThreshold)
      throws IOException {
    String blockSpecfications[] = blockId.split("_");
    String Chr = blockSpecfications[0];
    String gffoutputFileName = pathToChainsDir + "/" + blockId + ".gff";
    PrintWriter pw = new PrintWriter(new FileWriter(gffoutputFileName));
    final GFFWriter gffw = new GFFWriter(pw);
    int numberOfPDScores = PDScores.size();
    int oneStart = 0;
    int oneEnd = 0;
    int dummyPos = 0;

    for (int i = 0; i < numberOfPDScores - 1; i++) {
      double thisScore = PDScores.get(i);
      double nextScore = PDScores.get(i + 1);
      if (PDScores.get(0) >= scoreThreshold) {
        thisScore = thisScore - 0.001;
      }
      if (thisScore < scoreThreshold && nextScore >= scoreThreshold) {
        oneStart = i + 1;
        dummyPos = i + 1;
        double sum = 0;
        while (PDScores.get(dummyPos) >= scoreThreshold && dummyPos < numberOfPDScores - 1) {
          sum = sum + PDScores.get(dummyPos + 1);
          dummyPos++;
        } /*while*/
        // System.out.println("                      start = " + oneStart + " end = " + dummyPos);
        oneEnd = dummyPos;
        int oneChainLength = oneEnd - oneStart;
        SimpleGFFRecord oneRecord = new SimpleGFFRecord();
        oneRecord.setStart(oneStart + 1);
        oneRecord.setEnd(oneEnd);
        oneRecord.setSeqName(Chr);
        oneRecord.setScore(sum / oneChainLength); // oneRecord.setScore(sum/oneChainLength+1);
        oneRecord.setSource("composure");
        oneRecord.setFeature("chainFromPD");

        int minChainLength = getMinPeakLengths();
        if (oneChainLength > 5) {
          // System.out.println(Chr + "\t" + oneStart + "\t" + oneEnd + "\t" +  oneChainLength);
          gffw.recordLine(oneRecord);
        }
        i = oneEnd - 1;
      } /*if*/
    } /*for*/

    pw.flush();
  } /*wirteChainsIntoAGffFile*/
  /**
   * @param args
   * @throws Exception
   */
  public void main(String[] args) throws Exception {
    List<Map<String, Location>> locs = new ArrayList<Map<String, Location>>();
    for (String fileName : args) {
      locs.add(GFFUtils.gffToLocationMap(new File(fileName)));
    }

    Set<String> seqIds;
    {
      Iterator<Map<String, Location>> i = locs.iterator();
      seqIds = new HashSet<String>(i.next().keySet());
      while (i.hasNext()) {
        seqIds.retainAll(i.next().keySet());
      }
    }

    if (validate && (seqDB != null)) {
      for (Map<String, Location> ls : locs) {
        WriteCoveredSequences.validateGFFSequenceIdentifiersAgainstSequences(ls, seqDB);
      }
    }

    PrintWriter pw = null;
    GFFWriter gffw = null;
    GFFEntrySet gffEntries = null;

    if (outputFormat == Format.GFF) {
      pw = new PrintWriter(new OutputStreamWriter(System.out));
      gffw = new GFFWriter(pw);
    } else {
      gffEntries = new GFFEntrySet();
    }

    for (String id : seqIds) {
      Iterator<Map<String, Location>> i = locs.iterator();
      Location l = i.next().get(id);
      while (i.hasNext()) {
        l = LocationTools.intersection(l, i.next().get(id));
      }

      if (negate) {
        l = LocationTools.subtract(new RangeLocation(1, seqDB.getSequence(id).length()), l);
      }

      SimpleGFFRecord r = new SimpleGFFRecord();
      r.setSeqName(id);
      r.setFeature("block");
      r.setSource("nmintersectseq");
      r.setStrand(StrandedFeature.POSITIVE);

      for (Iterator<?> bi = l.blockIterator(); bi.hasNext(); ) {
        Location bloc = (Location) bi.next();
        r.setStart(bloc.getMin());
        r.setEnd(bloc.getMax());
        r.setComment("");
        r.setGroupAttributes(new HashMap<Object, Object>());
        if (gffw != null) {
          gffw.recordLine(r);
        } else {
          Sequence seq =
              new SimpleSequence(
                  seqDB.getSequence(id).subList(bloc.getMin(), bloc.getMax()),
                  null,
                  String.format("%s_|%d-%d|", id, bloc.getMin(), bloc.getMax()),
                  Annotation.EMPTY_ANNOTATION);
          RichSequence.IOTools.writeFasta(System.out, seq, null);
        }
      }
    }
    if (pw != null) pw.flush();

    if (seqDB != null) {
      System.err.println("Writing output sequences...");
      GFFTools.annotateSequences(seqDB, gffEntries);
    }
  }