Esempio n. 1
0
  String codons() {
    char seq[] = chromoSequence.toCharArray();
    char seqNew[] = chromoNewSequence.toCharArray();

    codonsOld = "";
    codonsNew = "";
    int codonIdx = 0;
    int i = 0;
    int step = transcript.isStrandPlus() ? 1 : -1;
    char codonOld[] = new char[3];
    char codonNew[] = new char[3];
    for (Exon ex : transcript.sortedStrand()) {
      int start = ex.isStrandPlus() ? ex.getStart() : ex.getEnd();
      for (i = start; ex.intersects(i); i += step, codonIdx = (codonIdx + 1) % 3) {
        codonOld[codonIdx] = seq[i];
        codonNew[codonIdx] = seqNew[i];
        if (codonIdx == 2) addIfDiff(codonOld, codonNew);
      }
    }

    for (; codonIdx != 0; i += step, codonIdx = (codonIdx + 1) % 3) {
      codonOld[codonIdx] = 'N';
      codonNew[codonIdx] = 'N';
      if (codonIdx == 2) addIfDiff(codonOld, codonNew);
    }

    return codonsOld + "/" + codonsNew;
  }
Esempio n. 2
0
  /**
   * Find the last position where a nonsense mediated decay is supposed to occurr This is 50 bases
   * (MND_BASES_BEFORE_LAST_JUNCTION bases) before the last exon-exon junction.
   *
   * @param tr
   * @return
   */
  public int lastNmdPos(Transcript tr) {
    // ---
    // Get last exon
    // ---
    int cdsEnd = tr.getCdsEnd();
    int cdsStart = tr.getCdsStart();
    Marker cds =
        new Marker(
            tr.getChromosome(),
            Math.min(cdsStart, cdsEnd),
            Math.max(cdsStart, cdsEnd),
            tr.getStrand(),
            ""); // Create a cds marker
    Exon lastExon = null;
    int countCodingExons = 0;
    for (Exon exon : tr.sortedStrand()) {
      if (exon.intersects(cdsEnd)) lastExon = exon;
      if (cds.intersects(exon)) countCodingExons++;
    }

    // Only one coding exon? => No NMD
    // Note: I'm assuming that we should have a splice event in a coding part of the transcript for
    // NMD to happen.
    if (countCodingExons <= 1) return -1;

    // Sanity check
    if (lastExon == null)
      throw new RuntimeException(
          "Cannot find last coding exon for transcript '"
              + tr.getId()
              + "' (cdsEnd: "
              + cdsEnd
              + ")\n\t"
              + tr);

    // ---
    // Find that position of MND_BASES_BEFORE_LAST_JUNCTION before the last exon-exon junction
    // ---
    int lastExonJunction = tr.isStrandPlus() ? lastExon.getStart() : lastExon.getEnd();
    int chrPos[] = tr.baseNumberCds2Pos();
    int lastNmdPos = -1;
    for (int cdsi = chrPos.length - 1; cdsi >= 0; cdsi--) {
      if (chrPos[cdsi] == lastExonJunction) {
        if (cdsi > MND_BASES_BEFORE_LAST_JUNCTION)
          lastNmdPos = chrPos[cdsi - MND_BASES_BEFORE_LAST_JUNCTION - 1];
        else return tr.isStrandPlus() ? 0 : Integer.MAX_VALUE; // Out of CDS range
        return lastNmdPos;
      }
    }

    throw new RuntimeException(
        "Cannot find last exon junction position for transcript '" + tr.getId() + "'\n\t" + tr);
    // return -1;
  }
