Revision 76e5c721
Added by Ben Stöver almost 8 years ago
.gitattributes | ||
---|---|---|
1987 | 1987 |
**/feature.xml merge=ours |
1988 | 1988 |
eu.etaxonomy.taxeditor.cdmlib/.classpath merge=ours |
1989 | 1989 |
eu.etaxonomy.taxeditor.cdmlib/build.properties merge=ours |
1990 |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java -text |
|
1991 |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java -text |
|
1990 | 1992 |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/ExportSingleReadAlignmentWizardPage.java -text |
1993 |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java -text |
|
1991 | 1994 |
eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product merge=ours |
1992 | 1995 |
eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product.with.jre merge=ours |
eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF | ||
---|---|---|
18 | 18 |
Bundle-Vendor: EDIT |
19 | 19 |
Export-Package: eu.etaxonomy.taxeditor.molecular, |
20 | 20 |
eu.etaxonomy.taxeditor.molecular.editor, |
21 |
eu.etaxonomy.taxeditor.molecular.handler |
|
21 |
eu.etaxonomy.taxeditor.molecular.handler, |
|
22 |
eu.etaxonomy.taxeditor.molecular.io |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.molecular.handler; |
|
11 |
|
|
12 |
|
|
13 |
import info.bioinfweb.jphyloio.JPhyloIOEventWriter; |
|
14 |
import info.bioinfweb.jphyloio.ReadWriteParameterMap; |
|
15 |
import info.bioinfweb.jphyloio.dataadapters.implementations.ListBasedDocumentDataAdapter; |
|
16 |
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory; |
|
17 |
import info.bioinfweb.jphyloio.formats.JPhyloIOFormatIDs; |
|
18 |
|
|
19 |
import java.io.File; |
|
20 |
import java.io.IOException; |
|
21 |
|
|
22 |
import org.eclipse.core.commands.AbstractHandler; |
|
23 |
import org.eclipse.core.commands.ExecutionEvent; |
|
24 |
import org.eclipse.core.commands.ExecutionException; |
|
25 |
import org.eclipse.jface.viewers.ISelection; |
|
26 |
import org.eclipse.jface.viewers.TreeNode; |
|
27 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
30 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
31 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
32 |
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin; |
|
33 |
import eu.etaxonomy.taxeditor.molecular.io.CDMSequenceMatrixAdapter; |
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Allows to exports a single read alignment to various alignment formats using |
|
39 |
* <a href="http://bioinfweb.info/JPhyloIO/">JPhyloIO</a>. |
|
40 |
* |
|
41 |
* @author Ben Stöver |
|
42 |
* @date 24.04.2016 |
|
43 |
*/ |
|
44 |
public class ExportSingleReadAlignmentHandler extends AbstractHandler { |
|
45 |
private static final JPhyloIOReaderWriterFactory factory = new JPhyloIOReaderWriterFactory(); |
|
46 |
|
|
47 |
|
|
48 |
@Override |
|
49 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
50 |
ISelection currentSelection = HandlerUtil.getCurrentSelection(event); |
|
51 |
TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection); |
|
52 |
if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence) { |
|
53 |
Sequence sequence = (Sequence)treeNodeOfSelection.getValue(); |
|
54 |
|
|
55 |
//TODO Collect the following information using a wizard. |
|
56 |
File targetFile = new File("O:\\Projects\\Bereich BBI\\EDIT Campanula\\Testdaten\\NeXMLExport.xml"); |
|
57 |
String formatID = JPhyloIOFormatIDs.NEXML_FORMAT_ID; |
|
58 |
ReadWriteParameterMap parameters = new ReadWriteParameterMap(); |
|
59 |
String consensusSequenceLabel = "Consensus sequence"; |
|
60 |
|
|
61 |
JPhyloIOEventWriter writer = factory.getWriter(formatID); |
|
62 |
|
|
63 |
ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter(); |
|
64 |
document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, consensusSequenceLabel)); |
|
65 |
|
|
66 |
try { |
|
67 |
writer.writeDocument(document, targetFile, parameters); |
|
68 |
} |
|
69 |
catch (IOException e) { |
|
70 |
e.printStackTrace(); |
|
71 |
MessagingUtils.errorDialog("IO error", this, |
|
72 |
"An error occured when trying to export a consensus sequence alignment to the file \"" + |
|
73 |
targetFile.getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false); //TODO set pluginID |
|
74 |
//TODO Use multi language error message. |
|
75 |
} |
|
76 |
} |
|
77 |
return null; |
|
78 |
} |
|
79 |
} |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ShowPherogramHandler.java | ||
---|---|---|
27 | 27 |
* Displays an undistorted pherogram with {@link PherogramViewPart}. |
28 | 28 |
* |
29 | 29 |
* @author Ben Stöver |
30 |
* |
|
31 | 30 |
*/ |
32 | 31 |
public class ShowPherogramHandler extends AbstractHandler { |
33 | 32 |
public static void showPherogram(PherogramComponentModel model) throws PartInitException { |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.molecular.io; |
|
11 |
|
|
12 |
|
|
13 |
import info.bioinfweb.commons.text.StringUtils; |
|
14 |
import info.bioinfweb.jphyloio.ReadWriteConstants; |
|
15 |
import info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver; |
|
16 |
import info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter; |
|
17 |
import info.bioinfweb.jphyloio.dataadapters.implementations.NoSetsMatrixDataAdapter; |
|
18 |
import info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent; |
|
19 |
import info.bioinfweb.jphyloio.events.SequenceTokensEvent; |
|
20 |
import info.bioinfweb.jphyloio.events.type.EventContentType; |
|
21 |
|
|
22 |
import java.io.IOException; |
|
23 |
import java.util.Iterator; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* In implementation of {@link MatrixDataAdapter} that delegates to a {@link Sequence} object. |
|
31 |
* |
|
32 |
* @author Ben Stöver |
|
33 |
* @date 29.04.2016 |
|
34 |
*/ |
|
35 |
public class CDMSequenceMatrixAdapter extends NoSetsMatrixDataAdapter implements ReadWriteConstants { |
|
36 |
public static final String MATRIX_ID = DEFAULT_MATRIX_ID_PREFIX + "ContigAlignment"; |
|
37 |
public static final String SINGLE_READ_SEQUENCE_ID_PREFIX = DEFAULT_SEQUENCE_ID_PREFIX + "SingleRead"; |
|
38 |
public static final String CONSENSUS_SEQUENCE_ID= DEFAULT_SEQUENCE_ID_PREFIX + "Consensus"; |
|
39 |
|
|
40 |
|
|
41 |
private Sequence sequence; |
|
42 |
private String consensusSequenceLabel; |
|
43 |
//TODO Also allow specifying single read labels? |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* Creates a new instance of this class. |
|
48 |
* |
|
49 |
* @param sequence |
|
50 |
* @param consensusSequenceLabel |
|
51 |
*/ |
|
52 |
public CDMSequenceMatrixAdapter(Sequence sequence, String consensusSequenceLabel) { |
|
53 |
super(); |
|
54 |
this.sequence = sequence; |
|
55 |
this.consensusSequenceLabel = consensusSequenceLabel; |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* @return the sequence |
|
61 |
*/ |
|
62 |
public Sequence getCDMSequence() { |
|
63 |
return sequence; |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
private int extractSingleReadIndexFromID(String sequenceID) { |
|
68 |
try { |
|
69 |
return Integer.parseInt(sequenceID.substring(SINGLE_READ_SEQUENCE_ID_PREFIX.length())); |
|
70 |
} |
|
71 |
catch (NumberFormatException e) { |
|
72 |
return -1; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
@Override |
|
78 |
public LinkedLabeledIDEvent getStartEvent() { |
|
79 |
return new LinkedLabeledIDEvent(EventContentType.ALIGNMENT, MATRIX_ID, "Contig alignment", null); |
|
80 |
//TODO Use label according to derivate and markers. |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
@Override |
|
85 |
public boolean containsLongTokens() { |
|
86 |
return false; |
|
87 |
} |
|
88 |
|
|
89 |
|
|
90 |
@Override |
|
91 |
public long getColumnCount() { |
|
92 |
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. |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
@Override |
|
97 |
public long getSequenceCount() { |
|
98 |
return /*sequence.getSingleReadAlignments().size() +*/ 1; |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
@Override |
|
103 |
public Iterator<String> getSequenceIDIterator() { |
|
104 |
return new SequenceIDIterator(getCDMSequence().getSingleReadAlignments().size()); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
@Override |
|
109 |
public long getSequenceLength(String sequenceID) throws IllegalArgumentException { |
|
110 |
int singleReadIndex = extractSingleReadIndexFromID(sequenceID); |
|
111 |
if (singleReadIndex >= 0) { |
|
112 |
//TODO Determine single read length. (Current problem: Reads are not ordered in the set of the Sequence object.) |
|
113 |
return 0; |
|
114 |
} |
|
115 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
116 |
return getCDMSequence().getSequenceString().length(); |
|
117 |
} |
|
118 |
else { |
|
119 |
throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found."); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
@Override |
|
125 |
public LinkedLabeledIDEvent getSequenceStartEvent(String sequenceID) { |
|
126 |
int singleReadIndex = extractSingleReadIndexFromID(sequenceID); |
|
127 |
if (singleReadIndex >= 0) { |
|
128 |
return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, "singleRead" + singleReadIndex, null); |
|
129 |
//TODO Use name displayed in derivate hierarchy or specified name as label instead? |
|
130 |
} |
|
131 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
132 |
return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, consensusSequenceLabel, null); |
|
133 |
} |
|
134 |
else { |
|
135 |
throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found."); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
@Override |
|
141 |
public void writeSequencePartContentData(JPhyloIOEventReceiver receiver, String sequenceID, long startColumn, |
|
142 |
long endColumn) throws IOException, IllegalArgumentException { |
|
143 |
|
|
144 |
int singleReadIndex = extractSingleReadIndexFromID(sequenceID); |
|
145 |
if (singleReadIndex >= 0) { |
|
146 |
//TODO Implement single read output. |
|
147 |
} |
|
148 |
else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) { |
|
149 |
if (startColumn == 0) { |
|
150 |
//TODO Add consensus sequence metadata. |
|
151 |
//TODO Possibly export additional properties of sequence (e.g. isBarcode(), getDdbjId(), ...) as metadata. |
|
152 |
} |
|
153 |
receiver.add(new SequenceTokensEvent(StringUtils.charSequenceToStringList( |
|
154 |
getCDMSequence().getSequenceString().substring((int)startColumn, (int)endColumn)))); |
|
155 |
} |
|
156 |
else { |
|
157 |
throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found."); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.molecular.io; |
|
11 |
|
|
12 |
import java.util.Iterator; |
|
13 |
import java.util.NoSuchElementException; |
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
/** |
|
18 |
* Iterator implementation used internally be {@link CDMSequenceMatrixAdapter}. |
|
19 |
* |
|
20 |
* @author Ben Stöver |
|
21 |
* @date 29.04.2016 |
|
22 |
*/ |
|
23 |
public class SequenceIDIterator implements Iterator<String> { |
|
24 |
private int singleReadPos; |
|
25 |
private int singleReadCount; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* Creates a new instance of this class. |
|
30 |
* |
|
31 |
* @param singleReadCount the number of single read IDs to be returned by this iterator before the consensus sequence |
|
32 |
*/ |
|
33 |
public SequenceIDIterator(int singleReadCount) { |
|
34 |
super(); |
|
35 |
this.singleReadCount = singleReadCount; |
|
36 |
this.singleReadPos = 0; |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
@Override |
|
41 |
public boolean hasNext() { |
|
42 |
return singleReadPos <= singleReadCount; |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
@Override |
|
47 |
public String next() { |
|
48 |
if (singleReadPos < singleReadCount) { |
|
49 |
return CDMSequenceMatrixAdapter.SINGLE_READ_SEQUENCE_ID_PREFIX + (singleReadPos++); |
|
50 |
} |
|
51 |
else if (singleReadPos == singleReadCount) { |
|
52 |
singleReadPos++; |
|
53 |
return CDMSequenceMatrixAdapter.CONSENSUS_SEQUENCE_ID; |
|
54 |
} |
|
55 |
else { |
|
56 |
throw new NoSuchElementException("There are no more sequence IDs availble from this iterator."); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
@Override |
|
62 |
public void remove() { |
|
63 |
throw new UnsupportedOperationException("This iterator does not support removing elements."); |
|
64 |
} |
|
65 |
} |
Also available in: Unified diff
Exported packages of molecular plugin updated.
Basic export functionality for direct export of consensus sequence alignments implemented (untested).