Exported packages of molecular plugin updated.
authorb.stoever <b.stoever@localhost>
Fri, 29 Apr 2016 18:09:50 +0000 (18:09 +0000)
committerb.stoever <b.stoever@localhost>
Fri, 29 Apr 2016 18:09:50 +0000 (18:09 +0000)
Basic export functionality for direct export of consensus sequence alignments implemented (untested).

.gitattributes
eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ShowPherogramHandler.java
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java [new file with mode: 0644]

index b1ef5559e4bb6898eead8e6547762d6b06c7d2e6..d993a4e0e57e6093c895c63dd41c4818ac931708 100644 (file)
@@ -1987,6 +1987,9 @@ src/site/site.xml -text
 **/feature.xml merge=ours
 eu.etaxonomy.taxeditor.cdmlib/.classpath merge=ours
 eu.etaxonomy.taxeditor.cdmlib/build.properties merge=ours
+eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java -text
+eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java -text
 eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/ExportSingleReadAlignmentWizardPage.java -text
+eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java -text
 eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product merge=ours
 eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product.with.jre merge=ours
index 2b9ee3480f927822a9e6b097340d6292260188e5..cc67becb1e5f5d12ceed7421e049c47275c5e2db 100644 (file)
@@ -18,4 +18,5 @@ Bundle-ActivationPolicy: lazy
 Bundle-Vendor: EDIT
 Export-Package: eu.etaxonomy.taxeditor.molecular,
  eu.etaxonomy.taxeditor.molecular.editor,
