File: RNAStructScoreManager.java

package info (click to toggle)
libjaba-client-java 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,052 kB
  • sloc: java: 17,308; makefile: 12
file content (137 lines) | stat: -rw-r--r-- 4,032 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package compbio.data.sequence;


import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;

import compbio.data.sequence.ScoreManager.ScoreHolder;
import compbio.util.SysPrefs;

@XmlAccessorType(XmlAccessType.FIELD)
public class RNAStructScoreManager extends ScoreManager {

	
	private RNAStructScoreManager() {
		//Default JAXB constructor
	}
	

	public RNAStructScoreManager(List<String> structs, List<TreeSet<Score>> data) {
		
		assert(structs.size() == data.size());
		
		List<ScoreHolder> seqScores = new ArrayList<ScoreHolder>();
		
		for (int i = 0; i < structs.size(); i++) {
			seqScores.add(new ScoreHolder(structs.get(i), data.get(i)));
		}
		this.seqScores = seqScores;
	}
	
	public static RNAStructScoreManager newInstance(List<String> structs, List<TreeSet<Score>> data) {
		return new RNAStructScoreManager(structs, data);
	}
	
	public List<String> getStructs() {
		List<String> structs = new ArrayList<String>();
		for (ScoreHolder sch : this.seqScores) {
			structs.add(sch.id);
		}
		return structs;
	}
	
	public List<TreeSet<Score>> getData() {
		List<TreeSet<Score>> data = new ArrayList<TreeSet<Score>>();
		for (ScoreHolder sch : this.seqScores) {
			data.add(sch.scores);
		}
		return data;
		
	}
	
	/*
	 *  I want to be able to get the information in a ScoreHolder Object by
	 *  
	 */

	// Send this data Structure back to something approximating the stdoutFile
	// with extra information from alifold.out
	@Override
	public String toString() {
		String out = "";
		// The first objects hold the Consensus Alignment and the alifold.out info
		out += this.getStructs().get(0) + SysPrefs.newlinechar;

		// Now the rest of the structures with energies/frequencies
		for (int i = 1; i < this.getStructs().size(); i++) {
			out = out + this.getStructs().get(i).toString();

			if (this.getData().get(i).first().getScores().size() > 0) {
				List<Float> scores = this.getData().get(i).first().getScores();
				if (scores.size() >= 3) {
					out = out + " (" + scores.get(0).toString() + " = " 
							+ scores.get(1).toString() + " + " + scores.get(2).toString()
							+ ")" + SysPrefs.newlinechar;
				}
				else if (this.getData().get(i).first().getMethod().equals("alifoldMEA")) {
					out = out + " { " + scores.get(0).toString() + " MEA=" 
							+ scores.get(1).toString() + "}" + SysPrefs.newlinechar;
				}
				else if (scores.size() >= 2) {
					out = out + " [" + scores.get(0).toString() + ", " 
							+ scores.get(1).toString() + "]" + SysPrefs.newlinechar;

				}
			} else out += SysPrefs.newlinechar; 
		}
		if (this.getData().get(0).first().getScores().size() > 0) {
			Iterator<Score> iScores = this.getData().get(0).iterator();
			out += "Base Pairings followed by probability" + SysPrefs.newlinechar;
			for (int i = 0; i < this.getData().get(0).size(); i++) {
				Score s = iScores.next();
				Range r = s.getRanges().first();
				Float score = s.getScores().get(0);
				out += String.format("%4d  %4d    %.1f%n", r.from, r.to,
						score);
			}
		}


		return out;
	}

	@Override 
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof RNAStructScoreManager)) {
			return false;
		}
		RNAStructScoreManager other = (RNAStructScoreManager) obj;
		if (this.getStructs() == null) {
			if (other.getStructs() != null) {
				return false;
			}
		} else if (!this.getStructs().equals(other.getStructs()))
			return false;
		if (this.getData() == null) {
			if (other.getData() != null)
				return false;
		} else if (!this.getData().equals(other.getData()))
			return false;

		return true;
	}
}