b4863284ce34de651ea0cb65cf03f4f997bb91af
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / molecular / AlignmentEditor.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 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.editor.molecular;
11
12
13 import info.bioinfweb.commons.bio.biojava3.alignment.SimpleAlignment;
14 import info.bioinfweb.commons.bio.biojava3.alignment.template.Alignment;
15 import info.bioinfweb.commons.bio.biojava3.core.sequence.compound.AlignmentAmbiguityNucleotideCompoundSet;
16 import info.bioinfweb.libralign.AlignmentArea;
17 import info.bioinfweb.libralign.AlignmentContentArea;
18 import info.bioinfweb.libralign.dataarea.implementations.ConsensusSequenceArea;
19 import info.bioinfweb.libralign.dataarea.implementations.SequenceIndexArea;
20 import info.bioinfweb.libralign.dataarea.implementations.pherogram.PherogramArea;
21 import info.bioinfweb.libralign.pherogram.BioJavaPherogramProvider;
22 import info.bioinfweb.libralign.pherogram.PherogramProvider;
23 import info.bioinfweb.libralign.pherogram.ReverseComplementPherogramProvider;
24 import info.bioinfweb.libralign.sequenceprovider.SequenceDataProvider;
25 import info.bioinfweb.libralign.sequenceprovider.implementations.BioJavaSequenceDataProvider;
26 import info.bioinfweb.libralign.sequenceprovider.implementations.PackedSequenceDataProvider;
27 import info.bioinfweb.libralign.sequenceprovider.tokenset.BioJavaTokenSet;
28 import info.bioinfweb.libralign.sequenceprovider.tokenset.TokenSet;
29
30 import java.io.File;
31
32 import org.biojava.bio.chromatogram.ChromatogramFactory;
33 import org.biojava3.core.sequence.DNASequence;
34 import org.biojava3.core.sequence.compound.DNACompoundSet;
35 import org.biojava3.core.sequence.compound.NucleotideCompound;
36 import org.eclipse.core.runtime.IProgressMonitor;
37 import org.eclipse.swt.SWT;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.ui.IEditorInput;
40 import org.eclipse.ui.IEditorSite;
41 import org.eclipse.ui.PartInitException;
42 import org.eclipse.ui.part.EditorPart;
43
44
45
46 /**
47 * Editor component to edit a contig alignment used to combine different overlapping pherograms from Sanger sequencing to
48 * a consensus sequence.
49 * <p>
50 * The contained GUI components used to edit the alignment come from <a href="http://bioinfweb.info/LibrAlign/">LibrAlign</a>.
51 *
52 * @author Ben Stöver
53 * @author pplitzner
54 * @date 04.08.2014
55 */
56 public class AlignmentEditor extends EditorPart {
57 public static final String ID = "eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditor";
58
59 private AlignmentArea alignmentArea;
60
61
62 private AlignmentArea createAlignmentArea() {
63 try {
64 AlignmentArea result = new AlignmentArea();
65 AlignmentContentArea contentArea = result.getContentArea();
66
67 TokenSet<NucleotideCompound> tokenSet = new BioJavaTokenSet<NucleotideCompound>(new DNACompoundSet(), true);
68 SequenceDataProvider<NucleotideCompound> provider = new PackedSequenceDataProvider<NucleotideCompound>(tokenSet);
69
70 // Add index area:
71 contentArea.getDataAreas().getTopAreas().add(new SequenceIndexArea(contentArea));
72
73
74 // First test sequence with pherogram:
75 provider.addSequence("Read 1");
76 int id = provider.sequenceIDByName("Read 1");
77 BioJavaPherogramProvider pherogramProvider = new BioJavaPherogramProvider(ChromatogramFactory.create(
78 new File("D:/Users/BenStoever/Documents/Studium/Projekte/Promotion/EDITor/Quelltexte/LibrAlign branch/Repository/eu.etaxonomy.taxeditor.editor/src/main/resources/AlignmentTestData/JR430_JR-P01.ab1")));
79 //new File("/home/pplitzner/svn/LibrAlign/taxeditor/eu.etaxonomy.taxeditor.editor/src/main/resources/AlignmentTestData/JR430_JR-P01.ab1")));
80
81 // Copy base call sequence into alignment:
82 for (int i = 0; i < pherogramProvider.getSequenceLength(); i++) {
83 provider.insertTokenAt(id, i, tokenSet.tokenByKeyChar(pherogramProvider.getBaseCall(i).getUpperedBase().charAt(0)));
84 }
85
86 // Add data area:
87 PherogramArea pherogramArea = new PherogramArea(result.getContentArea(), pherogramProvider);
88 result.getContentArea().getDataAreas().getSequenceAreas(id).add(pherogramArea);
89
90
91 // Second test sequence with pherogram:
92 provider.addSequence("Read 2");
93 id = provider.sequenceIDByName("Read 2");
94 pherogramProvider = new BioJavaPherogramProvider(ChromatogramFactory.create(
95 new File("D:/Users/BenStoever/Documents/Studium/Projekte/Promotion/EDITor/Quelltexte/LibrAlign branch/Repository/eu.etaxonomy.taxeditor.editor/src/main/resources/AlignmentTestData/JR444_JR-P05.ab1")));
96 //new File("/home/pplitzner/svn/LibrAlign/taxeditor/eu.etaxonomy.taxeditor.editor/src/main/resources/AlignmentTestData/JR444_JR-P05.ab1")));
97 // Copy base call sequence into alignment:
98 for (int i = 0; i < pherogramProvider.getSequenceLength(); i++) {
99 provider.insertTokenAt(id, i, tokenSet.tokenByKeyChar(pherogramProvider.getBaseCall(i).getUpperedBase().charAt(0)));
100 }
101
102 // Add data area:
103 pherogramArea = new PherogramArea(result.getContentArea(), pherogramProvider);
104 result.getContentArea().getDataAreas().getSequenceAreas(id).add(pherogramArea);
105
106
107 contentArea.setSequenceProvider(provider, false);
108
109 return result;
110 }
111 catch (Exception e) {
112 throw new RuntimeException(e);
113 }
114 }
115
116
117 /* (non-Javadoc)
118 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
119 */
120 @Override
121 public void createPartControl(Composite parent) {
122 alignmentArea = createAlignmentArea();
123 Composite alignmentWidget = alignmentArea.createSWTWidget(parent, SWT.NONE);
124 //getSite().setSelectionProvider(provider)
125 }
126
127
128 /* (non-Javadoc)
129 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
130 */
131 @Override
132 public void doSave(IProgressMonitor monitor) {
133 // TODO Auto-generated method stub
134
135 }
136
137
138 /* (non-Javadoc)
139 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
140 */
141 @Override
142 public void doSaveAs() {
143 // TODO Auto-generated method stub
144
145 }
146
147
148 /* (non-Javadoc)
149 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
150 */
151 @Override
152 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
153 setSite(site);
154 setInput(input);
155 }
156
157
158 /* (non-Javadoc)
159 * @see org.eclipse.ui.part.EditorPart#isDirty()
160 */
161 @Override
162 public boolean isDirty() {
163 // TODO Auto-generated method stub
164 return false;
165 }
166
167
168 /* (non-Javadoc)
169 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
170 */
171 @Override
172 public boolean isSaveAsAllowed() {
173 // TODO Auto-generated method stub
174 return false;
175 }
176
177
178 /* (non-Javadoc)
179 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
180 */
181 @Override
182 public void setFocus() {
183 //alignmentArea.getToolkitComponent().redistributeHeight();
184 }
185 }