Revision ecd0d355
Added by Ben Stöver over 7 years ago
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java | ||
---|---|---|
30 | 30 |
import java.io.IOException; |
31 | 31 |
import java.net.URI; |
32 | 32 |
import java.util.ArrayList; |
33 |
import java.util.Collections; |
|
33 | 34 |
import java.util.Iterator; |
34 | 35 |
import java.util.List; |
35 | 36 |
|
... | ... | |
57 | 58 |
|
58 | 59 |
|
59 | 60 |
private Sequence sequence; |
61 |
private boolean exportConsensus; |
|
60 | 62 |
private List<SingleReadAlignment> singleReadList; |
61 | 63 |
private String consensusSequenceLabel; |
62 | 64 |
private ObjectListDataAdapter<TokenSetDefinitionEvent> tokenSetList; |
... | ... | |
66 | 68 |
/** |
67 | 69 |
* Creates a new instance of this class. |
68 | 70 |
* |
69 |
* @param sequence |
|
70 |
* @param consensusSequenceLabel |
|
71 |
* @param sequence the <i>CDM</i> sequence object containing the data to be exported |
|
72 |
* @param consensusSequenceLabel the label to be used for the consensus sequence (Maybe {@code null}.) |
|
73 |
* @param exportConsensus Specify {@code true} here, if the consensus sequence shall be included in the export or {@code false} |
|
74 |
* otherwise. |
|
75 |
* @param exportSingleReads Specify {@code true} here, if the single reads shall be included in the export or {@code false} |
|
76 |
* otherwise. |
|
77 |
* @throws IllegalArgumentException if both {@code exportConsensus} and {@code exportSingleReads} are {@code false} |
|
71 | 78 |
*/ |
72 |
public CDMSequenceMatrixAdapter(Sequence sequence, String consensusSequenceLabel) { |
|
79 |
public CDMSequenceMatrixAdapter(Sequence sequence, String consensusSequenceLabel, boolean exportConsensus, boolean exportSingleReads) {
|
|
73 | 80 |
super(); |
74 |
this.sequence = sequence; |
|
75 |
this.consensusSequenceLabel = consensusSequenceLabel; |
|
76 |
tokenSetList = createTokenSetList(); |
|
77 |
singleReadList = new ArrayList<SingleReadAlignment>(sequence.getSingleReadAlignments()); // Store references of single reads in defined order to allow random access. |
|
78 |
//TODO Omit single reads that do not have an edited sequence yet? |
|
81 |
if (!exportConsensus && !exportSingleReads) { |
|
82 |
throw new IllegalArgumentException("Either exportConsensus or exportSingleReads must be true. " |
|
83 |
+ "Otherwise no sequences would be contained in this matrix."); |
|
84 |
} |
|
85 |
else { |
|
86 |
this.sequence = sequence; |
|
87 |
this.exportConsensus = exportConsensus; |
|
88 |
this.consensusSequenceLabel = consensusSequenceLabel; |
|
89 |
tokenSetList = createTokenSetList(); |
|
90 |
if (exportSingleReads) { |
|
91 |
singleReadList = new ArrayList<SingleReadAlignment>(sequence.getSingleReadAlignments()); // Store references of single reads in defined order to allow random access. |
|
92 |
//TODO Omit single reads that do not have an edited sequence yet? |
|
93 |
} |
|
94 |
else { |
|
95 |
singleReadList = Collections.emptyList(); |
|
96 |
} |
|
97 |
} |
|
79 | 98 |
} |
80 | 99 |
|
81 | 100 |
|
... | ... | |
125 | 144 |
|
126 | 145 |
@Override |
127 | 146 |
public long getColumnCount(ReadWriteParameterMap parameters) { |
128 |
return getCDMSequence().getSequenceString().length(); //TODO Consider that parts of single reads may lie outside of the current consensus sequence. Possibly return -1 in the future.
|
|
147 |
return -1; // Indicates that sequences may have different lengths. (Otherwise writing files without sequence elongation would not be possible.)
|
|
129 | 148 |
} |
130 | 149 |
|
131 | 150 |
|
132 | 151 |
@Override |
133 | 152 |
public long getSequenceCount(ReadWriteParameterMap parameters) { |
134 |
return singleReadList.size() + 1; // The last sequence is the consensus sequence. |
|
153 |
int addend = 1; |
|
154 |
if (!exportConsensus) { |
|
155 |
addend = 0; |
|
156 |
} |
|
157 |
return singleReadList.size() + addend; |
|
135 | 158 |
} |
136 | 159 |
|
137 | 160 |
|
138 | 161 |
@Override |
139 | 162 |
public Iterator<String> getSequenceIDIterator(ReadWriteParameterMap parameters) { |
140 |
return new SequenceIDIterator(getCDMSequence().getSingleReadAlignments().size());
|
|
163 |
return new SequenceIDIterator(singleReadList.size(), exportConsensus);
|
|
141 | 164 |
} |
142 | 165 |
|
143 | 166 |
|
... | ... | |
153 | 176 |
return 0; |
154 | 177 |
} |
155 | 178 |
} |
156 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
179 |
else if (exportConsensus && CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {
|
|
157 | 180 |
return getCDMSequence().getSequenceString().length(); |
158 | 181 |
} |
159 | 182 |
else { |
... | ... | |
169 | 192 |
return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, "Single read " + singleReadIndex, null); |
170 | 193 |
//TODO Use name displayed in derivate hierarchy or specified name as label instead? |
171 | 194 |
} |
172 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
195 |
else if (exportConsensus && CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {
|
|
173 | 196 |
return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, consensusSequenceLabel, null); |
174 | 197 |
} |
175 | 198 |
else { |
... | ... | |
225 | 248 |
} |
226 | 249 |
writeStringPart(receiver, singleRead.getEditedSequence(), startColumn, endColumn); |
227 | 250 |
} |
228 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
251 |
else if (exportConsensus && CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {
|
|
229 | 252 |
if (startColumn == 0) { |
230 | 253 |
writeMetadataEvents(receiver, sequenceID, PREDICATE_IS_CONSENSUS_SEQUENCE, W3CXSConstants.DATA_TYPE_BOOLEAN, new Boolean(true)); |
231 | 254 |
//TODO Possibly export additional properties of sequence (e.g. isBarcode(), getDdbjId(), ...) as metadata? |
Also available in: Unified diff
Messages edited.
Support for parameters to export only single reads or only consensus implemented.
JavaDoc extended.