Esempio n. 3
0
  @Test
  public void test_01() {
    Gpr.debug("Test");

    // Test N times
    //	- Create a random gene transcript, exons
    //	- Change each base in the exon
    //	- Calculate effect
    for (int i = 0; i < N; i++) {
      initSnpEffPredictor();

      if (debug)
        System.out.println(
            "MNP Test iteration: " + i + "\nChromo:\t" + chromoSequence + "\n" + transcript);
      else if (verbose)
        System.out.println(
            "MNP Test iteration: "
                + i
                + "\t"
                + (transcript.isStrandPlus() ? "+" : "-")
                + "\t"
                + transcript.cds());
      else Gpr.showMark(i + 1, 1);

      if (debug) {
        for (Exon exon : transcript.sortedStrand())
          System.out.println(
              "\tExon: "
                  + exon
                  + "\tSEQ:\t"
                  + (exon.isStrandMinus()
                          ? GprSeq.reverseWc(exon.getSequence())
                          : exon.getSequence())
                      .toUpperCase());
      }

      // For each base in this exon...
      for (int pos = 0; pos < chromoSequence.length() - 2; pos++) {
        // MNP length
        int mnpLen = rand.nextInt(MAX_MNP_LEN) + 2;
        int maxMnpLen = chromoSequence.length() - pos;
        mnpLen = Math.min(mnpLen, maxMnpLen);

        String ref = chromoSequence.substring(pos, pos + mnpLen);
        String mnp = createMnp(pos, mnpLen);

        analyze(i, pos, ref, mnp);
      }
    }

    System.err.println("");
  }
Esempio n. 4
0
  /** Set marker. Add some warnings if the marker relates to incomplete transcripts */
  public void setMarker(Marker marker) {
    this.marker = marker;

    Transcript transcript = getTranscript();
    if (transcript != null) {
      // Transcript level errors or warnings
      addErrorWarningInfo(transcript.sanityCheck(variant));

      // Exon level errors or warnings
      Exon exon = getExon();
      if (exon != null) addErrorWarningInfo(exon.sanityCheck(variant));
    }
  }
Esempio n. 5
0
  /** Get the simplest string describing the effect (this is mostly used for testcases) */
  public String toStringSimple(boolean shortFormat) {
    String transcriptId = "";
    Transcript tr = getTranscript();
    if (tr != null) transcriptId = tr.getId();

    String exonId = "";
    Exon exon = getExon();
    if (exon != null) exonId = exon.getId();

    String eff = effect(shortFormat, true, true, false);
    if (!eff.isEmpty()) return eff;
    if (!exonId.isEmpty()) return exonId;
    if (!transcriptId.isEmpty()) return transcriptId;

    return "NO EFFECT";
  }
Esempio n. 6
0
  public String toString(boolean useSeqOntology, boolean useHgvs) {
    // Get data to show
    String geneId = "", geneName = "", bioType = "", transcriptId = "", exonId = "", customId = "";
    int exonRank = -1;

    if (marker != null) {
      // Gene Id, name and biotype
      Gene gene = getGene();
      Transcript tr = getTranscript();

      // CDS size info
      if (gene != null) {
        geneId = gene.getId();
        geneName = gene.getGeneName();
        bioType = getBiotype();
      }

      // Update trId
      if (tr != null) transcriptId = tr.getId();

      // Exon rank information
      Exon exon = getExon();
      if (exon != null) {
        exonId = exon.getId();
        exonRank = exon.getRank();
      }

      // Regulation
      if (isRegulation()) bioType = ((Regulation) marker).getCellType();
    }

    // Add seqChage's ID
    if (!variant.getId().isEmpty()) customId += variant.getId();

    // Add custom markers
    if ((marker != null) && (marker instanceof Custom))
      customId += (customId.isEmpty() ? "" : ";") + marker.getId();

    // CDS length
    int cdsSize = getCdsLength();

    String errWarn = error + (error.isEmpty() ? "" : "|") + warning;

    String aaChange = "";
    if (useHgvs) aaChange = getHgvs();
    else aaChange = ((aaRef.length() + aaAlt.length()) > 0 ? aaRef + "/" + aaAlt : "");

    return errWarn //
        + "\t"
        + geneId //
        + "\t"
        + geneName //
        + "\t"
        + bioType //
        + "\t"
        + transcriptId //
        + "\t"
        + exonId //
        + "\t"
        + (exonRank >= 0 ? exonRank : "") //
        + "\t"
        + effect(false, false, false, useSeqOntology) //
        + "\t"
        + aaChange //
        + "\t"
        + ((codonsRef.length() + codonsAlt.length()) > 0 ? codonsRef + "/" + codonsAlt : "") //
        + "\t"
        + (codonNum >= 0 ? (codonNum + 1) : "") //
        + "\t"
        + (codonDegeneracy >= 0 ? codonDegeneracy + "" : "") //
        + "\t"
        + (cdsSize >= 0 ? cdsSize : "") //
        + "\t"
        + (codonsAroundOld.length() > 0 ? codonsAroundOld + " / " + codonsAroundNew : "") //
        + "\t"
        + (aasAroundOld.length() > 0 ? aasAroundOld + " / " + aasAroundNew : "") //
        + "\t"
        + customId //
    ;
  }
