Adjustments to recent changes in LibrAlign.
authorb.stoever <b.stoever@localhost>
Thu, 21 May 2015 16:45:28 +0000 (16:45 +0000)
committerb.stoever <b.stoever@localhost>
Thu, 21 May 2015 16:45:28 +0000 (16:45 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/AlignmentEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/molecular/ContigSequenceDataProvider.java

index 796e3d171d67aa58cd7ff52dd14e78d133febde6..67ce107f535bdf384700b6c430d794f3e34e68f4 100644 (file)
@@ -19,21 +19,21 @@ import info.bioinfweb.libralign.dataarea.implementations.pherogram.PherogramArea
 import info.bioinfweb.libralign.dataarea.implementations.pherogram.ShiftChange;
 import info.bioinfweb.libralign.editsettings.EditSettingsChangeEvent;
 import info.bioinfweb.libralign.editsettings.EditSettingsListener;
+import info.bioinfweb.libralign.model.AlignmentModel;
+import info.bioinfweb.libralign.model.AlignmentModelChangeListener;
+import info.bioinfweb.libralign.model.SequenceUtils;
+import info.bioinfweb.libralign.model.adapters.StringAdapter;
+import info.bioinfweb.libralign.model.events.SequenceChangeEvent;
+import info.bioinfweb.libralign.model.events.SequenceRenamedEvent;
+import info.bioinfweb.libralign.model.events.TokenChangeEvent;
+import info.bioinfweb.libralign.model.implementations.PackedAlignmentModel;
+import info.bioinfweb.libralign.model.tokenset.BioJavaTokenSet;
+import info.bioinfweb.libralign.model.tokenset.TokenSet;
 import info.bioinfweb.libralign.multiplealignments.AlignmentAreaList;
 import info.bioinfweb.libralign.multiplealignments.MultipleAlignmentsContainer;
-import info.bioinfweb.libralign.pherogram.provider.BioJavaPherogramProvider;
-import info.bioinfweb.libralign.pherogram.provider.PherogramProvider;
-import info.bioinfweb.libralign.pherogram.provider.ReverseComplementPherogramProvider;
-import info.bioinfweb.libralign.sequenceprovider.SequenceDataChangeListener;
-import info.bioinfweb.libralign.sequenceprovider.SequenceDataProvider;
-import info.bioinfweb.libralign.sequenceprovider.SequenceUtils;
-import info.bioinfweb.libralign.sequenceprovider.adapters.StringAdapter;
-import info.bioinfweb.libralign.sequenceprovider.events.SequenceChangeEvent;
-import info.bioinfweb.libralign.sequenceprovider.events.SequenceRenamedEvent;
-import info.bioinfweb.libralign.sequenceprovider.events.TokenChangeEvent;
-import info.bioinfweb.libralign.sequenceprovider.implementations.PackedSequenceDataProvider;
-import info.bioinfweb.libralign.sequenceprovider.tokenset.BioJavaTokenSet;
-import info.bioinfweb.libralign.sequenceprovider.tokenset.TokenSet;
+import info.bioinfweb.libralign.pherogram.model.BioJavaPherogramModel;
+import info.bioinfweb.libralign.pherogram.model.PherogramModel;
+import info.bioinfweb.libralign.pherogram.model.ReverseComplementPherogramModel;
 
 import java.io.File;
 import java.io.IOException;
@@ -97,7 +97,7 @@ public class AlignmentEditor extends EditorPart {
 
     private final ConversationHolder conversationHolder;
 
-       private final SequenceDataChangeListener DIRTY_LISTENER = new SequenceDataChangeListener() {
+       private final AlignmentModelChangeListener DIRTY_LISTENER = new AlignmentModelChangeListener() {
                                @Override
                                public <T> void afterTokenChange(TokenChangeEvent<T> e) {
                                        setDirty();
@@ -114,8 +114,8 @@ public class AlignmentEditor extends EditorPart {
                                }
 
                                @Override
-                               public <T, U> void afterProviderChanged(SequenceDataProvider<T> oldProvider,
-                                               SequenceDataProvider<U> newProvider) {  // Not expected.
+                               public <T, U> void afterProviderChanged(AlignmentModel<T> oldProvider,
+                                               AlignmentModel<U> newProvider) {  // Not expected.
 
                                        setDirty();
                                }
@@ -128,7 +128,8 @@ public class AlignmentEditor extends EditorPart {
 
     public AlignmentEditor() {
        super();
-       conversationHolder = CdmStore.createConversation();
+       //conversationHolder = CdmStore.createConversation();
+       conversationHolder = null;
     }
 
 
@@ -174,8 +175,8 @@ public class AlignmentEditor extends EditorPart {
                result.setAllowVerticalScrolling(allowVerticalScrolling);
 
                TokenSet<NucleotideCompound> tokenSet = new BioJavaTokenSet<NucleotideCompound>(new DNACompoundSet(), true);
-               SequenceDataProvider<NucleotideCompound> provider = new PackedSequenceDataProvider<NucleotideCompound>(tokenSet);
-               result.setSequenceProvider(provider, false);
+               AlignmentModel<NucleotideCompound> provider = new PackedAlignmentModel<NucleotideCompound>(tokenSet);
+               result.setAlignmentModel(provider, false);
                provider.getChangeListeners().add(DIRTY_LISTENER);
 
                return result;
@@ -183,7 +184,7 @@ public class AlignmentEditor extends EditorPart {
 
 
     private AlignmentArea createConsensusHintArea(MultipleAlignmentsContainer container,
-               SequenceDataProvider<?> sequenceProvider) {
+               AlignmentModel<?> sequenceProvider) {
 
                AlignmentArea result = new AlignmentArea(container);
                result.setAllowVerticalScrolling(false);
@@ -203,7 +204,7 @@ public class AlignmentEditor extends EditorPart {
                list.add(readsArea);  // Make sure READS_AREA_INDEX is correct.
                list.add(createEditableAlignmentArea(alignmentsContainer, false));  // Make sure COMSENSUS_AREA_INDEX is correct.
                list.add(createConsensusHintArea(alignmentsContainer,
-                               readsArea.getSequenceProvider()));
+                               readsArea.getAlignmentModel()));
 
                registerEditSettingListener(alignmentsContainer);
                }
@@ -233,7 +234,7 @@ public class AlignmentEditor extends EditorPart {
                        addRead(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").toURI(), false);
 
                        // Add test consensus sequence:
-                       SequenceDataProvider consensusProvider = getConsensusArea().getSequenceProvider();
+                       AlignmentModel consensusProvider = getConsensusArea().getAlignmentModel();
                        int id = consensusProvider.addSequence(CONSENSUS_NAME);
                        Collection<Object> tokens = new ArrayList<Object>();  // First save tokens in a collection to avoid GUI updated for each token.
                        tokens.add(consensusProvider.getTokenSet().tokenByKeyChar('A'));
@@ -271,7 +272,7 @@ public class AlignmentEditor extends EditorPart {
                }
 
                // Set consensus sequence:
-               SequenceDataProvider consensusProvider = getConsensusArea().getSequenceProvider();
+               AlignmentModel consensusProvider = getConsensusArea().getAlignmentModel();
                int id = consensusProvider.addSequence(CONSENSUS_NAME);
                consensusProvider.insertTokensAt(id, 0, SequenceUtils.stringToTokenList(
                                sequenceNode.getConsensusSequence().getString(), consensusProvider.getTokenSet()));
@@ -338,12 +339,12 @@ public class AlignmentEditor extends EditorPart {
             monitor.beginTask(taskName, 3);
 
                Sequence sequenceNode = ((AlignmentEditorInput)getEditorInput()).getSequenceNode();
-               StringAdapter stringProvider = new StringAdapter(getConsensusArea().getSequenceProvider(), false);  // Throws an exception if a token has more than one character.
+               StringAdapter stringProvider = new StringAdapter(getConsensusArea().getAlignmentModel(), false);  // Throws an exception if a token has more than one character.
 
                // Write consensus sequence:
                SequenceString consensusSequenceObj = sequenceNode.getConsensusSequence();
                String newConsensusSequence = stringProvider.getSequence(
-                               getConsensusArea().getSequenceProvider().sequenceIDByName(CONSENSUS_NAME));
+                               getConsensusArea().getAlignmentModel().sequenceIDByName(CONSENSUS_NAME));
                if (consensusSequenceObj == null) {
                        sequenceNode.setConsensusSequence(SequenceString.NewInstance(newConsensusSequence));
                }
@@ -352,9 +353,9 @@ public class AlignmentEditor extends EditorPart {
                }
 
                // Write single reads:
-               stringProvider.setUnderlyingProvider(getReadsArea().getSequenceProvider());
+               stringProvider.setUnderlyingProvider(getReadsArea().getAlignmentModel());
                sequenceNode.getSingleReadAlignments().retainAll(cdmMap.values());  // Remove all reads that are not in the alignment anymore.
-               Iterator<Integer> iterator = getReadsArea().getSequenceProvider().sequenceIDIterator();
+               Iterator<Integer> iterator = getReadsArea().getAlignmentModel().sequenceIDIterator();
                while (iterator.hasNext()) {
                        int id = iterator.next();
                        SingleReadAlignment singleRead = cdmMap.get(id);
@@ -364,7 +365,7 @@ public class AlignmentEditor extends EditorPart {
                        }
 
                        singleRead.setEditedSequence(stringProvider.getSequence(id));
-                       singleRead.setReverseComplement(getPherogramArea(id).getProvider() instanceof ReverseComplementPherogramProvider);  // Works only if ReverseComplementPherogramProvider instances are not nested.
+                       singleRead.setReverseComplement(getPherogramArea(id).getProvider() instanceof ReverseComplementPherogramModel);  // Works only if ReverseComplementPherogramProvider instances are not nested.
                        singleRead.setShifts(convertToCDMShifts(getPherogramArea(id).getAlignmentModel()));
                }
 
@@ -459,12 +460,12 @@ public class AlignmentEditor extends EditorPart {
 
     public void reverseComplementSelection() {
        SelectionModel selection = getReadsArea().getSelection();
-       SequenceDataProvider<?> provider = getReadsArea().getSequenceProvider();
+       AlignmentModel<?> provider = getReadsArea().getAlignmentModel();
        for (int row = selection.getStartRow(); row < selection.getStartRow() + selection.getCursorHeight(); row++) {
                        int sequenceID = getReadsArea().getSequenceOrder().idByIndex(row);
                        //TODO rc edited sequence
 
-                       if (getPherogramArea(sequenceID).getProvider() instanceof ReverseComplementPherogramProvider) {
+                       if (getPherogramArea(sequenceID).getProvider() instanceof ReverseComplementPherogramModel) {
                                //getPherogramArea(sequenceID).
                                //TODO Allow to set new provider in PherogramArea or create new PherogramArea
                                //TODO Reposition pherogram according to previous position in edited sequence and length
@@ -473,11 +474,11 @@ public class AlignmentEditor extends EditorPart {
     }
 
 
-       public static PherogramProvider readPherogram(URI uri) throws IOException, UnsupportedChromatogramFormatException {
-               PherogramProvider result;
+       public static PherogramModel readPherogram(URI uri) throws IOException, UnsupportedChromatogramFormatException {
+               PherogramModel result;
                InputStream stream = uri.toURL().openStream();
                try {
-                       result = new BioJavaPherogramProvider(ChromatogramFactory.create(stream));
+                       result = new BioJavaPherogramModel(ChromatogramFactory.create(stream));
                }
                finally {
                        stream.close();
@@ -488,8 +489,8 @@ public class AlignmentEditor extends EditorPart {
 
        private String newReadName() {
                int index = 1;
-               while (getReadsArea().getSequenceProvider().sequenceIDByName(DEFAULT_READ_NAME_PREFIX + index)
-                               != SequenceDataProvider.NO_SEQUENCE_FOUND) {
+               while (getReadsArea().getAlignmentModel().sequenceIDByName(DEFAULT_READ_NAME_PREFIX + index)
+                               != AlignmentModel.NO_SEQUENCE_FOUND) {
 
                        index++;
                }
@@ -522,10 +523,10 @@ public class AlignmentEditor extends EditorPart {
     public int addRead(String name, URI pherogramURI, boolean reverseComplemented, String editedSequence,
                SingleReadAlignment.Shift[] shifts) throws IOException, UnsupportedChromatogramFormatException {
 
-               SequenceDataProvider provider = getReadsArea().getSequenceProvider();
-               PherogramProvider pherogramProvider = readPherogram(pherogramURI);  // Must happen before a sequence is added, because it might throw an exception.
+               AlignmentModel provider = getReadsArea().getAlignmentModel();
+               PherogramModel pherogramProvider = readPherogram(pherogramURI);  // Must happen before a sequence is added, because it might throw an exception.
                if (reverseComplemented) {
-                       pherogramProvider = new ReverseComplementPherogramProvider(pherogramProvider);
+                       pherogramProvider = new ReverseComplementPherogramModel(pherogramProvider);
                }
 
         // Create sequence:
index 893b4eebf64cd7d218d54f2ca67670155cb0725a..6b93861b8dd54ed2d246070985509977c3df0ee6 100644 (file)
@@ -13,9 +13,9 @@ package eu.etaxonomy.taxeditor.editor.molecular;
 import org.biojava3.core.sequence.compound.NucleotideCompound;\r
 \r
 import info.bioinfweb.commons.bio.biojava3.core.sequence.compound.AlignmentAmbiguityDNACompoundSet;\r
-import info.bioinfweb.libralign.sequenceprovider.SequenceDataProvider;\r
-import info.bioinfweb.libralign.sequenceprovider.implementations.PackedSequenceDataProvider;\r
-import info.bioinfweb.libralign.sequenceprovider.tokenset.BioJavaTokenSet;\r
+import info.bioinfweb.libralign.model.AlignmentModel;\r
+import info.bioinfweb.libralign.model.implementations.PackedAlignmentModel;\r
+import info.bioinfweb.libralign.model.tokenset.BioJavaTokenSet;\r
 \r
 \r
 \r
@@ -25,8 +25,8 @@ import info.bioinfweb.libralign.sequenceprovider.tokenset.BioJavaTokenSet;
  * @author Ben Stöver\r
  * @date 04.08.2014\r
  */\r
-public class ContigSequenceDataProvider extends PackedSequenceDataProvider<NucleotideCompound> \r
-        implements SequenceDataProvider<NucleotideCompound> {\r
+public class ContigSequenceDataProvider extends PackedAlignmentModel<NucleotideCompound> \r
+        implements AlignmentModel<NucleotideCompound> {\r
 \r
        \r
        public ContigSequenceDataProvider() {\r