2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
12 import info
.bioinfweb
.libralign
.AlignmentArea
;
13 import info
.bioinfweb
.libralign
.AlignmentContentArea
;
14 import info
.bioinfweb
.libralign
.dataarea
.implementations
.pherogram
.PherogramArea
;
15 import info
.bioinfweb
.libralign
.pherogram
.BioJavaPherogramProvider
;
16 import info
.bioinfweb
.libralign
.sequenceprovider
.SequenceDataProvider
;
19 import java
.io
.IOException
;
21 import org
.biojava
.bio
.chromatogram
.ChromatogramFactory
;
22 import org
.biojava
.bio
.chromatogram
.UnsupportedChromatogramFormatException
;
23 import org
.eclipse
.core
.commands
.AbstractHandler
;
24 import org
.eclipse
.core
.commands
.ExecutionEvent
;
25 import org
.eclipse
.core
.commands
.ExecutionException
;
26 import org
.eclipse
.swt
.widgets
.FileDialog
;
27 import org
.eclipse
.ui
.IEditorPart
;
29 import eu
.etaxonomy
.taxeditor
.editor
.molecular
.AlignmentEditor
;
30 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
36 * Handler that loads an additional read into the contig alignment displayed by an instance of {@link AlignmentEditor}.
42 public class LoadPherogramHandler
extends AbstractHandler
{
43 public static final String DEFAULT_READ_NAME_PREFIX
= "Read ";
46 private String
newReadName(SequenceDataProvider provider
) {
48 while (provider
.sequenceIDByName(DEFAULT_READ_NAME_PREFIX
+ index
) != SequenceDataProvider
.NO_SEQUENCE_FOUND
) {
51 return DEFAULT_READ_NAME_PREFIX
+ index
;
55 private void addPherogram(AlignmentContentArea contentArea
, File pherogram
)
56 throws IOException
, UnsupportedChromatogramFormatException
{
58 SequenceDataProvider provider
= contentArea
.getSequenceProvider();
59 BioJavaPherogramProvider pherogramProvider
= new BioJavaPherogramProvider(ChromatogramFactory
.create(pherogram
)); // Must happen before a sequence is added, because it might throw an exception.
60 String name
= newReadName(provider
);
63 provider
.addSequence(name
);
64 int id
= provider
.sequenceIDByName(name
);
66 // Copy base call sequence into alignment:
67 for (int i
= 0; i
< pherogramProvider
.getSequenceLength(); i
++) {
68 provider
.insertTokenAt(id
, i
, provider
.getTokenSet().tokenByKeyChar(
69 pherogramProvider
.getBaseCall(i
).getUpperedBase().charAt(0)));
73 PherogramArea pherogramArea
= new PherogramArea(contentArea
, pherogramProvider
);
74 contentArea
.getDataAreas().getSequenceAreas(id
).add(pherogramArea
);
79 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
82 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
83 IEditorPart activeEditor
= AbstractUtility
.getActiveEditor();
84 if (activeEditor
instanceof AlignmentEditor
) {
85 AlignmentEditor alignmentEditor
= (AlignmentEditor
)activeEditor
;
87 FileDialog fileDialog
= new FileDialog(alignmentEditor
.getSite().getShell());
88 fileDialog
.setText("Import pherogram into contig alignment");
89 fileDialog
.setFilterNames(new String
[]{"All supported formats", "AB1 pherogram files", "SCF pherogram files", "All files"});
90 fileDialog
.setFilterExtensions(new String
[]{"*.ab1;*.scf", "*.ab1", "*.scf", "*.*"});
92 String path
= fileDialog
.open();
95 addPherogram(alignmentEditor
.getReadsArea().getContentArea(), new File(path
));
97 catch (UnsupportedChromatogramFormatException e
) {
98 MessagingUtils
.errorDialog("Unsupported format", this, "The format of the pherogram file \"" + path
+
99 "\" is not supported. (Only AB1 and SCF are supported.)", "eu.etaxonomy.taxeditor.editor", e
, false); //TODO set pluginID
101 catch (IOException e
) {
102 MessagingUtils
.errorDialog("Unsupported format", this,
103 "An IO error occurred while trying to read the file \"" + path
+ "\".",
104 "/eu.etaxonomy.taxeditor.editor", e
, false); //TODO set pluginID