/** * Set the region of sequence space to draw * * @param oneMin * @param oneMax * @param twoMin * @param twoMax */ public void setSequenceBounds(int oneMin, int oneMax, int twoMin, int twoMax) { sequenceOneMin = Math.max(oneMin, 0); sequenceTwoMin = Math.max(twoMin, 0); sequenceOneMax = Math.min(oneMax, sequenceOne.length()); sequenceTwoMax = Math.min(twoMax, sequenceTwo.length()); redrawImage = true; }
/** * Recompute the substring buffers, this needs to happen anytime the sequences are changed or the * block width changes...and results in a tiny speedup */ private void recalcSubstrs() { substrs1.clear(); substrs2.clear(); for (int i = 0; i < Math.min(sequenceOne.length(), sequenceTwo.length()); i++) { substrs1.add( sequenceOne.toString().substring(i, Math.min(i + blockWidth, sequenceOne.length()))); substrs2.add( sequenceTwo.toString().substring(i, Math.min(i + blockWidth, sequenceTwo.length()))); } }
public void setSequences(Sequence seq1, Sequence seq2) { sequenceOne = seq1; sequenceTwo = seq2; int minLength = Math.min(seq1.length(), seq2.length()); sequenceOneMin = 0; sequenceTwoMin = 0; sequenceOneMax = minLength; sequenceTwoMax = minLength; recalcSubstrs(); redrawImage = true; }
/** * Returns the amino acid that corresponds to the codon beginning at site i in this sequence * * @param sequence * @param site * @return */ public AminoAcid translate(Sequence sequence, int site) { if (site >= (sequence.length() - 2)) { throw new IllegalArgumentException( "Cannot translate codon site #" + site + " because sequence is only " + sequence.length() + " sites long."); } else { AminoAcid aa = translate(sequence.toString().substring(site, site + 3)); if (aa == null) { System.out.println( "Cannot translate codon :" + sequence.toString().substring(site, site + 3)); } return aa; } }