.println("WARNING: Consensus skipping null sequence - possible race condition.");
continue;
}
- char[] seq = sequences[row].getSequence();
- if (seq.length > column)
+ if (sequences[row].getLength() > column)
{
- char c = seq[column];
+ char c = sequences[row].getCharAt(column);
residueCounts.add(c);
if (Comparison.isNucleotide(c))
{
int toOffset = alignTo.getStart() - 1;
int sourceGapMappedLength = 0;
boolean inExon = false;
- final char[] thisSeq = alignTo.getSequence();
- final char[] thatAligned = alignFrom.getSequence();
- StringBuilder thisAligned = new StringBuilder(2 * thisSeq.length);
+ final int toLength = alignTo.getLength();
+ final int fromLength = alignFrom.getLength();
+ StringBuilder thisAligned = new StringBuilder(2 * toLength);
/*
* Traverse the 'model' aligned sequence
*/
- for (char sourceChar : thatAligned)
+ for (int i = 0; i < fromLength; i++)
{
+ char sourceChar = alignFrom.getCharAt(i);
if (sourceChar == sourceGap)
{
sourceGapMappedLength += ratio;
*/
int intronLength = 0;
while (basesWritten + toOffset < mappedCodonEnd
- && thisSeqPos < thisSeq.length)
+ && thisSeqPos < toLength)
{
- final char c = thisSeq[thisSeqPos++];
+ final char c = alignTo.getCharAt(thisSeqPos++);
if (c != myGapChar)
{
basesWritten++;
int gapsToAdd = calculateGapsToInsert(preserveMappedGaps,
preserveUnmappedGaps, sourceGapMappedLength, inExon,
trailingCopiedGap.length(), intronLength, startOfCodon);
- for (int i = 0; i < gapsToAdd; i++)
+ for (int k = 0; k < gapsToAdd; k++)
{
thisAligned.append(myGapChar);
}
* At end of model aligned sequence. Copy any remaining target sequence, optionally
* including (intron) gaps.
*/
- while (thisSeqPos < thisSeq.length)
+ while (thisSeqPos < toLength)
{
- final char c = thisSeq[thisSeqPos++];
+ final char c = alignTo.getCharAt(thisSeqPos++);
if (c != myGapChar || preserveUnmappedGaps)
{
thisAligned.append(c);
SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein);
if (peptide != null)
{
- int peptideLength = peptide.getLength();
+ final int peptideLength = peptide.getLength();
Mapping map = mapping.getMappingBetween(cdsSeq, peptide);
if (map != null)
{
{
mapList = mapList.getInverse();
}
- int cdsLength = cdsDss.getLength();
+ final int cdsLength = cdsDss.getLength();
int mappedFromLength = MappingUtils.getLength(mapList
.getFromRanges());
int mappedToLength = MappingUtils
* walk over the aligned peptide sequence and insert mapped
* codons for residues in the aligned cds sequence
*/
- char[] alignedPeptide = peptide.getSequence();
- char[] nucleotides = cdsDss.getSequence();
int copiedBases = 0;
int cdsStart = cdsDss.getStart();
int proteinPos = peptide.getStart() - 1;
int cdsCol = 0;
- for (char residue : alignedPeptide)
+
+ for (int col = 0; col < peptideLength; col++)
{
+ char residue = peptide.getCharAt(col);
+
if (Comparison.isGap(residue))
{
cdsCol += CODON_LENGTH;
{
for (int j = codon[0]; j <= codon[1]; j++)
{
- char mappedBase = nucleotides[j - cdsStart];
+ char mappedBase = cdsDss.getCharAt(j - cdsStart);
alignedCds[cdsCol++] = mappedBase;
copiedBases++;
}
* append stop codon if not mapped from protein,
* closing it up to the end of the mapped sequence
*/
- if (copiedBases == nucleotides.length - CODON_LENGTH)
+ if (copiedBases == cdsLength - CODON_LENGTH)
{
for (int i = alignedCds.length - 1; i >= 0; i--)
{
break;
}
}
- for (int i = nucleotides.length - CODON_LENGTH; i < nucleotides.length; i++)
+ for (int i = cdsLength - CODON_LENGTH; i < cdsLength; i++)
{
- alignedCds[cdsCol++] = nucleotides[i];
+ alignedCds[cdsCol++] = cdsDss.getCharAt(i);
}
}
cdsSeq.setSequence(new String(alignedCds));
List<SequenceI> unmappedProtein)
{
/*
- * Prefill aligned sequences with gaps before inserting aligned protein
- * residues.
+ * prefill peptide sequences with gaps
*/
int alignedWidth = alignedCodons.size();
char[] gaps = new char[alignedWidth];
Arrays.fill(gaps, protein.getGapCharacter());
- String allGaps = String.valueOf(gaps);
+ Map<SequenceI, char[]> peptides = new HashMap<>();
for (SequenceI seq : protein.getSequences())
{
if (!unmappedProtein.contains(seq))
{
- seq.setSequence(allGaps);
+ peptides.put(seq, Arrays.copyOf(gaps, gaps.length));
}
}
+ /*
+ * Traverse the codons left to right (as defined by CodonComparator)
+ * and insert peptides in each column where the sequence is mapped.
+ * This gives a peptide 'alignment' where residues are aligned if their
+ * corresponding codons occupy the same columns in the cdna alignment.
+ */
int column = 0;
for (AlignedCodon codon : alignedCodons.keySet())
{
.get(codon);
for (Entry<SequenceI, AlignedCodon> entry : columnResidues.entrySet())
{
- // place translated codon at its column position in sequence
- entry.getKey().getSequence()[column] = entry.getValue().product
- .charAt(0);
+ char residue = entry.getValue().product.charAt(0);
+ peptides.get(entry.getKey())[column] = residue;
}
column++;
}
+
+ /*
+ * and finally set the constructed sequences
+ */
+ for (Entry<SequenceI, char[]> entry : peptides.entrySet())
+ {
+ entry.getKey().setSequence(new String(entry.getValue()));
+ }
+
return 0;
}
.getInverse());
}
- char[] fromChars = fromSeq.getSequence();
int toStart = seq.getStart();
- char[] toChars = seq.getSequence();
/*
* traverse [start, end, start, end...] ranges in fromSeq
* of the next character of the mapped-to sequence; stop when all
* the characters of the range have been counted
*/
- while (mappedCharPos <= range[1] && fromCol <= fromChars.length
+ while (mappedCharPos <= range[1] && fromCol <= fromSeq.getLength()
&& fromCol >= 0)
{
- if (!Comparison.isGap(fromChars[fromCol - 1]))
+ if (!Comparison.isGap(fromSeq.getCharAt(fromCol - 1)))
{
/*
* mapped from sequence has a character in this column
seqsMap = new HashMap<SequenceI, Character>();
map.put(fromCol, seqsMap);
}
- seqsMap.put(seq, toChars[mappedCharPos - toStart]);
+ seqsMap.put(seq, seq.getCharAt(mappedCharPos - toStart));
mappedCharPos++;
}
fromCol += (forward ? 1 : -1);
public void completeAnnotations(AlignmentAnnotation conservation,
AlignmentAnnotation quality2, int istart, int alWidth)
{
- char[] sequence = getConsSequence().getSequence();
- float minR;
- float minG;
- float minB;
- float maxR;
- float maxG;
- float maxB;
- minR = 0.3f;
- minG = 0.0f;
- minB = 0f;
- maxR = 1.0f - minR;
- maxG = 0.9f - minG;
- maxB = 0f - minB; // scalable range for colouring both Conservation and
- // Quality
+ SequenceI cons = getConsSequence();
+
+ /*
+ * colour scale for Conservation and Quality;
+ */
+ float minR = 0.3f;
+ float minG = 0.0f;
+ float minB = 0f;
+ float maxR = 1.0f - minR;
+ float maxG = 0.9f - minG;
+ float maxB = 0f - minB;
float min = 0f;
float max = 11f;
float qmin = 0f;
float qmax = 0f;
- char c;
-
if (conservation != null && conservation.annotations != null
&& conservation.annotations.length < alWidth)
{
{
float value = 0;
- c = sequence[i];
+ char c = cons.getCharAt(i);
if (Character.isDigit(c))
{
*/
String getTooltip(int column)
{
- char[] sequence = getConsSequence().getSequence();
- char val = column < sequence.length ? sequence[column] : '-';
+ SequenceI cons = getConsSequence();
+ char val = column < cons.getLength() ? cons.getCharAt(column) : '-';
boolean hasConservation = val != '-' && val != '0';
int consp = column - start;
String tip = (hasConservation && consp > -1 && consp < consSymbs.length) ? consSymbs[consp]
{
return false;
}
- char[] c1 = seq1.getSequence();
- char[] c2 = seq2.getSequence();
- if (c1.length != c2.length)
+
+ if (seq1.getLength() != seq2.getLength())
{
return false;
}
- for (int i = 0; i < c1.length; i++)
+ int length = seq1.getLength();
+ for (int i = 0; i < length; i++)
{
- int diff = c1[i] - c2[i];
+ int diff = seq1.getCharAt(i) - seq2.getCharAt(i);
/*
* same char or differ in case only ('a'-'A' == 32)
*/
* Read off the mapped nucleotides (converting to position base 0)
*/
codonPos = MappingUtils.flattenRanges(codonPos);
- char[] dna = dnaSeq.getSequence();
int start = dnaSeq.getStart();
- result.add(new char[] { dna[codonPos[0] - start],
- dna[codonPos[1] - start], dna[codonPos[2] - start] });
+ char c1 = dnaSeq.getCharAt(codonPos[0] - start);
+ char c2 = dnaSeq.getCharAt(codonPos[1] - start);
+ char c3 = dnaSeq.getCharAt(codonPos[2] - start);
+ result.add(new char[] { c1, c2, c3 });
}
}
return result.isEmpty() ? null : result;
{
// TODO JAL-1270 needs test coverage
// currently tested for use in jalview.gui.SequenceFetcher
- boolean samegap = toappend.getGapCharacter() == getGapCharacter();
char oldc = toappend.getGapCharacter();
+ boolean samegap = oldc == getGapCharacter();
boolean hashidden = toappend.getHiddenSequences() != null
&& toappend.getHiddenSequences().hiddenSequences != null;
// get all sequences including any hidden ones
{
if (!samegap)
{
- char[] oldseq = addedsq.getSequence();
- for (int c = 0; c < oldseq.length; c++)
- {
- if (oldseq[c] == oldc)
- {
- oldseq[c] = gapCharacter;
- }
- }
+ addedsq.replace(oldc, gapCharacter);
}
toappendsq.add(addedsq);
}
int nores = (isNa) ? ResidueProperties.maxNucleotideIndex
: ResidueProperties.maxProteinIndex;
- dbinary = new double[getSequence().length * nores];
+ dbinary = new double[getLength() * nores];
return nores;
}
{
int nores = initMatrixGetNoRes();
final int[] sindex = getSymbolmatrix();
- for (int i = 0; i < getSequence().length; i++)
+ for (int i = 0; i < getLength(); i++)
{
int aanum = nores - 1;
{
int nores = initMatrixGetNoRes();
- for (int i = 0, iSize = getSequence().length; i < iSize; i++)
+ for (int i = 0, iSize = getLength(); i < iSize; i++)
{
int aanum = nores - 1;
/*
* The characters of the aligned sequence e.g. "-cGT-ACgTG-"
*/
- private final char[] alignedSeq;
+ private final SequenceI alignedSeq;
/*
* the sequence start residue
*/
public AlignedCodonIterator(SequenceI seq, char gapChar)
{
- this.alignedSeq = seq.getSequence();
+ this.alignedSeq = seq;
this.start = seq.getStart();
this.gap = gapChar;
fromRanges = map.getFromRanges().iterator();
if (toPosition <= currentToRange[1])
{
SequenceI seq = Mapping.this.to;
- char pep = seq.getSequence()[toPosition - seq.getStart()];
+ char pep = seq.getCharAt(toPosition - seq.getStart());
toPosition++;
return String.valueOf(pep);
}
* allow for offset e.g. treat pos 8 as 2 if sequence starts at 7
*/
int truePos = sequencePos - (start - 1);
- while (alignedBases < truePos && alignedColumn < alignedSeq.length)
+ int length = alignedSeq.getLength();
+ while (alignedBases < truePos && alignedColumn < length)
{
- char c = alignedSeq[alignedColumn++];
+ char c = alignedSeq.getCharAt(alignedColumn++);
if (c != gap && !Comparison.isGap(c))
{
alignedBases++;
protected void initSeqFrom(SequenceI seq,
AlignmentAnnotation[] alAnnotation)
{
- char[] oseq = seq.getSequence();
- initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
- seq.getStart(), seq.getEnd());
+ char[] oseq = seq.getSequence(); // returns a copy of the array
+ initSeqAndName(seq.getName(), oseq, seq.getStart(), seq.getEnd());
description = seq.getDescription();
if (seq != datasetSequence)
@Override
public char[] getSequence()
{
- return sequence;
+ // return sequence;
+ return sequence == null ? null : Arrays.copyOf(sequence,
+ sequence.length);
}
/*
private boolean _isNa;
- private long _seqhash = 0;
+ private int _seqhash = 0;
/**
* Answers false if the sequence is more than 85% nucleotide (ACGTU), else
{
changeCount++;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int replace(char c1, char c2)
+ {
+ if (c1 == c2)
+ {
+ return 0;
+ }
+ int count = 0;
+ synchronized (sequence)
+ {
+ for (int c = 0; c < sequence.length; c++)
+ {
+ if (sequence[c] == c1)
+ {
+ sequence[c] = c2;
+ count++;
+ }
+ }
+ }
+ if (count > 0)
+ {
+ sequenceChanged();
+ }
+
+ return count;
+ }
}
public String getSequenceAsString(int start, int end);
/**
- * Get the sequence as a character array
+ * Answers a copy of the sequence as a character array
*
- * @return seqeunce and any gaps
+ * @return
*/
public char[] getSequence();
* returns true.
*/
BitSet getInsertionsAsBits();
+
+ /**
+ * Replaces every occurrence of c1 in the sequence with c2 and returns the
+ * number of characters changed
+ *
+ * @param c1
+ * @param c2
+ */
+ public int replace(char c1, char c2);
}
System.err
.println("Implementation Notice: EMBLCDS records not properly supported yet - Making up the CDNA region of this sequence... may be incorrect ("
+ sourceDb + ":" + getAccession() + ")");
- if (translationLength * 3 == (1 - codonStart + dna.getSequence().length))
+ int dnaLength = dna.getLength();
+ if (translationLength * 3 == (1 - codonStart + dnaLength))
{
System.err
.println("Not allowing for additional stop codon at end of cDNA fragment... !");
dnaToProteinMapping = new Mapping(product, exons, new int[] { 1,
translationLength }, 3, 1);
}
- if ((translationLength + 1) * 3 == (1 - codonStart + dna
- .getSequence().length))
+ if ((translationLength + 1) * 3 == (1 - codonStart + dnaLength))
{
System.err
.println("Allowing for additional stop codon at end of cDNA fragment... will probably cause an error in VAMSAs!");
SequenceI sq, char[] secstr, char[] secstrcode, String chainId,
int firstResNum)
{
- char[] seq = sq.getSequence();
+ int length = sq.getLength();
boolean ssFound = false;
- Annotation asecstr[] = new Annotation[seq.length + firstResNum - 1];
- for (int p = 0; p < seq.length; p++)
+ Annotation asecstr[] = new Annotation[length + firstResNum - 1];
+ for (int p = 0; p < length; p++)
{
if (secstr[p] >= 'A' && secstr[p] <= 'z')
{
ShiftList offset = new ShiftList();
int ofstart = -1;
int sleng = seq.getLength();
- char[] seqChars = seq.getSequence();
for (int i = 0; i < sleng; i++)
{
- if (Comparison.isGap(seqChars[i]))
+ if (Comparison.isGap(seq.getCharAt(i)))
{
if (ofstart == -1)
{
out.append(newline);
- if (s[i].getSequence().length > max)
- {
- max = s[i].getSequence().length;
- }
+ max = Math.max(max, s[i].getLength());
i++;
}
{
String tmp = printId(s[i], jvsuffix);
- if (s[i].getSequence().length > max)
- {
- max = s[i].getSequence().length;
- }
+ max = Math.max(max, s[i].getLength());
if (tmp.length() > maxid)
{
int start = i * len;
int end = start + len;
- if ((end < s[j].getSequence().length)
- && (start < s[j].getSequence().length))
+ int length = s[j].getLength();
+ if ((end < length) && (start < length))
{
out.append(s[j].getSequenceAsString(start, end));
}
else
{
- if (start < s[j].getSequence().length)
+ if (start < length)
{
out.append(s[j].getSequenceAsString().substring(start));
}
// in the future we could search for the query
// sequence in the alignment before calling this function.
SequenceI seqRef = al.getSequenceAt(firstSeq);
- int width = preds[0].getSequence().length;
+ int width = preds[0].getLength();
int[] gapmap = al.getSequenceAt(firstSeq).gapMap();
if ((delMap != null && delMap.length > width)
|| (delMap == null && gapmap.length != width))
}
long maxNB = 0;
- out.append(" MSF: " + s[0].getSequence().length + " Type: "
+ out.append(" MSF: " + s[0].getLength() + " Type: "
+ (is_NA ? "N" : "P") + " Check: " + (bigChecksum % 10000)
+ " ..");
out.append(newline);
nameBlock[i] = new String(" Name: " + printId(s[i], jvSuffix) + " ");
- idBlock[i] = new String("Len: "
- + maxLenpad.form(s[i].getSequence().length) + " Check: "
- + maxChkpad.form(checksums[i]) + " Weight: 1.00" + newline);
+ idBlock[i] = new String("Len: " + maxLenpad.form(s[i].getLength())
+ + " Check: " + maxChkpad.form(checksums[i])
+ + " Weight: 1.00" + newline);
if (s[i].getName().length() > maxid)
{
int start = (i * 50) + (k * 10);
int end = start + 10;
- if ((end < s[j].getSequence().length)
- && (start < s[j].getSequence().length))
+ int length = s[j].getLength();
+ if ((end < length)
+ && (start < length))
{
out.append(s[j].getSequence(start, end));
}
else
{
- if (start < s[j].getSequence().length)
+ if (start < length)
{
out.append(s[j].getSequenceAsString().substring(start));
out.append(newline);
{
String tmp = printId(s[i], jvsuffix);
- if (s[i].getSequence().length > max)
- {
- max = s[i].getSequence().length;
- }
+ max = Math.max(max, s[i].getLength());
if (tmp.length() > maxid)
{
sb.append(" ");
// if there are no sequences, then define the number of characters as 0
sb.append(
- (sqs.length > 0) ? Integer.toString(sqs[0].getSequence().length)
+(sqs.length > 0) ? Integer.toString(sqs[0].getLength())
: "0")
.append(newline);
// sequential has the entire sequence following the name
if (sequential)
{
- sb.append(s.getSequence());
+ sb.append(s.getSequenceAsString());
}
else
{
// Jalview ensures all sequences are of same length so no need
// to keep track of min/max length
- sequenceLength = s.getSequence().length;
+ sequenceLength = s.getLength();
// interleaved breaks the sequence into chunks for
// interleavedColumns characters
sb.append(s.getSequence(0,
i++;
}
- out.append(" MSF: " + s[0].getSequence().length
+ out.append(" MSF: " + s[0].getLength()
+ " Type: P Check: " + bigChecksum % 10000 + " ..");
out.append(newline);
out.append(newline);
int start = (i * 50) + (k * 10);
int end = start + 10;
- if ((end < s[j].getSequence().length)
- && (start < s[j].getSequence().length))
+ int length = s[j].getLength();
+ if ((end < length) && (start < length))
{
out.append(s[j].getSequence(start, end));
}
else
{
- if (start < s[j].getSequence().length)
+ if (start < length)
{
out.append(s[j].getSequenceAsString().substring(start));
out.append(newline);
while ((in < s.length) && (s[in] != null))
{
String tmp = printId(s[in], jvSuffix);
- if (s[in].getSequence().length > max)
- {
- max = s[in].getSequence().length;
- }
+ max = Math.max(max, s[in].getLength());
if (tmp.length() > maxid)
{
public static boolean isRNA(SequenceI seq)
{
- for (char c : seq.getSequence())
+ int length = seq.getLength();
+ for (int i = 0; i < length; i++)
{
+ char c = seq.getCharAt(i);
if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
{
return false;
for (SequenceI sq : seqs)
{
- char[] seq = sq.getSequence();
-
- int end_j = seq.length - 1;
+ int end_j = sq.getLength() - 1;
+ int length = sq.getLength();
for (int i = 0; i <= end_j; i++)
{
- if ((seq.length - 1) < i)
+ if (length - 1 < i)
{
res = 23;
}
else
{
- res = ResidueProperties.aaIndex[seq[i]];
+ res = ResidueProperties.aaIndex[sq.getCharAt(i)];
}
cons2[i][res]++;
}
{
return false;
}
- char[][] letters = new char[seqs.length][];
- for (int i = 0; i < seqs.length; i++)
- {
- if (seqs[i] != null)
- {
- char[] sequence = seqs[i].getSequence();
- if (sequence != null)
- {
- letters[i] = sequence;
- }
- }
- }
-
- return areNucleotide(letters);
- }
- /**
- * Answers true if more than 85% of the sequence residues (ignoring gaps) are
- * A, G, C, T or U, else false. This is just a heuristic guess and may give a
- * wrong answer (as AGCT are also amino acid codes).
- *
- * @param letters
- * @return
- */
- static final boolean areNucleotide(char[][] letters)
- {
int ntCount = 0;
int aaCount = 0;
- for (char[] seq : letters)
+ for (SequenceI seq : seqs)
{
if (seq == null)
{
}
// TODO could possibly make an informed guess just from the first sequence
// to save a lengthy calculation
- for (char c : seq)
+ int len = seq.getLength();
+ for (int i = 0; i < len; i++)
{
+ char c = seq.getCharAt(i);
if (isNucleotide(c))
{
ntCount++;
{
idvector.append(sep);
}
- idvector.append(seq.getSequence());
+ idvector.append(seq.getSequenceAsString());
}
return new StringBody(idvector.toString());
}
AlignmentI alignment = new Alignment(new SequenceI[] { seq });
alignment.setDataset(alignment);
}
+
+ @Test(groups = "Functional")
+ public void testAppend()
+ {
+ SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
+ AlignmentI alignment = new Alignment(new SequenceI[] { seq });
+ alignment.setGapCharacter('-');
+ SequenceI seq2 = new Sequence("seq1", "KP..L.FQII.");
+ AlignmentI alignment2 = new Alignment(new SequenceI[] { seq2 });
+ alignment2.setGapCharacter('.');
+
+ alignment.append(alignment2);
+
+ assertEquals('-', alignment.getGapCharacter());
+ assertSame(seq, alignment.getSequenceAt(0));
+ assertEquals("KP--L-FQII-", alignment.getSequenceAt(1)
+ .getSequenceAsString());
+
+ // todo test coverage for annotations, mappings, groups,
+ // hidden sequences, properties
+ }
}
/*
* TODO: can we add assertions to the sysouts that follow?
*/
- System.out.println("Original sequence align:\n" + sub_gapped_s
+ System.out.println("\nOriginal sequence align:\n" + sub_gapped_s
+ "\nReconstructed window from 8 to 48\n" + "XXXXXXXX"
+ sub_se_gp.getSequenceString('-') + "..." + "\nCigar String:"
+ sub_se_gp.getCigarstring() + "\n");
SequenceI gen_sgapped_s = gen_sgapped.getSeq('-');
// assertEquals("Couldn't reconstruct sequence", s_gapped.getSequence(),
// gen_sgapped_s);
- if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence()))
+ if (!gen_sgapped_s.getSequenceAsString().equals(
+ s_gapped.getSequenceAsString()))
{
// TODO: investigate errors reported here, to allow full conversion to
// passing JUnit assertion form
// change sequence, should trigger an update of cached result
sq.setSequence("ASDFASDFADSF");
assertTrue(sq.isProtein());
- /*
- * in situ change of sequence doesn't change hashcode :-O
- * (sequence should not expose internal implementation)
- */
- for (int i = 0; i < sq.getSequence().length; i++)
- {
- sq.getSequence()[i] = "acgtu".charAt(i % 5);
- }
- assertTrue(sq.isProtein()); // but it isn't
}
@Test(groups = { "Functional" })
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 13, 10, ++token), cursor);
}
+
+ @Test(groups = { "Functional" })
+ public void testGetSequence()
+ {
+ String seqstring = "-A--BCD-EF--";
+ Sequence sq = new Sequence("test/8-13", seqstring);
+ sq.createDatasetSequence();
+ assertTrue(Arrays.equals(sq.getSequence(), seqstring.toCharArray()));
+ assertTrue(Arrays.equals(sq.getDatasetSequence().getSequence(),
+ "ABCDEF".toCharArray()));
+
+ // verify a copy of the sequence array is returned
+ char[] theSeq = (char[]) PA.getValue(sq, "sequence");
+ assertNotSame(theSeq, sq.getSequence());
+ theSeq = (char[]) PA.getValue(sq.getDatasetSequence(), "sequence");
+ assertNotSame(theSeq, sq.getDatasetSequence().getSequence());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testReplace()
+ {
+ String seqstring = "-A--BCD-EF--";
+ SequenceI sq = new Sequence("test/8-13", seqstring);
+ assertEquals(0, PA.getValue(sq, "changeCount"));
+
+ assertEquals(0, sq.replace('A', 'A')); // same char
+ assertEquals(seqstring, sq.getSequenceAsString());
+ assertEquals(0, PA.getValue(sq, "changeCount"));
+
+ assertEquals(0, sq.replace('X', 'Y')); // not there
+ assertEquals(seqstring, sq.getSequenceAsString());
+ assertEquals(0, PA.getValue(sq, "changeCount"));
+
+ assertEquals(1, sq.replace('A', 'K'));
+ assertEquals("-K--BCD-EF--", sq.getSequenceAsString());
+ assertEquals(1, PA.getValue(sq, "changeCount"));
+
+ assertEquals(6, sq.replace('-', '.'));
+ assertEquals(".K..BCD.EF..", sq.getSequenceAsString());
+ assertEquals(2, PA.getValue(sq, "changeCount"));
+ }
}
{
{
SequenceI struseq = null;
- String sq_ = new String(sq.getSequence()).toLowerCase();
+ String sq_ = sq.getSequenceAsString().toLowerCase();
for (SequenceI _struseq : pdbf.getSeqsAsArray())
{
- final String lowerCase = new String(_struseq.getSequence())
+ final String lowerCase = _struseq.getSequenceAsString()
.toLowerCase();
if (lowerCase.equals(sq_))
{