import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Vector;
import com.stevesoft.pat.Regex;
*/
public class StockholmFile extends AlignFile
{
- private static final String ANNOTATION = "annotation";
+ private static final char UNDERSCORE = '_';
- private static final Regex OPEN_PAREN = new Regex("(<|\\[)", "(");
+ private static final String ANNOTATION = "annotation";
- private static final Regex CLOSE_PAREN = new Regex("(>|\\])", ")");
+ // private static final Regex OPEN_PAREN = new Regex("(<|\\[)", "(");
+ //
+ // private static final Regex CLOSE_PAREN = new Regex("(>|\\])", ")");
public static final Regex DETECT_BRACKETS = new Regex(
"(<|>|\\[|\\]|\\(|\\)|\\{|\\})");
String version;
// String id;
Hashtable seqAnn = new Hashtable(); // Sequence related annotations
- LinkedHashMap<String, String> seqs = new LinkedHashMap<String, String>();
+ LinkedHashMap<String, String> seqs = new LinkedHashMap<>();
Regex p, r, rend, s, x;
// Temporary line for processing RNA annotation
// String RNAannot = "";
strucAnn = new Hashtable();
}
- Vector<AlignmentAnnotation> newStruc = new Vector<AlignmentAnnotation>();
+ Vector<AlignmentAnnotation> newStruc = new Vector<>();
parseAnnotationRow(newStruc, type, ns);
for (AlignmentAnnotation alan : newStruc)
{
private void guessDatabaseFor(Sequence seqO, String dbr, String dbsource)
{
DBRefEntry dbrf = null;
- List<DBRefEntry> dbrs = new ArrayList<DBRefEntry>();
+ List<DBRefEntry> dbrs = new ArrayList<>();
String seqdb = "Unknown", sdbac = "" + dbr;
int st = -1, en = -1, p;
if ((st = sdbac.indexOf("/")) > -1)
for (int i = 0; i < annots.length(); i++)
{
String pos = annots.substring(i, i + 1);
+ if (UNDERSCORE == pos.charAt(0))
+ {
+ pos = " ";
+ }
Annotation ann;
ann = new Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not
// be written out
.form("#=GS " + idd.toString() + " "));
if (type.contains("PFAM") || type.contains("RFAM"))
{
-
out.append(" AC " + type.substring(type.indexOf(";") + 1));
}
else
String seq = "";
for (int k = 0; k < ann.length; k++)
{
- seq += outputCharacter(key, k, isrna, ann, s[i]);
+ seq += outputCharacter(key, k, ann, s[i]);
}
out.append(seq);
out.append(newline);
out.append(
new Format("%-" + maxid + "s").form("#=GC " + label + " "));
- boolean isrna = aa.isValidStruc();
for (int j = 0; j < aa.annotations.length; j++)
{
- seq += outputCharacter(key, j, isrna, aa.annotations, null);
+ seq += outputCharacter(key, j, aa.annotations, null);
}
out.append(seq);
out.append(newline);
*
* @param seq
* @param key
- * @param k
- * @param isrna
+ * @param column
* @param ann
* @param sequenceI
*/
- private char outputCharacter(String key, int k, boolean isrna,
- Annotation[] ann, SequenceI sequenceI)
+ static char outputCharacter(String key, int column, Annotation[] ann,
+ SequenceI sequenceI)
{
- char seq = ' ';
- Annotation annot = ann[k];
+ Annotation annot = column >= ann.length ? null : ann[column];
String ch = (annot == null)
? ((sequenceI == null) ? "-"
- : Character.toString(sequenceI.getCharAt(k)))
+ : Character.toString(sequenceI.getCharAt(column)))
: annot.displayCharacter;
- if (key != null && key.equals("SS"))
+
+ if ("SS".equals(key))
{
if (annot == null)
{
- // sensible gap character
- return ' ';
+ // whitespace not allowed in annotation
+ return UNDERSCORE;
}
else
{
}
}
+ char seq = '0';
if (ch.length() == 0)
{
seq = '.';
{
seq = ch.charAt(0);
}
- else if (ch.length() > 1)
+ else
{
seq = ch.charAt(1);
}
return out.toString();
}
- private static Hashtable typeIds = null;
+ private static Map<String, String> typeIds = null;
static
{
if (typeIds == null)
{
- typeIds = new Hashtable();
+ typeIds = new Hashtable<>();
typeIds.put("SS", "Secondary Structure");
typeIds.put("SA", "Surface Accessibility");
typeIds.put("TM", "transmembrane");
typeIds.put("DR", "reference");
typeIds.put("LO", "look");
typeIds.put("RF", "Reference Positions");
-
}
}
{
if (typeIds.containsKey(id))
{
- return (String) typeIds.get(id);
+ return typeIds.get(id);
}
System.err.println(
"Warning : Unknown Stockholm annotation type code " + id);
protected static String type2id(String type)
{
String key = null;
- Enumeration e = typeIds.keys();
- while (e.hasMoreElements())
+ for (Entry<String, String> entry : typeIds.entrySet())
{
- Object ll = e.nextElement();
- if (typeIds.get(ll).toString().equalsIgnoreCase(type))
+ if (entry.getValue().equalsIgnoreCase(type))
{
- key = (String) ll;
- break;
+ return entry.getKey();
}
}
- if (key != null)
- {
- return key;
- }
System.err.println(
"Warning : Unknown Stockholm annotation type: " + type);
return key;