/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
import jalview.analysis.Rna;
import jalview.analysis.SecStrConsensus.SimpleBP;
import jalview.analysis.WUSSParseException;
+import jalview.schemes.ResidueProperties;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
*/
public class AlignmentAnnotation
{
+ private static final String ANNOTATION_ID_PREFIX = "ann";
+
+ /*
+ * Identifers for different types of profile data
+ */
+ public static final int SEQUENCE_PROFILE = 0;
+
+ public static final int STRUCTURE_PROFILE = 1;
+
+ public static final int CDNA_PROFILE = 2;
+
+ private static long counter = 0;
+
/**
* If true, this annotations is calculated every edit, eg consensus, quality
* or conservation graphs
public SequenceFeature[] _rnasecstr = null;
/**
- * position of annotation resulting in invalid WUSS parsing or -1
+ * position of annotation resulting in invalid WUSS parsing or -1. -2 means
+ * there was no RNA structure in this annotation
*/
- private long invalidrnastruc = -1;
+ private long invalidrnastruc = -2;
/**
* Updates the _rnasecstr field Determines the positions that base pair and
private void _markRnaHelices()
{
+ int mxval = 0;
// Figure out number of helices
// Length of rnasecstr is the number of pairs of positions that base pair
// with each other in the secondary structure
try
{
val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
+ if (mxval < val)
+ {
+ mxval = val;
+ }
} catch (NumberFormatException q)
{
}
annotations[_rnasecstr[x].getBegin()].value = val;
annotations[_rnasecstr[x].getEnd()].value = val;
- annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
- annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
+ // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
+ // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
}
+ setScore(mxval);
}
/**
* map of positions in the associated annotation
*/
- public java.util.Hashtable<Integer, Annotation> sequenceMapping;
+ private Map<Integer, Annotation> sequenceMapping;
/** DOCUMENT ME!! */
public float graphMin;
public AlignmentAnnotation(String label, String description,
Annotation[] annotations)
{
+ setAnnotationId();
// always editable?
editable = true;
this.label = label;
&& firstChar != 'Y'
&& firstChar != 'Z'
&& firstChar != '-'
- && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
+ && firstChar < ResidueProperties.aaIndex.length)
{
- if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
+ if (ResidueProperties.aaIndex[firstChar] < 23) // TODO:
// parameterise
// to
// gap
_updateRnaSecStr(new AnnotCharSequence());
}
}
-
- annotationId = this.hashCode() + "";
}
/**
public char charAt(int index)
{
return ((index + offset < 0) || (index + offset) >= max
- || annotations[index + offset] == null || (annotations[index
- + offset].secondaryStructure < ' ') ? ' '
- : annotations[index + offset].secondaryStructure);
+ || annotations[index + offset] == null
+ || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
+ : annotations[index + offset].displayCharacter == null
+ || annotations[index + offset].displayCharacter
+ .length() == 0 ? annotations[index + offset].secondaryStructure
+ : annotations[index + offset].displayCharacter
+ .charAt(0));
}
+ @Override
public String toString()
{
char[] string = new char[max - offset];
for (int i = offset; i < mx; i++)
{
- string[i] = (annotations[i] == null || (annotations[i].secondaryStructure < 32)) ? ' '
- : annotations[i].secondaryStructure;
+ string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
+ : (annotations[i].displayCharacter == null
+ || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
+ : annotations[i].displayCharacter.charAt(0));
}
return new String(string);
}
public AlignmentAnnotation(String label, String description,
Annotation[] annotations, float min, float max, int graphType)
{
+ setAnnotationId();
// graphs are not editable
editable = graphType == 0;
{
if (annotations[i] != null)
{
- annotations[i].displayCharacter = "X";
+ annotations[i].displayCharacter = "";
}
}
}
*/
public AlignmentAnnotation(AlignmentAnnotation annotation)
{
+ setAnnotationId();
this.label = new String(annotation.label);
if (annotation.description != null)
{
if (annotation.sequenceMapping != null)
{
Integer p = null;
- sequenceMapping = new Hashtable();
- Enumeration pos = annotation.sequenceMapping.keys();
- while (pos.hasMoreElements())
+ sequenceMapping = new HashMap<Integer, Annotation>();
+ Iterator<Integer> pos = annotation.sequenceMapping.keySet()
+ .iterator();
+ while (pos.hasNext())
{
// could optimise this!
- p = (Integer) pos.nextElement();
+ p = pos.next();
Annotation a = annotation.sequenceMapping.get(p);
if (a == null)
{
int epos = sequenceRef.findPosition(endRes);
if (sequenceMapping != null)
{
- Hashtable newmapping = new Hashtable();
- Enumeration e = sequenceMapping.keys();
- while (e.hasMoreElements())
+ Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
+ Iterator<Integer> e = sequenceMapping.keySet().iterator();
+ while (e.hasNext())
{
- Integer pos = (Integer) e.nextElement();
+ Integer pos = e.next();
if (pos.intValue() >= spos && pos.intValue() <= epos)
{
newmapping.put(pos, sequenceMapping.get(pos));
*
* @return DOCUMENT ME!
*/
+ @Override
public String toString()
{
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder(256);
for (int i = 0; i < annotations.length; i++)
{
{
return;
}
- sequenceMapping = new java.util.Hashtable();
+ sequenceMapping = new HashMap<Integer, Annotation>();
int seqPos;
.getTo() == sq.getDatasetSequence()) : false;
// TODO build a better annotation element map and get rid of annotations[]
- Hashtable<Integer, Annotation> mapForsq = new Hashtable();
+ Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
if (sequenceMapping != null)
{
if (sp2sq != null)
{
if (mapping != null)
{
- Hashtable<Integer, Annotation> old = sequenceMapping, remap = new Hashtable<Integer, Annotation>();
+ Map<Integer, Annotation> old = sequenceMapping;
+ Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
int index = -1;
for (int mp[] : mapping)
{
{
if (properties == null)
{
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return properties.keySet();
}
+
+ /**
+ * Returns the Annotation for the given sequence position (base 1) if any,
+ * else null
+ *
+ * @param position
+ * @return
+ */
+ public Annotation getAnnotationForPosition(int position)
+ {
+ return sequenceMapping == null ? null : sequenceMapping.get(position);
+
+ }
+
+ /**
+ * Set the id to "ann" followed by a counter that increments so as to be
+ * unique for the lifetime of the JVM
+ */
+ protected final void setAnnotationId()
+ {
+ this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
+ }
+
+ protected static synchronized long nextId()
+ {
+ return counter++;
+ }
}