import eu.etaxonomy.cdm.model.molecular.SequenceString;
import eu.etaxonomy.cdm.model.molecular.SingleRead;
import eu.etaxonomy.cdm.model.molecular.SingleReadAlignment;
-import eu.etaxonomy.cdm.model.molecular.SingleReadAlignment.Shift;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
import eu.etaxonomy.taxeditor.molecular.handler.ToggleInsertOverwriteHandler;
private MultipleAlignmentsContainer alignmentsContainer = null;
- private final Map<Integer, SingleReadAlignment> cdmMap = new TreeMap<Integer, SingleReadAlignment>(); //TODO Move this to ContigSequenceDataProvider
+ private final Map<String, SingleReadAlignment> cdmMap = new TreeMap<String, SingleReadAlignment>(); //TODO Move this to ContigSequenceDataProvider
private boolean dirty = false;
- public AlignmentEditor()
- {
+
+ public AlignmentEditor() {
super();
conversationHolder = CdmStore.createConversation();
//conversationHolder = null;
result.setAllowVerticalScrolling(allowVerticalScrolling);
CharacterTokenSet tokenSet = CharacterTokenSet.newDNAInstance(); //TODO Should NUCLEOTIDE be used instead?
- AlignmentModel<Character> provider = new PackedAlignmentModel<Character>(tokenSet);
- result.setAlignmentModel(provider, false);
- provider.getChangeListeners().add(DIRTY_LISTENER);
+ AlignmentModel<Character> model = new PackedAlignmentModel<Character>(tokenSet);
+ result.setAlignmentModel(model, false);
+ model.getChangeListeners().add(DIRTY_LISTENER);
result.getPaintSettings().getTokenPainterList().set(0, new NucleotideTokenPainter());
return result;
}
- public boolean hasPherogram(int sequenceID) {
+ public boolean hasPherogram(String sequenceID) {
return getReadsArea().getDataAreas().getSequenceAreas(sequenceID).size() > PHEROGRAM_AREA_INDEX;
}
- public PherogramArea getPherogramArea(int sequenceID) {
+ public PherogramArea getPherogramArea(String sequenceID) {
if (hasPherogram(sequenceID)) {
return (PherogramArea)getReadsArea().getDataAreas().getSequenceAreas(sequenceID).get(PHEROGRAM_AREA_INDEX);
}
// Add test consensus sequence:
AlignmentModel consensusModel = getEditableConsensusArea().getAlignmentModel();
- int id = consensusModel.addSequence(CONSENSUS_NAME);
+ String id = consensusModel.addSequence(CONSENSUS_NAME);
Collection<Object> tokens = new ArrayList<Object>(); // First save tokens in a collection to avoid GUI updated for each token.
tokens.add(consensusModel.getTokenSet().tokenByRepresentation("A"));
tokens.add(consensusModel.getTokenSet().tokenByRepresentation("C"));
for (SingleReadAlignment singleReadAlignment : sequenceNode.getSingleReadAlignments()) {
try {
SingleRead pherogramInfo = singleReadAlignment.getSingleRead();
- URI uri = null;
- if (pherogramInfo.getPherogram() != null) {
- uri = MediaUtils.getFirstMediaRepresentationPart(pherogramInfo.getPherogram()).getUri();
- }
- int id = addRead(DerivateLabelProvider.getDerivateText(pherogramInfo, conversationHolder),
- uri,
+ String id = addRead(DerivateLabelProvider.getDerivateText(pherogramInfo, conversationHolder),
+ getPherogramURI(pherogramInfo),
singleReadAlignment.isReverseComplement(),
singleReadAlignment.getEditedSequence(),
singleReadAlignment.getFirstSeqPosition(),
}
// Set consensus sequence:
- AlignmentModel consensusProvider = getEditableConsensusArea().getAlignmentModel();
- int id = consensusProvider.addSequence(CONSENSUS_NAME);
- consensusProvider.insertTokensAt(id, 0, AlignmentModelUtils.charSequenceToTokenList(
- sequenceNode.getConsensusSequence().getString(), consensusProvider.getTokenSet()));
+ AlignmentModel consensusModel = getEditableConsensusArea().getAlignmentModel();
+ String id = consensusModel.addSequence(CONSENSUS_NAME);
+ consensusModel.insertTokensAt(id, 0, AlignmentModelUtils.charSequenceToTokenList(
+ sequenceNode.getConsensusSequence().getString(), consensusModel.getTokenSet()));
//TODO Can the consensus sequence also be null? / Should it be created here, if nothing is in the DB?
}
bars.getStatusLineManager().setMessage("Edit mode: " +
(getReadsArea().getEditSettings().isInsert() ? "Insert" : "Overwrite") + " " +
"Insertion in pherogram: " +
- (getReadsArea().getEditSettings().isInsertLeftInDataArea() ? "Left" : "Right"));
+ (getReadsArea().getEditSettings().isInsertLeftInDataArea() ? "Left" : "Right")); //TODO multi language
}
private SingleReadAlignment.Shift[] convertToCDMShifts(PherogramAreaModel model) {
Iterator<ShiftChange> iterator = model.shiftChangeIterator();
- List<Shift> shifts = new ArrayList<SingleReadAlignment.Shift>();
+ List<SingleReadAlignment.Shift> shifts = new ArrayList<SingleReadAlignment.Shift>();
while (iterator.hasNext()) {
ShiftChange shiftChange = iterator.next();
shifts.add(new SingleReadAlignment.Shift(shiftChange.getBaseCallIndex(), shiftChange.getShiftChange()));
}
- return shifts.toArray(new Shift[]{});
+ return shifts.toArray(new SingleReadAlignment.Shift[shifts.size()]);
}
@Override
public void doSave(IProgressMonitor monitor) {
if (getEditorInput() instanceof AlignmentEditorInput) {
- String taskName = "Saving alignment";
+ String taskName = "Saving alignment"; //TODO multi language
monitor.beginTask(taskName, 3);
//re-loading sequence to avoid session conflicts
// Write single reads:
stringProvider.setUnderlyingModel(getReadsArea().getAlignmentModel());
sequenceNode.getSingleReadAlignments().retainAll(cdmMap.values()); // Remove all reads that are not in the alignment anymore.
- Iterator<Integer> iterator = getReadsArea().getAlignmentModel().sequenceIDIterator();
+ Iterator<String> iterator = getReadsArea().getAlignmentModel().sequenceIDIterator();
while (iterator.hasNext()) {
- int id = iterator.next();
+ String id = iterator.next();
SingleReadAlignment singleRead = cdmMap.get(id);
if (singleRead == null) {
- throw new InternalError("Creating new reads from AlignmentEditor not implemented.");
+ throw new InternalError("Creating new reads from AlignmentEditor not implemented."); //TODO multi language
//TODO Create new read object. => Shall it be allowed to add reads in the alignment editor which are not represented in the CDM tree before the alignment editor is saved?
//singleRead = SingleReadAlignment.NewInstance(consensusSequence, singleRead, shifts, editedSequence);
}
private String cutPherogram(boolean left) {
SelectionModel selection = getReadsArea().getSelection();
if (selection.getCursorHeight() != 1) {
- return "Cutting pherograms is only possible if exactly one row is selected.";
+ return "Cutting pherograms is only possible if exactly one row is selected."; //TODO multi language
}
else {
PherogramArea pherogramArea =
getPherogramArea(getReadsArea().getSequenceOrder().idByIndex(selection.getCursorRow()));
if (pherogramArea == null) {
- return "There is no pherogram attached to the current sequence.";
+ return "There is no pherogram attached to the current sequence."; //TODO multi language
}
else {
if (left) {
return null;
}
else {
- return "The left end of the selection lies outside the pherogram attached to this sequence.";
+ return "The left end of the selection lies outside the pherogram attached to this sequence."; //TODO multi language
}
}
else {
return null;
}
else {
- return "The right end of the selection lies outside the pherogram attached to this sequence.";
+ return "The right end of the selection lies outside the pherogram attached to this sequence."; //TODO multi language
}
}
}
SelectionModel selection = getReadsArea().getSelection();
AlignmentModel<?> model = getReadsArea().getAlignmentModel();
for (int row = selection.getFirstRow(); row < selection.getFirstRow() + selection.getCursorHeight(); row++) {
- int sequenceID = getReadsArea().getSequenceOrder().idByIndex(row);
+ String sequenceID = getReadsArea().getSequenceOrder().idByIndex(row);
PherogramArea area = getPherogramArea(sequenceID);
PherogramAreaModel pherogramAlignmentModel = area.getModel();
AlignmentModelUtils.reverseComplement(model, sequenceID,
public <T> void createConsensusSequence() {
ConsensusSequenceArea area = getConsensusHintDataArea();
AlignmentModel<T> model = (AlignmentModel<T>)getEditableConsensusArea().getAlignmentModel();
- int sequenceID = model.sequenceIDIterator().next(); // There is always one sequence contained.
+ String sequenceID = model.sequenceIDIterator().next(); // There is always one sequence contained.
int length = getReadsArea().getAlignmentModel().getMaxSequenceLength();
Collection<T> tokens = new ArrayList<T>(length);
ConsensusSequenceArea area = getConsensusHintDataArea();
AlignmentModel<T> model = (AlignmentModel<T>)getEditableConsensusArea().getAlignmentModel();
TokenSet<T> tokenSet = model.getTokenSet();
- int sequenceID = model.sequenceIDIterator().next(); // There is always one sequence contained.
+ String sequenceID = model.sequenceIDIterator().next(); // There is always one sequence contained.
int currentConsensusLength = model.getSequenceLength(sequenceID);
int overallLength = getReadsArea().getAlignmentModel().getMaxSequenceLength();
private String newReadName() {
int index = 1;
- while (getReadsArea().getAlignmentModel().sequenceIDByName(DEFAULT_READ_NAME_PREFIX + index)
- != AlignmentModel.NO_SEQUENCE_FOUND) {
-
+ while (getReadsArea().getAlignmentModel().sequenceIDByName(DEFAULT_READ_NAME_PREFIX + index) != null) {
index++;
}
return DEFAULT_READ_NAME_PREFIX + index;
* @throws IOException if an error occurred when trying to read the pherogram file
* @throws UnsupportedChromatogramFormatException if the format of the pherogram file is not supported
*/
- public int addRead(String name, URI pherogramURI, boolean reverseComplemented, String editedSequence,
+ public String addRead(String name, URI pherogramURI, boolean reverseComplemented, String editedSequence,
Integer firstSeqPos, Integer leftCutPos, Integer rightCutPos, SingleReadAlignment.Shift[] shifts)
throws IOException, UnsupportedChromatogramFormatException {
- AlignmentModel provider = getReadsArea().getAlignmentModel();
+ AlignmentModel model = getReadsArea().getAlignmentModel();
PherogramProvider pherogramProvider = null;
if (pherogramURI != null) {
pherogramProvider = readPherogram(pherogramURI); // Must happen before a sequence is added, because it might throw an exception.
}
// Create sequence:
- provider.addSequence(name);
- int id = provider.sequenceIDByName(name);
+ model.addSequence(name);
+ String id = model.sequenceIDByName(name);
// Set edited sequence:
Collection<Object> tokens = null; // First save tokens in a collection to avoid GUI updated for each token.
if (editedSequence != null) {
- tokens = AlignmentModelUtils.charSequenceToTokenList(editedSequence, provider.getTokenSet());
+ tokens = AlignmentModelUtils.charSequenceToTokenList(editedSequence, model.getTokenSet());
}
else if (pherogramProvider != null) { // Copy base call sequence into alignment:
tokens = new ArrayList<Object>();
for (int i = 0; i < pherogramProvider.getSequenceLength(); i++) {
- tokens.add(provider.getTokenSet().tokenByRepresentation(
+ tokens.add(model.getTokenSet().tokenByRepresentation(
Character.toString(pherogramProvider.getBaseCall(i))));
}
setDirty();
}
if (tokens != null) { // If either an edited sequence or a pherogram URI was provided.
- provider.insertTokensAt(id, 0, tokens);
+ model.insertTokensAt(id, 0, tokens);
if (pherogramProvider != null) {
// Create pherogram area:
new PherogramAreaModel(pherogramProvider));
// Set position properties and shifts:
- PherogramAreaModel model = pherogramArea.getModel();
+ PherogramAreaModel phergramModel = pherogramArea.getModel();
if ((firstSeqPos != null) && (leftCutPos != null)) {
- model.setFirstSeqLeftCutPos(firstSeqPos, leftCutPos);
+ phergramModel.setFirstSeqLeftCutPos(firstSeqPos, leftCutPos);
}
if (rightCutPos != null) {
- model.setRightCutPosition(rightCutPos);
+ phergramModel.setRightCutPosition(rightCutPos);
}
if ((shifts != null) && (shifts.length > 0)) {
for (int i = 0; i < shifts.length; i++) {
- model.addShiftChange(shifts[i].position, shifts[i].shift);
+ phergramModel.addShiftChange(shifts[i].position, shifts[i].shift);
}
setDirty();
}
}
return id;
}
+
+
+ public static URI getPherogramURI(SingleRead pherogramInfo) {
+ if (pherogramInfo.getPherogram() != null) {
+ return MediaUtils.getFirstMediaRepresentationPart(pherogramInfo.getPherogram()).getUri();
+ }
+ else {
+ return null;
+ }
+ }
}