X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=bad33d1ae79c327d48a1d9451e6b3a47d28e20cb;hb=3e88c926f9e1fc649f9c0932b57eb088052473ec;hp=8c3e538bd6d1601b5e04586eb50675983ff0f9cf;hpb=3da878124135ff033f42d19d8733891b09e953cd;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 8c3e538..bad33d1 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -47,23 +47,26 @@ import fr.orsay.lri.varna.models.rna.RNA; public class Sequence extends ASequence implements SequenceI { - /** - * A subclass that gives us access to modCount, which tracks - * whether there have been any changes. We use this to update - * @author hansonr - * - * @param - */ + /** + * A subclass that gives us access to modCount, which tracks whether there + * have been any changes. We use this to update + * + * @author hansonr + * + * @param + */ @SuppressWarnings("serial") - public class DBModList extends ArrayList { + public class DBModList extends ArrayList + { + + protected int getModCount() + { + return modCount; + } - protected int getModCount() { - return modCount; - } - } -SequenceI datasetSequence; + SequenceI datasetSequence; private String name; @@ -89,7 +92,7 @@ SequenceI datasetSequence; private int refModCount = 0; private RNA rna; - + /** * This annotation is displayed below the alignment but the positions are tied * to the residues of this sequence @@ -301,7 +304,7 @@ SequenceI datasetSequence; { setDatasetSequence(seq.getDatasetSequence()); } - + /* * only copy DBRefs and seqfeatures if we really are a dataset sequence */ @@ -376,8 +379,8 @@ SequenceI datasetSequence; { if (sf.getType() == null) { - System.err.println("SequenceFeature type may not be null: " - + sf.toString()); + System.err.println( + "SequenceFeature type may not be null: " + sf.toString()); return false; } @@ -389,6 +392,10 @@ SequenceI datasetSequence; return sequenceFeatureStore.add(sf); } + /** + * @param sf + * A known feature of this featureStore + */ @Override public void deleteFeature(SequenceFeature sf) { @@ -596,8 +603,8 @@ SequenceI datasetSequence; public char[] getSequence() { // return sequence; - return sequence == null ? null : Arrays.copyOf(sequence, - sequence.length); + return sequence == null ? null + : Arrays.copyOf(sequence, sequence.length); } /* @@ -693,8 +700,8 @@ SequenceI datasetSequence; public void setGeneLoci(String speciesId, String assemblyId, String chromosomeId, MapList map) { - addDBRef(new DBRefEntry(speciesId, assemblyId, DBRefEntry.CHROMOSOME - + ":" + chromosomeId, new Mapping(map))); + addDBRef(new DBRefEntry(speciesId, assemblyId, + DBRefEntry.CHROMOSOME + ":" + chromosomeId, new Mapping(map))); } /** @@ -723,9 +730,11 @@ SequenceI datasetSequence; @Override public String getAssemblyId() { - // DEV NOTE: DBRefEntry is reused here to hold chromosomal locus of a gene sequence. - // source=species, version=assemblyId, accession=chromosome, map = positions. - + // DEV NOTE: DBRefEntry is reused here to hold chromosomal locus + // of a gene sequence. + // source=species, version=assemblyId, accession=chromosome, map = + // positions. + return ref.getVersion(); } @@ -733,8 +742,8 @@ SequenceI datasetSequence; public String getChromosomeId() { // strip off "chromosome:" prefix to chrId - return ref.getAccessionId().substring( - DBRefEntry.CHROMOSOME.length() + 1); + return ref.getAccessionId() + .substring(DBRefEntry.CHROMOSOME.length() + 1); } @Override @@ -905,7 +914,7 @@ SequenceI datasetSequence; { return findPosition(column + 1, cursor); } - + // TODO recode this more naturally i.e. count residues only // as they are found, not 'in anticipation' @@ -1210,7 +1219,7 @@ SequenceI datasetSequence; { ArrayList map = new ArrayList<>(); int lastj = -1, j = 0; - int pos = start; + // int pos = start; int seqlen = sequence.length; while ((j < seqlen)) { @@ -1244,7 +1253,7 @@ SequenceI datasetSequence; { BitSet map = new BitSet(); int lastj = -1, j = 0; - int pos = start; + // int pos = start; int seqlen = sequence.length; while ((j < seqlen)) { @@ -1437,7 +1446,6 @@ SequenceI datasetSequence; return dbrefs; } - @Override public void addDBRef(DBRefEntry entry) { @@ -1449,10 +1457,10 @@ SequenceI datasetSequence; if (dbrefs == null) { - dbrefs = new DBModList(); + dbrefs = new DBModList<>(); } - for (int ib = 0, nb= dbrefs.size(); ib < nb; ib++) + for (int ib = 0, nb = dbrefs.size(); ib < nb; ib++) { if (dbrefs.get(ib).updateFrom(entry)) { @@ -1464,19 +1472,18 @@ SequenceI datasetSequence; } } + // /// BH OUCH! + // /* + // * extend the array to make room for one more + // */ + // // TODO use an ArrayList instead + // int j = dbrefs.length; + // List temp = new DBRefEntry[j + 1]; + // System.arraycopy(dbrefs, 0, temp, 0, j); + // temp[temp.length - 1] = entry; + // + // dbrefs = temp; -// /// BH OUCH! -// /* -// * extend the array to make room for one more -// */ -// // TODO use an ArrayList instead -// int j = dbrefs.length; -// List temp = new DBRefEntry[j + 1]; -// System.arraycopy(dbrefs, 0, temp, 0, j); -// temp[temp.length - 1] = entry; -// -// dbrefs = temp; - dbrefs.add(entry); } @@ -1590,7 +1597,7 @@ SequenceI datasetSequence; private int _seqhash = 0; -private List primaryRefs; + private List primaryRefs; /** * Answers false if the sequence is more than 85% nucleotide (ACGTU), else @@ -1766,8 +1773,9 @@ private List primaryRefs; List sfs = entry.getSequenceFeatures(); for (SequenceFeature feature : sfs) { - SequenceFeature sf[] = (mp != null) ? mp.locateFeature(feature) - : new SequenceFeature[] { new SequenceFeature(feature) }; + SequenceFeature sf[] = (mp != null) ? mp.locateFeature(feature) + : new SequenceFeature[] + { new SequenceFeature(feature) }; if (sf != null) { for (int sfi = 0; sfi < sf.length; sfi++) @@ -1869,7 +1877,7 @@ private List primaryRefs; } private List tmpList; - + @Override public List getPrimaryDBRefs() { @@ -1884,17 +1892,22 @@ private List primaryRefs; synchronized (dbrefs) { if (refModCount == dbrefs.getModCount() && primaryRefs != null) - return primaryRefs; // no changes - refModCount = dbrefs.getModCount(); - List primaries = (primaryRefs == null ? (primaryRefs = new ArrayList<>()) : primaryRefs); + { + return primaryRefs; // no changes + } + refModCount = dbrefs.getModCount(); + List primaries = (primaryRefs == null + ? (primaryRefs = new ArrayList<>()) + : primaryRefs); primaries.clear(); - if (tmpList == null) { - tmpList = new ArrayList<>(); - tmpList.add(null); // for replacement + if (tmpList == null) + { + tmpList = new ArrayList<>(); + tmpList.add(null); // for replacement } for (int i = 0, n = dbrefs.size(); i < n; i++) { - DBRefEntry ref = dbrefs.get(i); + DBRefEntry ref = dbrefs.get(i); if (!ref.isPrimaryCandidate()) { continue; @@ -1909,7 +1922,8 @@ private List primaryRefs; } } // whilst it looks like it is a primary ref, we also sanity check type - if (DBRefSource.PDB_CANONICAL_NAME.equals(ref.getCanonicalSourceName())) + if (DBRefSource.PDB_CANONICAL_NAME + .equals(ref.getCanonicalSourceName())) { // PDB dbrefs imply there should be a PDBEntry associated // TODO: tighten PDB dbrefs @@ -1922,19 +1936,23 @@ private List primaryRefs; { continue; } - } else { - // check standard protein or dna sources - tmpList.set(0, ref); - List res = DBRefUtils.selectDbRefs(!isProtein(), tmpList); - if (res == null || res.get(0) != tmpList.get(0)) - { - continue; - } - } + } + else + { + // check standard protein or dna sources + tmpList.set(0, ref); + List res = DBRefUtils.selectDbRefs(!isProtein(), + tmpList); + if (res == null || res.get(0) != tmpList.get(0)) + { + continue; + } + } primaries.add(ref); } - - // version must be not null, as otherwise it will not be a candidate, above + + // version must be not null, as otherwise it will not be a candidate, + // above DBRefUtils.ensurePrimaries(this, primaries); return primaries; } @@ -1953,15 +1971,15 @@ private List primaryRefs; List result = getFeatures().findFeatures(startPos, endPos, types); - if (datasetSequence != null) - { - result = datasetSequence.getFeatures().findFeatures(startPos, endPos, - types); - } - else - { - result = sequenceFeatureStore.findFeatures(startPos, endPos, types); - } + // if (datasetSequence != null) + // { + // result = datasetSequence.getFeatures().findFeatures(startPos, endPos, + // types); + // } + // else + // { + // result = sequenceFeatureStore.findFeatures(startPos, endPos, types); + // } /* * if end column is gapped, endPos may be to the right, @@ -2012,6 +2030,7 @@ private List primaryRefs; @Override public void sequenceChanged() { + argb = null; changeCount++; } @@ -2113,4 +2132,54 @@ private List primaryRefs; // otherwise, sequence was completely hidden return 0; } + + private int[] argb; + + @Override + public int getColor(int i) + { + return argb == null ? 0 : argb[i]; + } + + @Override + public int setColor(int i, int rgb) + { + if (argb == null) + { + argb = new int[this.sequence.length]; + } + return (argb[i] = rgb); + } + + @Override + public void resetColors() + { + argb = null; + } + + /** + * @author Bob Hanson 2019.07.30 + * + * allows passing the result ArrayList as a parameter to avoid + * unnecessary construction + * @return result (JavaScript) or new ArrayList (Java -- see FeatureRender) + * + */ + @Override + public List findFeatures(int column, String type, + List result) + { + return getFeatures().findFeatures(findPosition(column - 1), type, + result); + } + + /** + * allows early intervention for renderer if this returns false + */ + @Override + public boolean hasFeatures(String type) + { + return getFeatures().hasFeatures(type); + } + }