import java.io.IOException;\r
import java.io.OutputStream;\r
import java.io.OutputStreamWriter;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
public class ScoreManager {\r
\r
+ public static final String SINGLE_ENTRY_KEY = "Alignment";\r
+\r
private List<ScoreHolder> seqScores;\r
\r
private ScoreManager() {\r
// Default JAXB constructor\r
}\r
\r
- public int getNumberOfSeq() {\r
- return seqScores.size();\r
+ private ScoreManager(String id, Set<Score> data) {\r
+ seqScores = new ArrayList<ScoreManager.ScoreHolder>();\r
+ seqScores.add(new ScoreHolder(id, data));\r
}\r
\r
- public ScoreHolder getFirstSequenceScores() {\r
- if (seqScores.isEmpty())\r
- return null;\r
- return seqScores.get(0);\r
+ private ScoreManager(Map<String, Set<Score>> data) {\r
+ List<ScoreHolder> seqScores = new ArrayList<ScoreHolder>();\r
+ for (Map.Entry<String, Set<Score>> singleSeqScores : data.entrySet()) {\r
+ seqScores.add(new ScoreHolder(singleSeqScores.getKey(),\r
+ singleSeqScores.getValue()));\r
+ }\r
+ this.seqScores = seqScores;\r
+ }\r
+\r
+ public static ScoreManager newInstance(Map<String, Set<Score>> data) {\r
+ return new ScoreManager(data);\r
+ }\r
+\r
+ public static ScoreManager newInstanceSingleScore(\r
+ Map<String, Score> seqScoresMap) {\r
+ Map<String, Set<Score>> multipleScoresMap = new HashMap<String, Set<Score>>();\r
+ for (Map.Entry<String, Score> seqScore : seqScoresMap.entrySet()) {\r
+ Set<Score> scores = new HashSet<Score>();\r
+ scores.add(seqScore.getValue());\r
+ multipleScoresMap.put(seqScore.getKey(), scores);\r
+ }\r
+ return new ScoreManager(multipleScoresMap);\r
+ }\r
+\r
+ public static ScoreManager newInstanceSingleSequence(Set<Score> data) {\r
+ return new ScoreManager(ScoreManager.SINGLE_ENTRY_KEY, data);\r
+ }\r
+\r
+ public Map<String, Set<Score>> asMap() {\r
+ Map<String, Set<Score>> seqScoresMap = new HashMap<String, Set<Score>>();\r
+ for (ScoreHolder sch : this.seqScores) {\r
+ Set<Score> oldValue = seqScoresMap.put(sch.id, sch.scores);\r
+ if (oldValue != null) {\r
+ throw new IllegalStateException(\r
+ "Cannot represent this ScoreManager instance "\r
+ + "as a Map as it contains duplicated keys: "\r
+ + sch.id);\r
+ }\r
+ }\r
+ return seqScoresMap;\r
+ }\r
+\r
+ public Set<Score> asSet() {\r
+ if (seqScores.size() == 0 || seqScores.size() > 1) {\r
+ throw new IllegalStateException(\r
+ "This ScoreManager has no or multiple sequence entries and thus "\r
+ + "cannot be represented as a Set. Number of entries are: "\r
+ + seqScores.size());\r
+ }\r
+ ScoreHolder sch = seqScores.get(0);\r
+ return sch.scores;\r
+ }\r
+\r
+ public int getNumberOfSeq() {\r
+ return seqScores.size();\r
}\r
\r
public ScoreHolder getAnnotationForSequence(String seqId) {\r
writer.flush();\r
}\r
\r
+ @XmlAccessorType(XmlAccessType.FIELD)\r
public static class ScoreHolder {\r
\r
public String id;\r
- public HashSet<Score> scores;\r
+ public Set<Score> scores;\r
+\r
+ private ScoreHolder() {\r
+ // JAXB Default constructor should not be used otherwise\r
+ }\r
+\r
+ ScoreHolder(String id, Set<Score> scores) {\r
+ this.id = id;\r
+ this.scores = scores;\r
+ }\r
\r
public void writeOut(OutputStream outStream) throws IOException {\r
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
Score.write(scores, outStream);\r
}\r
\r
- public Score getFirstScore() {\r
- if (scores.isEmpty())\r
- return null;\r
- return scores.iterator().next();\r
- }\r
-\r
public Score getScoreByMethod(Enum<?> method) {\r
for (Score sc : scores) {\r
if (method == sc.getMethod()) {\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Scanner;\r
+import java.util.Set;\r
import java.util.TreeSet;\r
import java.util.logging.Level;\r
import java.util.regex.Matcher;\r
* @throws IOException\r
* @throws UnknownFileFormatException\r
*/\r
- public static HashMap<FastaSequence, HashSet<Score>> readDisembl(\r
+ public static HashMap<String, Set<Score>> readDisembl(\r
final InputStream input) throws IOException,\r
UnknownFileFormatException {\r
Scanner scan = new Scanner(input);\r
+ " No such line was found!");\r
}\r
\r
- HashMap<FastaSequence, HashSet<Score>> results = new HashMap<FastaSequence, HashSet<Score>>();\r
+ HashMap<String, Set<Score>> results = new HashMap<String, Set<Score>>();\r
int seqCounter = 0;\r
while (scan.hasNext()) {\r
seqCounter++;\r
rem.add(scansingle.nextFloat());\r
hotloops.add(scansingle.nextFloat());\r
}\r
- FastaSequence fs = new FastaSequence(sequenceName,\r
- seqbuffer.toString());\r
+ /*\r
+ * Also possible FastaSequence fs = new FastaSequence(sequenceName,\r
+ * seqbuffer.toString());\r
+ */\r
HashSet<Score> scores = new HashSet<Score>();\r
scores.add(new Score(DisemblResult.COILS, coils, coilsR));\r
scores.add(new Score(DisemblResult.HOTLOOPS, hotloops, rem465R));\r
scores.add(new Score(DisemblResult.REM465, rem, loopsR));\r
- results.put(fs, scores);\r
+ results.put(sequenceName, scores);\r
\r
scansingle.close();\r
}\r
return ranges;\r
}\r
\r
- public static HashMap<String, HashSet<Score>> removeSequences(\r
- HashMap<FastaSequence, HashSet<Score>> disemblResults) {\r
- HashMap<String, HashSet<Score>> seqNameScores = new HashMap<String, HashSet<Score>>();\r
- for (Map.Entry<FastaSequence, HashSet<Score>> dres : disemblResults\r
- .entrySet()) {\r
- seqNameScores.put(dres.getKey().getId(), dres.getValue());\r
- }\r
- return seqNameScores;\r
- }\r
-\r
/**\r
* \r
> Foobar_dundeefriends\r
* @throws IOException\r
* @throws UnknownFileFormatException\r
*/\r
- public static HashMap<FastaSequence, HashSet<Score>> readGlobPlot(\r
+ public static HashMap<String, Set<Score>> readGlobPlot(\r
final InputStream input) throws IOException,\r
UnknownFileFormatException {\r
Scanner scan = new Scanner(input);\r
+ " No such line was found!");\r
}\r
\r
- HashMap<FastaSequence, HashSet<Score>> results = new HashMap<FastaSequence, HashSet<Score>>();\r
+ HashMap<String, Set<Score>> results = new HashMap<String, Set<Score>>();\r
int seqCounter = 0;\r
while (scan.hasNext()) {\r
seqCounter++;\r
rawScore.add(scansingle.nextFloat());\r
smoothedScore.add(scansingle.nextFloat());\r
}\r
- FastaSequence fs = new FastaSequence(sequenceName,\r
- seqbuffer.toString());\r
+ /*\r
+ * Also possible FastaSequence fs = new FastaSequence(sequenceName,\r
+ * seqbuffer.toString());\r
+ */\r
HashSet<Score> scores = new HashSet<Score>();\r
scores.add(new Score(GlobProtResult.Disorder, disorderR));\r
scores.add(new Score(GlobProtResult.GlobDoms, domsR));\r
scores.add(new Score(GlobProtResult.Dydx, dydxScore));\r
scores.add(new Score(GlobProtResult.RawScore, rawScore));\r
scores.add(new Score(GlobProtResult.SmoothedScore, smoothedScore));\r
- results.put(fs, scores);\r
+ results.put(sequenceName, scores);\r
\r
scansingle.close();\r
}\r
}\r
/**\r
* Read AACon result with no alignment files. This method leaves incoming\r
- * the InputStream results open!\r
+ * InputStream open!\r
* \r
* @param results\r
* output file of AAConservation\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.util.Arrays;\r
-import java.util.HashSet;\r
import java.util.List;\r
\r
import org.apache.log4j.Logger;\r
\r
import compbio.data.sequence.SMERFSConstraints;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.engine.client.CommandBuilder;\r
import compbio.engine.client.Executable;\r
}\r
// HashMap<Method, float[]>\r
@Override\r
- public HashSet<Score> getResults(String workDirectory)\r
+ public ScoreManager getResults(String workDirectory)\r
throws ResultNotAvailableException {\r
- HashSet<Score> annotations = null;\r
+ ScoreManager annotations = null;\r
try {\r
InputStream inStream = new FileInputStream(new File(workDirectory,\r
getOutput()));\r
- annotations = SequenceUtil.readAAConResults(inStream);\r
+ annotations = ScoreManager.newInstanceSingleSequence(SequenceUtil\r
+ .readAAConResults(inStream));\r
inStream.close();\r
} catch (FileNotFoundException e) {\r
log.error(e.getMessage(), e.getCause());\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
\r
import org.apache.log4j.Logger;\r
\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.engine.client.Executable;\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
- public HashMap<String, HashSet<Score>> getResults(String workDirectory)\r
+ public ScoreManager getResults(String workDirectory)\r
throws ResultNotAvailableException {\r
\r
InputStream inStream = null;\r
- HashMap<String, HashSet<Score>> results = null;\r
+ ScoreManager results = null;\r
\r
try {\r
inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
- results = SequenceUtil.removeSequences(SequenceUtil\r
+ results = ScoreManager.newInstance(SequenceUtil\r
.readDisembl(inStream));\r
inStream.close();\r
} catch (FileNotFoundException e) {\r
log.trace("DRESULTS: " + results);\r
return results;\r
}\r
-\r
@Override\r
public Disembl setInput(String inFile) {\r
super.setInput(inFile);\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
\r
import org.apache.log4j.Logger;\r
\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.engine.client.Executable;\r
}\r
\r
@SuppressWarnings("unchecked")\r
- public HashMap<String, HashSet<Score>> getResults(String workDirectory)\r
+ public ScoreManager getResults(String workDirectory)\r
throws ResultNotAvailableException {\r
\r
InputStream inStream = null;\r
- HashMap<String, HashSet<Score>> results = null;\r
+ ScoreManager results = null;\r
// How about getting ranges?\r
try {\r
inStream = new FileInputStream(new File(workDirectory, getOutput()));\r
- results = SequenceUtil.removeSequences(SequenceUtil\r
+ results = ScoreManager.newInstance(SequenceUtil\r
.readGlobPlot(inStream));\r
inStream.close();\r
} catch (FileNotFoundException e) {\r
import java.io.InputStream;\r
import java.util.Arrays;\r
import java.util.List;\r
-import java.util.Map;\r
\r
import org.apache.log4j.Logger;\r
\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
import compbio.data.sequence.SequenceUtil;\r
import compbio.data.sequence.UnknownFileFormatException;\r
import compbio.engine.client.CommandBuilder;\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
- public Map<String, Score> getResults(String workDirectory)\r
+ public ScoreManager getResults(String workDirectory)\r
throws ResultNotAvailableException {\r
- Map<String, Score> sequences = null;\r
+ ScoreManager sequences = null;\r
try {\r
InputStream inStream = new FileInputStream(new File(workDirectory,\r
getOutput()));\r
- sequences = SequenceUtil.readJRonn(inStream);\r
+ sequences = ScoreManager.newInstanceSingleScore(SequenceUtil\r
+ .readJRonn(inStream));\r
inStream.close();\r
} catch (FileNotFoundException e) {\r
log.error(e.getMessage(), e.getCause());\r
try {\r
fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+ "disembl.out");\r
- Map<FastaSequence, HashSet<Score>> aseqs = SequenceUtil\r
- .readDisembl(fio);\r
+ Map<String, Set<Score>> aseqs = SequenceUtil.readDisembl(fio);\r
assertNotNull(aseqs);\r
assertEquals(aseqs.size(), 3);\r
// System.out.println(aseqs);\r
- for (FastaSequence fs : aseqs.keySet()) {\r
+ for (String fs : aseqs.keySet()) {\r
assertTrue(" Foobar_dundeefriends Foobar dundeefriends "\r
- .contains(fs.getId()));\r
+ .contains(fs));\r
Set<Score> scores = aseqs.get(fs);\r
assertEquals(scores.size(), 3);\r
}\r
try {\r
fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+ "globplot.out");\r
- HashMap<FastaSequence, HashSet<Score>> aseqs = SequenceUtil\r
- .readGlobPlot(fio);\r
+ HashMap<String, Set<Score>> aseqs = SequenceUtil.readGlobPlot(fio);\r
assertNotNull(aseqs);\r
assertEquals(aseqs.size(), 3);\r
\r
- FastaSequence fsdf = null;\r
+ String fsdf = null;\r
Set<Score> scores = null;\r
- for (FastaSequence fs : aseqs.keySet()) {\r
- if ("Foobar_dundeefriends".contains(fs.getId())) {\r
+ for (String fs : aseqs.keySet()) {\r
+ if ("Foobar_dundeefriends".contains(fs)) {\r
fsdf = fs;\r
scores = aseqs.get(fs);\r
}\r
System.out.println("J: " + jobId);\r
ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
+ assertEquals(result.asSet().size(), 1);\r
\r
- assertEquals(result.getFirstSequenceScores().getFirstScore()\r
- .getMethod(), ConservationMethod.SHENKIN);\r
- List<Float> scores = result.getFirstSequenceScores()\r
- .getFirstScore().getScores();\r
+ assertEquals(result.asSet().iterator().next().getMethod(),\r
+ ConservationMethod.SHENKIN);\r
+ List<Float> scores = result.asSet().iterator().next().getScores();\r
assertNotNull(scores);\r
assertEquals(scores.size(), 568);\r
\r
presets.getPresetByName("Quick conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
- 13);\r
+ assertEquals(result.asSet().size(), 13);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Slow conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 5);\r
+ assertEquals(result.asSet().size(), 5);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Complete conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
- 18);\r
+ assertEquals(result.asSet().size(), 18);\r
\r
} catch (UnsupportedRuntimeException e) {\r
e.printStackTrace();\r
presets.getPresetByName("Quick conservation"));\r
ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
- 13);\r
+ assertEquals(result.asSet().size(), 13);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Slow conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 5);\r
+ assertEquals(result.asSet().size(), 5);\r
\r
jobId = msaws.presetAnalize(fsl,\r
presets.getPresetByName("Complete conservation"));\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(),\r
- 18);\r
+ assertEquals(result.asSet().size(), 18);\r
\r
} catch (UnsupportedRuntimeException e) {\r
e.printStackTrace();\r
String jobId = msaws.customAnalize(fsl, options.getArguments());\r
ScoreManager result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
- assertEquals(result.getFirstSequenceScores().getFirstScore()\r
- .getScores().get(0), 0.698f);\r
+ assertEquals(result.asSet().size(), 1);\r
+ assertEquals(result.asSet().iterator().next().getScores().get(0),\r
+ 0.698f);\r
\r
options.getArgument("Calculation method").setDefaultValue("SMERFS");\r
options.removeArgument("Normalize");\r
jobId = msaws.customAnalize(fsl, options.getArguments());\r
result = msaws.getAnnotation(jobId);\r
assertNotNull(result);\r
- assertEquals(result.getFirstSequenceScores().getNumberOfScores(), 1);\r
- assertEquals(result.getFirstSequenceScores().getFirstScore()\r
- .getScores().get(0), 0.401f);\r
+ assertEquals(result.asSet().size(), 1);\r
+ assertEquals(result.asSet().iterator().next().getScores().get(0),\r
+ 0.401f);\r
\r
} catch (WrongParameterException e) {\r
e.printStackTrace();\r