2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.workers;
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.scoremodels.ScoreModels;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.datamodel.AlignedCodonFrame;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.SequenceI;
33 import jalview.util.MappingUtils;
35 import java.util.ArrayList;
36 import java.util.ConcurrentModificationException;
37 import java.util.Hashtable;
38 import java.util.List;
41 * A thread to compute the columnwise correspondence between aligned positions
42 * and their positions in a linked alignment
47 public class AlignmentComparisonThread extends AlignCalcWorker
50 public AlignmentComparisonThread(AlignViewportI alignViewport,
51 AlignmentViewPanel alignPanel)
53 super(alignViewport, alignPanel);
56 Annotation[] correspondence = new Annotation[] {};
57 AlignmentAnnotation comparisonAnnot=null;
65 calcMan.notifyStart(this); // updatingConservation = true;
67 while ((calcMan != null) && (!calcMan.notifyWorking(this)))
73 // ap.paintAlignment(false);
76 } catch (Exception ex)
81 if ((alignViewport == null) || (calcMan == null)
82 || (alignViewport.isClosed()))
87 List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
89 AlignmentI alignment = alignViewport.getAlignment();
90 AlignViewportI codingComplement = alignViewport.getCodingComplement();
91 if (alignment == null || (alWidth = alignment.getWidth()) < 0
92 || (codingComplement == null))
94 calcMan.workerComplete(this);
95 // .updatingConservation = false;
96 // AlignViewport.UPDATING_CONSERVATION = false;
100 comparisonAnnot = alignViewport.getAlignment().findOrCreateAnnotation("Comparison", "CORRESPONDENCE", true, null, null);
101 comparisonAnnot.annotations=correspondence;
102 ourAnnot.add(comparisonAnnot);
103 ourAnnots = ourAnnot;
107 computeColumnCorrespondence(alignViewport, codingComplement);
108 } catch (IndexOutOfBoundsException x)
110 // probable race condition. just finish and return without any fuss.
111 calcMan.workerComplete(this);
114 updateResultAnnotation(true);
115 } catch (OutOfMemoryError error)
117 ap.raiseOOMWarning("calculating conservation", error);
118 calcMan.disableWorker(this);
119 // alignViewport.conservation = null;
120 // this.alignViewport.quality = null;
123 calcMan.workerComplete(this);
125 if ((alignViewport == null) || (calcMan == null)
126 || (alignViewport.isClosed()))
133 ap.paintAlignment(true, true);
138 private void computeColumnCorrespondence(AlignViewportI alignViewport,
139 AlignViewportI codingComplement)
141 List<SequenceI> us = alignViewport.getAlignment().getSequences();
142 List<AlignedCodonFrame> ourMappings = alignViewport.getAlignment()
144 List<SequenceI> them = codingComplement.getAlignment().getSequences();
145 List<AlignedCodonFrame> theirMappings = codingComplement.getAlignment()
147 if (us == null || them == null || us.isEmpty() || them.isEmpty())
152 int colEnd = alignViewport.getAlignment().getWidth();
153 Annotation[] colCorrsp = new Annotation[colEnd];
154 for (int col = 0; col < colEnd; col++)
156 int[] theirWidth = MappingUtils.findMappedColumns(col, ourMappings,
157 us, them, alignViewport.getGapCharacter());
158 colCorrsp[col] = new Annotation(
159 theirWidth != null ? Math.abs(theirWidth[1] - theirWidth[0])
162 correspondence=colCorrsp;
165 private void updateResultAnnotation(boolean b)
167 if (b || !calcMan.isWorking(this) && correspondence!=null)
169 comparisonAnnot.annotations = correspondence;
170 comparisonAnnot.validateRangeAndDisplay();
175 public void updateAnnotation()
177 updateResultAnnotation(false);