Revision ecd0d355
Added by Ben Stöver over 6 years ago
eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/messages.properties | ||
---|---|---|
1 | 1 |
wizardExportAlignmentAppendExtensionButton=Append default extension |
2 | 2 |
wizardExportAlignmentBrowseButton=Browse... |
3 | 3 |
wizardExportAlignmentDataLabel=Select the data to export: |
4 |
wizardExportAlignmentDescription=Define which data of the single read alignment shall be exported where.
|
|
4 |
wizardExportAlignmentDescription=Define the output file and format.
|
|
5 | 5 |
wizardExportAlignmentDestinationLabel=Select the export destination: |
6 | 6 |
wizardExportAlignmentErrorMissingFileName=The file name must not be empty. |
7 | 7 |
wizardExportAlignmentErrorMissingSeqLabel=The consensus sequence label must not be empty. |
eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/messages_de.properties | ||
---|---|---|
1 | 1 |
wizardExportAlignmentAppendExtensionButton=Standarddateiendung anh?ngen |
2 | 2 |
wizardExportAlignmentBrowseButton=Durchsuchen... |
3 | 3 |
wizardExportAlignmentDataLabel=Zu exportierende Daten: |
4 |
wizardExportAlignmentDescription=W?hlen Sie die zu exportierenden Daten und den Zielort aus!
|
|
4 |
wizardExportAlignmentDescription=W?hlen Sie den Zielort und das Zielformat aus!
|
|
5 | 5 |
wizardExportAlignmentDestinationLabel=Zieldatei: |
6 | 6 |
wizardExportAlignmentErrorMissingFileName=Der Dateiname darf nicht leer sein. |
7 | 7 |
wizardExportAlignmentErrorMissingSeqLabel=Der Name der Konsensussequenz darf nicht leer sein. |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
/** |
46 | 46 |
* Allows to export a single read alignment to various alignment formats using |
47 |
* <a href="http://bioinfweb.info/JPhyloIO/"><i>JPhyloIO</i> |
|
48 |
* </a>. |
|
47 |
* <a href="http://bioinfweb.info/JPhyloIO/"><i>JPhyloIO</i></a>. |
|
49 | 48 |
* |
50 | 49 |
* @author Ben Stöver |
51 | 50 |
* @date 24.04.2016 |
... | ... | |
67 | 66 |
// Prepare writer parameters: |
68 | 67 |
ReadWriteParameterMap parameters = new ReadWriteParameterMap(); |
69 | 68 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_NAME, ApplicationUtil.getTitle()); |
70 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_VERSION, ApplicationUtil.getVersion());
|
|
69 |
//parameters.put(ReadWriteParameterNames.KEY_APPLICATION_VERSION, ApplicationUtil.getVersion()); // Setting the version unnecessary, since its already contained in the title.
|
|
71 | 70 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_URL, "http://cybertaxonomy.eu/taxeditor/"); //TODO Specify URL obtained from a central class? |
72 | 71 |
parameters.put(ReadWriteParameterNames.KEY_SEQUENCE_EXTENSION_TOKEN, wizard.getModel().getElongationToken()); |
73 | 72 |
|
... | ... | |
80 | 79 |
// Create writer and document adapters: |
81 | 80 |
JPhyloIOEventWriter writer = factory.getWriter(wizard.getModel().getFormatInfo().getFormatID()); |
82 | 81 |
ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter(); |
83 |
document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getModel().getConsensusSequenceLabel())); |
|
82 |
document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getModel().getConsensusSequenceLabel(), |
|
83 |
wizard.getModel().isExportConsensusSequence(), wizard.getModel().isExportSingleReads())); |
|
84 | 84 |
|
85 | 85 |
// Write document: |
86 | 86 |
File file = new File(wizard.getModel().getFileName()); |
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? |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java | ||
---|---|---|
21 | 21 |
* @date 29.04.2016 |
22 | 22 |
*/ |
23 | 23 |
class SequenceIDIterator implements Iterator<String> { |
24 |
private boolean containsConsensus; |
|
24 | 25 |
private int singleReadPos; |
25 | 26 |
private int singleReadCount; |
26 | 27 |
|
... | ... | |
30 | 31 |
* |
31 | 32 |
* @param singleReadCount the number of single read IDs to be returned by this iterator before the consensus sequence |
32 | 33 |
*/ |
33 |
public SequenceIDIterator(int singleReadCount) { |
|
34 |
public SequenceIDIterator(int singleReadCount, boolean containsConsensus) {
|
|
34 | 35 |
super(); |
36 |
this.containsConsensus = containsConsensus; |
|
35 | 37 |
this.singleReadCount = singleReadCount; |
36 | 38 |
this.singleReadPos = 0; |
37 | 39 |
} |
... | ... | |
39 | 41 |
|
40 | 42 |
@Override |
41 | 43 |
public boolean hasNext() { |
42 |
return singleReadPos <= singleReadCount;
|
|
44 |
return (singleReadPos < singleReadCount) || (containsConsensus && (singleReadPos <= singleReadCount));
|
|
43 | 45 |
} |
44 | 46 |
|
45 | 47 |
|
... | ... | |
48 | 50 |
if (singleReadPos < singleReadCount) { |
49 | 51 |
return CDMSequenceMatrixAdapter.SINGLE_READ_SEQUENCE_ID_PREFIX + (singleReadPos++); |
50 | 52 |
} |
51 |
else if (singleReadPos == singleReadCount) {
|
|
53 |
else if (containsConsensus && (singleReadPos == singleReadCount)) {
|
|
52 | 54 |
singleReadPos++; |
53 | 55 |
return CDMSequenceMatrixAdapter.CONSENSUS_SEQUENCE_ID; |
54 | 56 |
} |
eu.etaxonomy.taxeditor.molecular/src/test/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIteratorTest.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
|
21 | 21 |
/** |
22 |
* @author bstoe_01
|
|
22 |
* @author Ben Stöver
|
|
23 | 23 |
* @date 29.04.2016 |
24 |
* |
|
25 | 24 |
*/ |
26 | 25 |
public class SequenceIDIteratorTest { |
27 | 26 |
@Test |
28 | 27 |
public void test_next() { |
29 |
SequenceIDIterator iterator = new SequenceIDIterator(3); |
|
28 |
SequenceIDIterator iterator = new SequenceIDIterator(3, true);
|
|
30 | 29 |
|
31 | 30 |
for (int i = 0; i < 3; i++) { |
32 | 31 |
assertTrue(iterator.hasNext()); |
... | ... | |
36 | 35 |
assertEquals("seqConsensus", iterator.next()); |
37 | 36 |
assertFalse(iterator.hasNext()); |
38 | 37 |
} |
38 |
|
|
39 |
|
|
40 |
@Test |
|
41 |
public void test_next_woConsensus() { |
|
42 |
SequenceIDIterator iterator = new SequenceIDIterator(3, false); |
|
43 |
|
|
44 |
for (int i = 0; i < 3; i++) { |
|
45 |
assertTrue(iterator.hasNext()); |
|
46 |
assertEquals("seqSingleRead" + i, iterator.next()); |
|
47 |
} |
|
48 |
assertFalse(iterator.hasNext()); |
|
49 |
} |
|
39 | 50 |
} |
Also available in: Unified diff
Messages edited.
Support for parameters to export only single reads or only consensus implemented.
JavaDoc extended.