From: b.stoever Date: Mon, 27 Oct 2014 15:33:59 +0000 (+0000) Subject: Basic implementation for LoadPherogramHandler added. (Imported data is currently... X-Git-Tag: 3.8.0^2~59^2~107 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/79ef938c5180a070265be8e76d3f2e1cd19b4307 Basic implementation for LoadPherogramHandler added. (Imported data is currently not displayed due to currently unimplemented support for adding sequences and data areas during runtime in LibrAlign.) --- diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/LoadPherogramHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/LoadPherogramHandler.java index 2ffa2ca70..61addf4e5 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/LoadPherogramHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/LoadPherogramHandler.java @@ -9,6 +9,17 @@ package eu.etaxonomy.taxeditor.editor.handler; +import info.bioinfweb.libralign.AlignmentArea; +import info.bioinfweb.libralign.AlignmentContentArea; +import info.bioinfweb.libralign.dataarea.implementations.pherogram.PherogramArea; +import info.bioinfweb.libralign.pherogram.BioJavaPherogramProvider; +import info.bioinfweb.libralign.sequenceprovider.SequenceDataProvider; + +import java.io.File; +import java.io.IOException; + +import org.biojava.bio.chromatogram.ChromatogramFactory; +import org.biojava.bio.chromatogram.UnsupportedChromatogramFormatException; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -17,6 +28,7 @@ import org.eclipse.ui.IEditorPart; import eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor; import eu.etaxonomy.taxeditor.model.AbstractUtility; +import eu.etaxonomy.taxeditor.model.MessagingUtils; @@ -27,19 +39,71 @@ import eu.etaxonomy.taxeditor.model.AbstractUtility; * @author pplitzner * @date 16.10.2014 */ -public class LoadPherogramHandler extends AbstractHandler{ +public class LoadPherogramHandler extends AbstractHandler { + public static final String DEFAULT_READ_NAME_PREFIX = "Read "; + + + private String newReadName(SequenceDataProvider provider) { + int index = 1; + while (provider.sequenceIDByName(DEFAULT_READ_NAME_PREFIX + index) != SequenceDataProvider.NO_SEQUENCE_FOUND) { + index++; + } + return DEFAULT_READ_NAME_PREFIX + index; + } + + + private void addPherogram(AlignmentContentArea contentArea, File pherogram) + throws IOException, UnsupportedChromatogramFormatException { + + SequenceDataProvider provider = contentArea.getSequenceProvider(); + BioJavaPherogramProvider pherogramProvider = new BioJavaPherogramProvider(ChromatogramFactory.create(pherogram)); // Must happen before a sequence is added, because it might throw an exception. + String name = newReadName(provider); + + // Create sequence: + provider.addSequence(name); + int id = provider.sequenceIDByName(name); + + // Copy base call sequence into alignment: + for (int i = 0; i < pherogramProvider.getSequenceLength(); i++) { + provider.insertTokenAt(id, i, provider.getTokenSet().tokenByKeyChar( + pherogramProvider.getBaseCall(i).getUpperedBase().charAt(0))); + } + + // Add data area: + PherogramArea pherogramArea = new PherogramArea(contentArea, pherogramProvider); + contentArea.getDataAreas().getSequenceAreas(id).add(pherogramArea); + } + + /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart activeEditor = AbstractUtility.getActiveEditor(); - if(activeEditor instanceof AlignmentEditor){ - AlignmentEditor alignmentEditor = (AlignmentEditor) activeEditor; + if (activeEditor instanceof AlignmentEditor) { + AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor; + FileDialog fileDialog = new FileDialog(alignmentEditor.getSite().getShell()); + fileDialog.setText("Import pherogram into contig alignment"); + fileDialog.setFilterNames(new String[]{"All supported formats", "AB1 pherogram files", "SCF pherogram files", "All files"}); + fileDialog.setFilterExtensions(new String[]{"*.ab1;*.scf", "*.ab1", "*.scf", "*.*"}); + String path = fileDialog.open(); - System.out.println(path); -// alignmentEditor.getAlignmentArea().getSelection() + if (path != null) { + try { + addPherogram(alignmentEditor.getReadsArea().getContentArea(), new File(path)); + } + catch (UnsupportedChromatogramFormatException e) { + MessagingUtils.errorDialog("Unsupported format", this, "The format of the pherogram file \"" + path + + "\" is not supported. (Only AB1 and SCF are supported.)", "eu.etaxonomy.taxeditor.editor", e, false); //TODO set pluginID + } + catch (IOException e) { + MessagingUtils.errorDialog("Unsupported format", this, + "An IO error occurred while trying to read the file \"" + path + "\".", + "/eu.etaxonomy.taxeditor.editor", e, false); //TODO set pluginID + } + } } return null; } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java index b4863284c..3efa522e0 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java @@ -56,10 +56,10 @@ import org.eclipse.ui.part.EditorPart; public class AlignmentEditor extends EditorPart { public static final String ID = "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor"; - private AlignmentArea alignmentArea; + private AlignmentArea readsArea; - private AlignmentArea createAlignmentArea() { + private AlignmentArea createReadsArea() { try { AlignmentArea result = new AlignmentArea(); AlignmentContentArea contentArea = result.getContentArea(); @@ -114,13 +114,18 @@ public class AlignmentEditor extends EditorPart { } - /* (non-Javadoc) + public AlignmentArea getReadsArea() { + return readsArea; + } + + + /* (non-Javadoc) * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ @Override public void createPartControl(Composite parent) { - alignmentArea = createAlignmentArea(); - Composite alignmentWidget = alignmentArea.createSWTWidget(parent, SWT.NONE); + readsArea = createReadsArea(); + Composite alignmentWidget = readsArea.createSWTWidget(parent, SWT.NONE); //getSite().setSelectionProvider(provider) }