Exemplo n.º 1
0
  public static void main(String[] args) {

    try {
      ArrayList<GeneSequence> sequences = new ArrayList<GeneSequence>();
      ChromosomeSequence seq1 =
          new ChromosomeSequence(
              "ATATATATATATATATATATATATATATATATACGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCATATATATATATATATATATATACGCGCGCGCGCGCGCGCATATATATATATATATATATATATATATATATACGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCATATATATATATATATATATATACGCGCGCGCGCGCGCGC");
      GeneSequence gene1 = seq1.addGene(new AccessionID("gene1"), 1, 20, Strand.POSITIVE);

      gene1.addExon(new AccessionID("t1_1_10"), 1, 10);
      gene1.addExon(new AccessionID("t1_12_15"), 12, 15);
      GeneSequence gene2 = seq1.addGene(new AccessionID("gene2"), 1, 20, Strand.NEGATIVE);

      gene2.addExon(new AccessionID("t2_1_10"), 1, 10);
      gene2.addExon(new AccessionID("t2_12_15"), 12, 15);
      sequences.add(gene1);
      sequences.add(gene2);

      FastaGeneWriter fastaWriter =
          new FastaGeneWriter(
              System.out,
              sequences,
              new GenericFastaHeaderFormat<GeneSequence, NucleotideCompound>(),
              true);
      fastaWriter.process();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /** @throws Exception */
  public void process() throws Exception {
    byte[] lineSep = System.getProperty("line.separator").getBytes();

    for (GeneSequence sequence : sequences) {
      String header = headerFormat.getHeader(sequence);
      os.write('>');
      os.write(header.getBytes());
      os.write(lineSep);

      int compoundCount = 0;
      String seq = "";
      // GeneSequence currently has a strand attribute to indicate direction

      seq = sequence.getSequence5PrimeTo3Prime().getSequenceAsString();
      if (showExonUppercase) {
        StringBuilder sb = new StringBuilder(seq.toLowerCase());
        int geneBioBegin = sequence.getBioBegin();
        int geneBioEnd = sequence.getBioEnd();
        for (ExonSequence exonSequence : sequence.getExonSequences()) {
          int featureBioBegin = 0;
          int featureBioEnd = 0;
          if (sequence.getStrand() != Strand.NEGATIVE) {
            featureBioBegin = exonSequence.getBioBegin() - geneBioBegin;
            featureBioEnd = exonSequence.getBioEnd() - geneBioBegin;
          } else {
            featureBioBegin = geneBioEnd - exonSequence.getBioEnd();
            featureBioEnd = geneBioEnd - exonSequence.getBioBegin();
          }
          if (featureBioBegin < 0
              || featureBioEnd < 0
              || featureBioEnd > sb.length()
              || featureBioBegin > sb.length()) {
            System.out.println(
                "Bad Feature "
                    + sequence.getAccession().toString()
                    + " "
                    + sequence.getStrand()
                    + " "
                    + geneBioBegin
                    + " "
                    + geneBioEnd
                    + " "
                    + exonSequence.getBioBegin()
                    + " "
                    + exonSequence.getBioEnd());
          } else {
            for (int i = featureBioBegin; i <= featureBioEnd; i++) {
              char ch = sb.charAt(i);
              // probably not the fastest but the safest way if language is not standard ASCII
              String temp = ch + "";
              ch = temp.toUpperCase().charAt(0);
              sb.setCharAt(i, ch);
            }
          }
        }
        seq = sb.toString();
      }

      for (int i = 0; i < seq.length(); i++) {
        os.write(seq.charAt(i));
        compoundCount++;
        if (compoundCount == lineLength) {
          os.write(lineSep);
          compoundCount = 0;
        }
      }

      // If we had sequence which was a reciprocal of line length
      // then don't write the line terminator as this has already written
      // it
      if ((sequence.getLength() % getLineLength()) != 0) {
        os.write(lineSep);
      }
    }
  }