1 package compbio.data.sequence;
4 import java.util.Iterator;
6 import java.util.TreeSet;
8 import java.util.ArrayList;
10 import javax.xml.bind.annotation.XmlAccessType;
11 import javax.xml.bind.annotation.XmlAccessorType;
13 import compbio.util.annotation.Immutable;
14 import compbio.util.SysPrefs;
15 import compbio.data.sequence.Score;
18 * RNA secondary structure
19 * A class which is essentially just a Pair(List<String>, List<Set<Score>>)
20 * For the purpose of creating and retrieving data from ScoreManager Objects
21 * which are being used to store RNA folding output
24 @XmlAccessorType(XmlAccessType.FIELD)
25 public final class RNAStruct {
27 private List<String> structs = new ArrayList<String>();
28 private List<TreeSet<Score>> data = new ArrayList<TreeSet<Score>>();
32 // default JaxB Constructor
35 public RNAStruct(List<String> structs, List<TreeSet<Score>> data) {
36 assert(structs.size() == data.size());
37 this.structs = structs;
41 public List<String> getStructs() {
45 public List<TreeSet<Score>> getData() {
49 // Send this data Structure back to something approximating the stdoutFile
50 // with extra information from alifold.out
52 public String toString() {
54 // The first objects hold the Consensus Alignment and the alifold.out info
55 out += structs.get(0) + SysPrefs.newlinechar;
57 // Now the rest of the structures with energies/frequencies
58 for (int i = 1; i < structs.size(); i++) {
59 out = out + structs.get(i).toString();
61 if (data.get(i).first().getScores().size() > 0) {
62 List<Float> scores = data.get(i).first().getScores();
63 if (scores.size() >= 3) {
64 out = out + " (" + scores.get(0).toString() + " = "
65 + scores.get(1).toString() + " + " + scores.get(2).toString()
66 + ")" + SysPrefs.newlinechar;
68 else if (data.get(i).first().getMethod().equals("alifoldMEA")) {
69 out = out + " { " + scores.get(0).toString() + " MEA="
70 + scores.get(1).toString() + "}" + SysPrefs.newlinechar;
72 else if (scores.size() >= 2) {
73 out = out + " [" + scores.get(0).toString() + ", "
74 + scores.get(1).toString() + "]" + SysPrefs.newlinechar;
77 } else out += SysPrefs.newlinechar;
79 if (data.get(0).first().getScores().size() > 0) {
80 Iterator<Score> iScores = data.get(0).iterator();
81 out += "Base Pairings followed by probability" + SysPrefs.newlinechar;
82 for (int i = 0; i < data.get(0).size(); i++) {
83 Score s = iScores.next();
84 Range r = s.getRanges().first();
85 Float score = s.getScores().get(0);
86 out += String.format("%4d %4d %.1f%n", r.getFrom(), r.getTo(),
95 public boolean equals(Object obj) {
99 if (!(obj instanceof RNAStruct)) {
102 RNAStruct other = (RNAStruct) obj;
103 if (structs == null) {
104 if (other.structs != null) {
107 } else if (!structs.equals(other.structs))
110 if (other.data != null)
112 } else if (!data.equals(other.data))