Esempio n. 7
0
  /**
   * Name of the regions hit by a marker
   *
   * @param marker
   * @param showGeneDetails
   * @param compareTemplate
   * @param id : Only use genes or transcripts matching this ID
   * @return
   */
  public Set<String> regions(
      Marker marker, boolean showGeneDetails, boolean compareTemplate, String id) {
    if (Config.get().isErrorOnMissingChromo() && isChromosomeMissing(marker))
      throw new RuntimeEOFException("Chromosome missing for marker: " + marker);

    boolean hitChromo = false;
    HashSet<String> hits = new HashSet<String>();

    Markers intersects = query(marker);
    if (intersects.size() > 0) {
      for (Marker markerInt : intersects) {

        if (markerInt instanceof Chromosome) {
          hitChromo = true; // OK (we have to hit a chromosome, otherwise it's an error
          hits.add(markerInt.getClass().getSimpleName()); // Add marker name to the list
        } else if (markerInt instanceof Gene) {
          // Analyze Genes
          Gene gene = (Gene) markerInt;
          regionsAddHit(hits, gene, marker, showGeneDetails, compareTemplate);

          // For all transcripts...
          for (Transcript tr : gene) {
            if ((id == null)
                || gene.getId().equals(id)
                || tr.getId().equals(id)) { // Mathes ID? (...or no ID to match)

              // Does it intersect this transcript?
              if (tr.intersects(marker)) {
                regionsAddHit(hits, tr, marker, showGeneDetails, compareTemplate);

                // Does it intersect a UTR?
                for (Utr utr : tr.getUtrs())
                  if (utr.intersects(marker))
                    regionsAddHit(hits, utr, marker, showGeneDetails, compareTemplate);

                // Does it intersect an exon?
                for (Exon ex : tr)
                  if (ex.intersects(marker))
                    regionsAddHit(hits, ex, marker, showGeneDetails, compareTemplate);

                // Does it intersect an intron?
                for (Intron intron : tr.introns())
                  if (intron.intersects(marker))
                    regionsAddHit(hits, intron, marker, showGeneDetails, compareTemplate);
              }
            }
          }
        } else {
          // No ID to match?
          if (id == null) regionsAddHit(hits, markerInt, marker, showGeneDetails, compareTemplate);
          else {
            // Is ID from transcript?
            Transcript tr = (Transcript) markerInt.findParent(Transcript.class);
            if ((tr != null) && (tr.getId().equals(id))) {
              regionsAddHit(
                  hits,
                  markerInt,
                  marker,
                  showGeneDetails,
                  compareTemplate); // Transcript ID matches => count
            } else {
              // Is ID from gene?
              Gene gene = (Gene) markerInt.findParent(Gene.class);
              if ((gene != null) && (gene.getId().equals(id)))
                regionsAddHit(
                    hits,
                    markerInt,
                    marker,
                    showGeneDetails,
                    compareTemplate); // Gene ID matches => count
            }
          }
        }
      }
    }

    if (!hitChromo) throw new RuntimeException("ERROR: Out of chromosome range. " + marker);
    return hits;
  }