public class StockholmFile extends AlignFile
{
// static Logger logger = Logger.getLogger("jalview.io.StockholmFile");
- StringBuffer out;
+ StringBuffer out; // output buffer
AlignmentI al;
public StockholmFile()
if (rend.search(line))
{
// End of the alignment, pass stuff back
-
this.noSeqs = seqs.size();
+
+ String propety = null;
+ Regex pf = new Regex("PF[0-9]{5}(.*)"); // Finds AC for Pfam
+ Regex rf = new Regex("RF[0-9]{5}(.*)"); // Finds AC for Rfam
+ if (getAlignmentProperty("AC") != null)
+ {
+ String dbType = getAlignmentProperty("AC").toString();
+ if (pf.search(dbType))
+ {
+ propety = "PFAM";
+ }
+ else if (rf.search(dbType))
+ {
+ propety = "RFAM";
+ }
+ }
// logger.debug("Number of sequences: " + this.noSeqs);
Enumeration accs = seqs.keys();
while (accs.hasMoreElements())
String desc = (String) accAnnotations.get("DE");
seqO.setDescription((desc == null) ? "" : desc);
}
+
+
+
// Add DB References (if any)
if (accAnnotations != null && accAnnotations.containsKey("DR"))
{
String src = dbr.substring(0, dbr.indexOf(";"));
String acn = dbr.substring(dbr.indexOf(";") + 1);
jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn);
- // seqO.addDBRef(dbref);
- }
- }
-
+ }
+ }
+
+ if (accAnnotations != null && accAnnotations.containsKey("AC") && propety != null)
+ {
+ String dbr = (String) accAnnotations.get("AC");
+ if (dbr != null)
+ {
+ String src = propety;
+ String acn = dbr.toString();
+ jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn);
+ }
+ }
+
+
Hashtable features = null;
// We need to adjust the positions of all features to account for gaps
try
convert1 = openparen.replaceAll(annots);
convert2 = closeparen.replaceAll(convert1);
annots = convert2;
-
- String type = (label.indexOf("_cons") == label.length() - 5) ? label
- .substring(0, label.length() - 5) : label;
+
+ String type = label;
+ if (label.contains("_cons")) {
+ type = (label.indexOf("_cons") == label.length() - 5) ? label
+ .substring(0, label.length() - 5) : label;
+ }
boolean ss = false;
type = id2type(type);
if (type.equals("secondary structure"))
}
return annot;
}
-
+
public String print(SequenceI[] s)
{
// find max length of id
int max = 0;
int maxid = 0;
int in = 0;
+ Hashtable dataRef = null;
while ((in < s.length) && (s[in] != null))
{
String tmp = printId(s[in]);
{
maxid = tmp.length();
}
-
+ if (s[in].getDBRef() != null)
+ {
+ for (int idb = 0; idb < s[in].getDBRef().length; idb++)
+ {
+ if (dataRef == null)
+ dataRef = new Hashtable();
+
+ String datAs1 = s[in].getDBRef()[idb].getSource().toString() + " ; " +s[in].getDBRef()[idb].getAccessionId().toString();
+ dataRef.put(tmp, datAs1);
+ }
+ }
in++;
}
maxid += 9;
int i = 0;
+ // output database type
+ if (al.getProperties() != null)
+ {
+ if (!al.getProperties().isEmpty())
+ {
+ Enumeration key = al.getProperties().keys();
+ Enumeration val = al.getProperties().elements();
+ while (key.hasMoreElements())
+ {
+ out.append("#=GF " + key.nextElement() + " " + val.nextElement());
+ out.append(newline);
+ }
+ }
+ }
+
+ // output database accessions
+ if (dataRef != null)
+ {
+ Enumeration en = dataRef.keys();
+ while (en.hasMoreElements())
+ {
+ Object idd = en.nextElement();
+ String type = (String) dataRef.remove(idd);
+ out.append(new Format("%-" + (maxid - 2) + "s").form("#=GS " +idd.toString() + " "));
+ if (type.contains("PFAM") || type.contains("RFAM") )
+ {
+
+ out.append(" AC " + type.substring(type.indexOf(";") + 1));
+ } else
+ {
+ out.append(" DR " + type + " ");
+ }
+ out.append(newline);
+ }
+ }
+
+ // output annotations
while (i < s.length && s[i] != null)
{
if (s[i].getDatasetSequence() != null)
{
- SequenceI ds = s[i].getDatasetSequence();
+ SequenceI ds = s[i].getDatasetSequence();
AlignmentAnnotation[] alAnot;
Annotation[] ann;
Annotation annot;
}
String key = type2id(feature);
- // output annotations
+
if (key == null)
continue;
continue;
}
String seq = "";
- String label = type2id(aa.label);
+ String label;
+
+ if (aa.label.equals("seq"))
+ label = "seq_cons";
+ else
+ label = type2id(aa.label.toLowerCase())+"_cons";
if (label == null)
label = aa.label;
-
- label += "_cons";
-
+
out.append(new Format("%-" + maxid + "s").form("#=GC " + label+" "));
for (int j = 0; j < aa.annotations.length; j++)
{
break;
}
}
- if (key != null)
+ if (key != null)
{
return (String) key;
}