- eu.etaxonomy.taxeditor.molecular.handler
+ eu.etaxonomy.taxeditor.molecular.handler,
+ eu.etaxonomy.taxeditor.molecular.io
diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSingleReadAlignmentHandler.java
new file mode 100644 (file)
index 0000000..e99f985
--- /dev/null
@@ -0,0 +1,79 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.molecular.handler;\r
+\r
+\r
+import info.bioinfweb.jphyloio.JPhyloIOEventWriter;\r
+import info.bioinfweb.jphyloio.ReadWriteParameterMap;\r
+import info.bioinfweb.jphyloio.dataadapters.implementations.ListBasedDocumentDataAdapter;\r
+import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
+import info.bioinfweb.jphyloio.formats.JPhyloIOFormatIDs;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.TreeNode;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+\r
+import eu.etaxonomy.cdm.model.molecular.Sequence;\r
+import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
+import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;\r
+import eu.etaxonomy.taxeditor.molecular.io.CDMSequenceMatrixAdapter;\r
+\r
+\r
+\r
+/**\r
+ * Allows to exports a single read alignment to various alignment formats using\r
+ * <a href="http://bioinfweb.info/JPhyloIO/">JPhyloIO</a>.\r
+ *\r
+ * @author Ben Stöver\r
+ * @date 24.04.2016\r
+ */\r
+public class ExportSingleReadAlignmentHandler extends AbstractHandler {\r
+    private static final JPhyloIOReaderWriterFactory factory = new JPhyloIOReaderWriterFactory();\r
+\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);\r
+        TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);\r
+        if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence) {\r
+            Sequence sequence = (Sequence)treeNodeOfSelection.getValue();\r
+\r
+            //TODO Collect the following information using a wizard.\r
+            File targetFile = new File("O:\\Projects\\Bereich BBI\\EDIT Campanula\\Testdaten\\NeXMLExport.xml");\r
+            String formatID = JPhyloIOFormatIDs.NEXML_FORMAT_ID;\r
+            ReadWriteParameterMap parameters = new ReadWriteParameterMap();\r
+            String consensusSequenceLabel = "Consensus sequence";\r
+\r
+            JPhyloIOEventWriter writer = factory.getWriter(formatID);\r
+\r
+            ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter();\r
+            document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, consensusSequenceLabel));\r
+\r
+            try {\r
+                writer.writeDocument(document, targetFile, parameters);\r
+            }\r
+            catch (IOException e) {\r
+                e.printStackTrace();\r
+                MessagingUtils.errorDialog("IO error", this,\r
+                        "An error occured when trying to export a consensus sequence alignment to the file \"" +\r
+                        targetFile.getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID\r
+                        //TODO Use multi language error message.\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+}\r
index f4c658084b6e9f38b80ac456b5a5565bfa3e4036..c4eb1c33c2f578d55eb063bee13e1080a465ce62 100644 (file)
@@ -27,7 +27,6 @@ import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
  * Displays an undistorted pherogram with {@link PherogramViewPart}.
  *
  * @author Ben Stöver
- *
  */
 public class ShowPherogramHandler extends AbstractHandler {
        public static void showPherogram(PherogramComponentModel model) throws PartInitException {
diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/CDMSequenceMatrixAdapter.java
new file mode 100644 (file)
index 0000000..e3ab7f6
--- /dev/null
@@ -0,0 +1,160 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.molecular.io;\r
+\r
+\r
+import info.bioinfweb.commons.text.StringUtils;\r
+import info.bioinfweb.jphyloio.ReadWriteConstants;\r
+import info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver;\r
+import info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter;\r
+import info.bioinfweb.jphyloio.dataadapters.implementations.NoSetsMatrixDataAdapter;\r
+import info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent;\r
+import info.bioinfweb.jphyloio.events.SequenceTokensEvent;\r
+import info.bioinfweb.jphyloio.events.type.EventContentType;\r
+\r
+import java.io.IOException;\r
+import java.util.Iterator;\r
+\r
+import eu.etaxonomy.cdm.model.molecular.Sequence;\r
+\r
+\r
+\r
+/**\r
+ * In implementation of {@link MatrixDataAdapter} that delegates to a {@link Sequence} object.\r
+ *\r
+ * @author Ben Stöver\r
+ * @date 29.04.2016\r
+ */\r
+public class CDMSequenceMatrixAdapter extends NoSetsMatrixDataAdapter implements ReadWriteConstants {\r
+    public static final String MATRIX_ID = DEFAULT_MATRIX_ID_PREFIX + "ContigAlignment";\r
+    public static final String SINGLE_READ_SEQUENCE_ID_PREFIX = DEFAULT_SEQUENCE_ID_PREFIX + "SingleRead";\r
+    public static final String CONSENSUS_SEQUENCE_ID= DEFAULT_SEQUENCE_ID_PREFIX + "Consensus";\r
+\r
+\r
+    private Sequence sequence;\r
+    private String consensusSequenceLabel;\r
+    //TODO Also allow specifying single read labels?\r
+\r
+\r
+    /**\r
+     * Creates a new instance of this class.\r
+     *\r
+     * @param sequence\r
+     * @param consensusSequenceLabel\r
+     */\r
+    public CDMSequenceMatrixAdapter(Sequence sequence, String consensusSequenceLabel) {\r
+        super();\r
+        this.sequence = sequence;\r
+        this.consensusSequenceLabel = consensusSequenceLabel;\r
+    }\r
+\r
+\r
+    /**\r
+     * @return the sequence\r
+     */\r
+    public Sequence getCDMSequence() {\r
+        return sequence;\r
+    }\r
+\r
+\r
+    private int extractSingleReadIndexFromID(String sequenceID) {\r
+        try {\r
+            return Integer.parseInt(sequenceID.substring(SINGLE_READ_SEQUENCE_ID_PREFIX.length()));\r
+        }\r
+        catch (NumberFormatException e) {\r
+            return -1;\r
+        }\r
+    }\r
+\r
+\r
+    @Override\r
+    public LinkedLabeledIDEvent getStartEvent() {\r
+        return new LinkedLabeledIDEvent(EventContentType.ALIGNMENT, MATRIX_ID, "Contig alignment", null);\r
+                //TODO Use label according to derivate and markers.\r
+    }\r
+\r
+\r
+    @Override\r
+    public boolean containsLongTokens() {\r
+        return false;\r
+    }\r
+\r
+\r
+    @Override\r
+    public long getColumnCount() {\r
+        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.\r
+    }\r
+\r
+\r
+    @Override\r
+    public long getSequenceCount() {\r
+        return /*sequence.getSingleReadAlignments().size() +*/ 1;\r
+    }\r
+\r
+\r
+    @Override\r
+    public Iterator<String> getSequenceIDIterator() {\r
+        return new SequenceIDIterator(getCDMSequence().getSingleReadAlignments().size());\r
+    }\r
+\r
+\r
+    @Override\r
+    public long getSequenceLength(String sequenceID) throws IllegalArgumentException {\r
+        int singleReadIndex = extractSingleReadIndexFromID(sequenceID);\r
+        if (singleReadIndex >= 0) {\r
+            //TODO Determine single read length. (Current problem: Reads are not ordered in the set of the Sequence object.)\r
+            return 0;\r
+        }\r
+        else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {\r
+            return getCDMSequence().getSequenceString().length();\r
+        }\r
+        else {\r
+            throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found.");\r
+        }\r
+    }\r
+\r
+\r
+    @Override\r
+    public LinkedLabeledIDEvent getSequenceStartEvent(String sequenceID) {\r
+        int singleReadIndex = extractSingleReadIndexFromID(sequenceID);\r
+        if (singleReadIndex >= 0) {\r
+            return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, "singleRead" + singleReadIndex, null);\r
+                    //TODO Use name displayed in derivate hierarchy or specified name as label instead?\r
+        }\r
+        else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {\r
+            return new LinkedLabeledIDEvent(EventContentType.SEQUENCE, sequenceID, consensusSequenceLabel, null);\r
+        }\r
+        else {\r
+            throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found.");\r
+        }\r
+    }\r
+\r
+\r
+    @Override\r
+    public void writeSequencePartContentData(JPhyloIOEventReceiver receiver, String sequenceID, long startColumn,\r
+            long endColumn) throws IOException, IllegalArgumentException {\r
+\r
+        int singleReadIndex = extractSingleReadIndexFromID(sequenceID);\r
+        if (singleReadIndex >= 0) {\r
+            //TODO Implement single read output.\r
+        }\r
+        else if (CONSENSUS_SEQUENCE_ID.equals(sequenceID)) {\r
+            if (startColumn == 0) {\r
+                //TODO Add consensus sequence metadata.\r
+                //TODO Possibly export additional properties of sequence (e.g. isBarcode(), getDdbjId(), ...) as metadata.\r
+            }\r
+            receiver.add(new SequenceTokensEvent(StringUtils.charSequenceToStringList(\r
+                    getCDMSequence().getSequenceString().substring((int)startColumn, (int)endColumn))));\r
+        }\r
+        else {\r
+            throw new IllegalArgumentException("No sequence with the ID \"" + sequenceID + "\" could be found.");\r
+        }\r
+    }\r
+}\r
diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/SequenceIDIterator.java
new file mode 100644 (file)
index 0000000..75e750b
--- /dev/null
@@ -0,0 +1,65 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.taxeditor.molecular.io;\r
+\r
+import java.util.Iterator;\r
+import java.util.NoSuchElementException;\r
+\r
+\r
+\r
+/**\r
+ * Iterator implementation used internally be {@link CDMSequenceMatrixAdapter}.\r
+ *\r
+ * @author Ben Stöver\r
+ * @date 29.04.2016\r
+ */\r
+public class SequenceIDIterator implements Iterator<String> {\r
+    private int singleReadPos;\r
+    private int singleReadCount;\r
+\r
+\r
+    /**\r
+     * Creates a new instance of this class.\r
+     *\r
+     * @param singleReadCount the number of single read IDs to be returned by this iterator before the consensus sequence\r
+     */\r
+    public SequenceIDIterator(int singleReadCount) {\r
+        super();\r
+        this.singleReadCount = singleReadCount;\r
+        this.singleReadPos = 0;\r
+    }\r
+\r
+\r
+    @Override\r
+    public boolean hasNext() {\r
+        return singleReadPos <= singleReadCount;\r
+    }\r
+\r
+\r
+    @Override\r
+    public String next() {\r
+        if (singleReadPos < singleReadCount) {\r
+            return CDMSequenceMatrixAdapter.SINGLE_READ_SEQUENCE_ID_PREFIX + (singleReadPos++);\r
+        }\r
+        else if (singleReadPos == singleReadCount) {\r
+            singleReadPos++;\r
+            return CDMSequenceMatrixAdapter.CONSENSUS_SEQUENCE_ID;\r
+        }\r
+        else {\r
+            throw new NoSuchElementException("There are no more sequence IDs availble from this iterator.");\r
+        }\r
+    }\r
+\r
+\r
+    @Override\r
+    public void remove() {\r
+        throw new UnsupportedOperationException("This iterator does not support removing elements.");\r
+    }\r
+}\r