From: MorellThomas Date: Thu, 18 Apr 2024 12:13:43 +0000 (+0200) Subject: Implemented ProgressBar for PaSiMap X-Git-Tag: Release_2_11_4_0~31^2~18^2~1^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e63fbac40aee31b0563c07a349f46d9dad37f46a;p=jalview.git Implemented ProgressBar for PaSiMap --- diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index 8e8d423..c776701 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -23,23 +23,16 @@ package jalview.analysis; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Console; -import jalview.datamodel.AlignmentView; import jalview.datamodel.Point; import jalview.datamodel.SequenceI; import jalview.datamodel.SequenceGroup; import jalview.gui.PairwiseAlignPanel; -import jalview.gui.PaSiMapPanel; import jalview.math.Matrix; import jalview.math.MatrixI; -import jalview.math.MiscMath; import jalview.viewmodel.AlignmentViewport; import java.io.PrintStream; -import java.util.ArrayList; import java.util.Hashtable; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Enumeration; /** * Performs Principal Component Analysis on given sequences @@ -54,8 +47,6 @@ public class PaSiMap implements Runnable final private ScoreModelI scoreModel; - final private SimilarityParamsI similarityParams; - final private byte dim = 3; final private int openCost = 100; @@ -63,16 +54,9 @@ public class PaSiMap implements Runnable final private int extendCost = 5; /* - * other - */ - private long total; // total number of combinations - - private long count; // current iteration number - - /* * outputs */ - private PairwiseAlignPanel alignment; + final private PairwiseAlignPanel alignment; private MatrixI pairwiseScores; @@ -86,15 +70,11 @@ public class PaSiMap implements Runnable * @param sm * @param options */ - public PaSiMap(AlignmentViewport sequences, ScoreModelI sm, - SimilarityParamsI options) + public PaSiMap(AlignmentViewport sequences, ScoreModelI sm, PairwiseAlignPanel pap) { this.seqs = sequences; this.scoreModel = sm; - this.similarityParams = options; - int nseqs = seqs.getAlignment().getHeight(); - this.total = (long) MiscMath.permutations(nseqs, 2) / 2; // n!/(n-r)! - this.count = 0l; + this.alignment = pap; } /** @@ -222,45 +202,13 @@ public class PaSiMap implements Runnable { try { -for (SequenceI see : seqs.getAlignment().getSequencesArray()) -{ -System.out.println(see.getName()); -} - -/* - int nSeqs = seqs.getAlignment().getHeight(); - float[][] scores = new float[nSeqs][nSeqs]; // rows, cols - - int nSplits = 1; - while (((float) nSeqs / nSplits) > 20f) // heap full at 341 - //while (((float) nSeqs / nSplits) > 5f) // heap full at 341 - nSplits++; - int splitSeqs = (int) Math.ceil((float) nSeqs / nSplits); -System.out.println(String.format("%d -> %d splits into %d seqs", nSeqs, nSplits, splitSeqs)); - - int[] splitIndices = new int[nSplits]; - for (int i = 0; i < nSplits; i++) - { - splitIndices[i] = splitSeqs * (i + 1); //exclusive!! - } - - HashMap valuesForScores = splitCombineAndAlign(seqs.getAlignment().getSequencesArray(), splitIndices, splitSeqs); - - for (int[] coords : valuesForScores.keySet()) - { - scores[coords[0]][coords[1]] = valuesForScores.get(coords); - } -pairwiseScores = new Matrix(scores); -pairwiseScores.print(System.out, "%1.4f "); -*/ - - alignment = new PairwiseAlignPanel(seqs, true, 100, 5); + //alignment = new PairwiseAlignPanel(seqs, true, 100, 5); + alignment.calculate(); float[][] scores = alignment.getAlignmentScores(); //bigger index first -- eg scores[14][13] - //Hashtable connectivity = seqs.calculateConnectivity(scores, dim); + seqs.calculateConnectivity(scores, dim); pairwiseScores = new Matrix(scores); -pairwiseScores.print(System.out, "%1.4f "); pairwiseScores.fillDiagonal(); eigenMatrix = pairwiseScores.copy(); @@ -276,173 +224,6 @@ pairwiseScores.print(System.out, "%1.4f "); } /** - * aligns sequences in splits - * Splits each split into halves and aligns them agains halves of other splits - * - * @param seqs - * @param i ~ indices of split - * @param s ~ sequences per split - * - * @return a map of where to put in scores, value ~ scores[n][m] = v - **/ - protected HashMap splitCombineAndAlign(SequenceI[] seqArray, int[] i, int s) - { - HashMap result = new HashMap(); - - int[][] allGroups = new int[i.length][s]; - for (int g = 0; g < i.length; g++) // group g - { - int e = 0; // index going through allGroups[][e] - for (int j = g * s; j < i[g]; j++) // goes through all numbers in one group - { - allGroups[g][e++] = j >= seqArray.length ? -1 : j; - } - } - - int g = 0; // group count - for (int[] group : allGroups) - { - ArrayList sg = new ArrayList(); - //SequenceGroup sg = new SequenceGroup(); - for (int index : group) - { - if (index == -1) - continue; - //sg.addSequence(seqArray[index], false); - sg.add(seqArray[index]); - } - SequenceI[] sgArray = new SequenceI[sg.size()]; - int k = 0; - for (SequenceI seq : sg) - { - sgArray[k++] = seq; - } - //seqs.setSelectionGroup(sg); - //PairwiseAlignPanel pap = new PairwiseAlignPanel(seqs, true, 100, 5); - //float[][] scores = pap.getAlignmentScores(); //bigger index first -- eg scores[14][13] - float[][] scores = simulateAlignment(sgArray); - for (int s1 = 0; s1 < scores.length; s1++) // row - { - result.put(new int[]{s1 + g * s, s1 + g * s}, Float.NaN); // self score = Float.NaN - for (int s2 = 0; s2 < s1; s2++) // col - { -System.out.println(String.format("%s x %s -> [%d][%d] (%f)", sgArray[s1].getName(), sgArray[s2].getName(), s1+g*s, s2+g*s, scores[s1][s2])); - result.put(new int[]{s1 + g * s, s2 + g * s}, scores[s1][s2]); - } - } - g++; - } - - int smallS = (int) Math.ceil((float) s/2); - int[][] newGroups = new int[i.length * 2][smallS]; - - g = 0; - for (int[] group : allGroups) - { - int[] split1 = new int[smallS]; - int[] split2 = new int[smallS]; - for (int k = 0; k < group.length; k++) - { - if (k < smallS) - split1[k] = group[k]; - else - split2[k - smallS] = group[k]; - } - newGroups[g++] = split1; - newGroups[g++] = split2; - } - - // align each subsplit with subsplits from other split groups - for (int subsplitN = 0; subsplitN < newGroups.length; subsplitN++) - { -System.gc(); - int c = 1; // current subsplit block - while (newGroups[subsplitN][0] > smallS * c) - { - c++; - } - for (int nextSplit = subsplitN + 1; nextSplit < newGroups.length; nextSplit++) - { -System.out.println(String.format("subsplitN %d, nextSplit %d, %d > %d * %d", subsplitN, nextSplit, allGroups[(int) Math.floor((float) nextSplit / 2)][0], smallS, c)); - if (allGroups[(int) Math.floor((float) nextSplit / 2)][0] > smallS * c) - { - ArrayList sg = new ArrayList(); - //SequenceGroup sg = new SequenceGroup(); - for (int index : newGroups[subsplitN]) - { - if (index == -1) - continue; - //sg.addSequence(seqArray[index], false); - sg.add(seqArray[index]); - } - for (int index : newGroups[nextSplit]) - { - if (index == -1) - continue; - //sg.addSequence(seqArray[index], false); - sg.add(seqArray[index]); - } - SequenceI[] sgArray = new SequenceI[sg.size()]; - int k = 0; - for (SequenceI seq : sg) - { - sgArray[k++] = seq; - } - //seqs.setSelectionGroup(sg); - //PairwiseAlignPanel pap = new PairwiseAlignPanel(seqs, true, 100, 5); - //float[][] scores = pap.getAlignmentScores(); //bigger index first -- eg scores[14][13] - float[][] scores = simulateAlignment(sgArray); -System.gc(); - for (int s1 = 0; s1 < scores.length; s1++) // row - { - for (int s2 = 0; s2 < s1; s2++) // col - { - if (s1 >= smallS && s2 < smallS) -System.out.println(String.format("%s x %s -> [%d][%d] (%f)", sgArray[s1].getName(), sgArray[s2].getName(), s1+(nextSplit-1)*smallS, s2+subsplitN*smallS, scores[s1][s2])); - result.put(new int[]{s1 + (nextSplit-1) * smallS, s2 + subsplitN * smallS}, scores[s1][s2]); - } - } - } - } - } - - return result; - } - - /** - * simulate the alignment of a PairwiseAlignPanel - * - * @param seqs - * @return alignment scores - */ - protected float[][] simulateAlignment(SequenceI[] seqs) - { - float[][] result = new float[seqs.length][seqs.length]; - for (int i = 1; i < seqs.length; i++) - { - for (int j = 0; j < i; j++) - { - String[] seqStrings = new String[2]; - seqStrings[0] = seqs[i].getSequenceAsString(); - seqStrings[1] = seqs[j].getSequenceAsString(); - - AlignSeq as = new AlignSeq(seqs[i], seqStrings[0], seqs[j], seqStrings[1], AlignSeq.PEP, openCost, extendCost); - as.seqInit(seqs[i], seqStrings[0], seqs[j], seqStrings[1], AlignSeq.PEP); - as.calcScoreMatrix(); - as.traceAlignmentWithEndGaps(); - as.scoreAlignment(); - //as.printAlignment(System.out); - result[i][j] = as.getAlignmentScore(); - //as.clear(); - -System.out.println(String.format("%d / %d (%3.2f)", count, total, (float) ((count / total) * 100))); - count++; - } - } - return result; - } - - /** * Returns a PrintStream that wraps (appends its output to) the given * StringBuilder * diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 49bd4e9..d82fa42 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -70,6 +70,7 @@ import javax.swing.JLayeredPane; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPanel; +import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; @@ -988,6 +989,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } @Override + public JProgressBar getProgressBar(long id) + { + if (progressBar != null) + return progressBar.getProgressBar(id); + return null; + } + + @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index bc3c0d2..90a3822 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import java.awt.Font; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; @@ -91,6 +92,15 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } /** + * set font size of the textarea + * @param size + */ + public void setFont(Font font) + { + textarea.setFont(font); + } + + /** * DOCUMENT ME! */ public void setForInput(AlignmentViewPanel viewpanel) @@ -206,6 +216,16 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { } } + + /** + * show menu for changing the font + * @param e + */ + @Override + public void fontSizeMenu_actionPerformed(ActionEvent e) + { + new FontChooser(this); + } /** * DOCUMENT ME! diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 12ff20b..b82bc72 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -22,6 +22,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; @@ -2728,6 +2729,23 @@ public class Desktop extends jalview.jbgui.GDesktop } } + @Override + public JProgressBar getProgressBar(long id) + { + if (progressBars == null) + return null; + + if (progressBars.get(Long.valueOf(id)) == null) + return null; + + for (Component c : progressBars.get(Long.valueOf(id)).getComponents()) + { + if (c.getClass() == JProgressBar.class) + return (JProgressBar) c; + } + return null; + } + /* * (non-Javadoc) * diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index f532706..853d4aa 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -43,6 +43,8 @@ public class FontChooser extends GFontChooser TreePanel tp; + CutAndPasteTransfer cap; + /* * The font on opening the dialog (to be restored on Cancel) */ @@ -109,30 +111,44 @@ public class FontChooser extends GFontChooser init(); } + /** + * Creates a new FontChooser for a CutAndPasteTransfer + * @param cap + */ + public FontChooser(CutAndPasteTransfer cap) + { + oldFont = new Font("Monospaced", Font.PLAIN, 12); + this.cap = cap; + init(); + } + void init() { frame = new JInternalFrame(); frame.setFrameIcon(null); frame.setContentPane(this); - smoothFont.setSelected(ap.av.antiAlias); - - /* - * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is - * stored in the ViewStyle of both dna and protein Viewport. Also enable - * checkbox for copy font changes to other half of split frame. - */ - boolean inSplitFrame = ap.av.getCodingComplement() != null; - if (inSplitFrame) + if (!isCapFont()) { - oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) - .getFont(); - oldComplementSmooth = ((AlignViewport) ap.av - .getCodingComplement()).antiAlias; - scaleAsCdna.setVisible(true); - scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna()); - fontAsCdna.setVisible(true); - fontAsCdna.setSelected(ap.av.isProteinFontAsCdna()); + smoothFont.setSelected(ap.av.antiAlias); + + /* + * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is + * stored in the ViewStyle of both dna and protein Viewport. Also enable + * checkbox for copy font changes to other half of split frame. + */ + boolean inSplitFrame = ap.av.getCodingComplement() != null; + if (inSplitFrame) + { + oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) + .getFont(); + oldComplementSmooth = ((AlignViewport) ap.av + .getCodingComplement()).antiAlias; + scaleAsCdna.setVisible(true); + scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna()); + fontAsCdna.setVisible(true); + fontAsCdna.setSelected(ap.av.isProteinFontAsCdna()); + } } if (isTreeFont()) @@ -269,6 +285,10 @@ public class FontChooser extends GFontChooser return tp != null; } + private boolean isCapFont() + { + return cap != null; + } /** * DOCUMENT ME! */ @@ -350,6 +370,10 @@ public class FontChooser extends GFontChooser splitFrame.repaint(); } } + else if (isCapFont()) + { + cap.setFont(newFont); + } monospaced.setSelected(mw == iw); diff --git a/src/jalview/gui/IProgressIndicator.java b/src/jalview/gui/IProgressIndicator.java index 35bd871..387236a 100644 --- a/src/jalview/gui/IProgressIndicator.java +++ b/src/jalview/gui/IProgressIndicator.java @@ -20,6 +20,8 @@ */ package jalview.gui; +import javax.swing.JProgressBar; + /** * Visual progress indicator interface. * @@ -56,4 +58,11 @@ public interface IProgressIndicator */ boolean operationInProgress(); + /** + * + * @param id + * @return progressbar mapped to id + */ + public JProgressBar getProgressBar(long id); + } diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 211c370..bd7f963 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -33,6 +33,7 @@ import java.awt.print.PrinterJob; import javax.swing.ButtonGroup; import javax.swing.JMenuItem; +import javax.swing.JProgressBar; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -775,4 +776,10 @@ public class PCAPanel extends GPCAPanel getRotatableCanvas().ap = panel; PaintRefresher.Register(PCAPanel.this, panel.av.getSequenceSetId()); } + + @Override + public JProgressBar getProgressBar(long id) + { + return progressBar.getProgressBar(id); + } } diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 832bbad..6188674 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -49,9 +49,12 @@ import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import javax.swing.ButtonGroup; import javax.swing.JMenuItem; +import javax.swing.JProgressBar; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -66,6 +69,10 @@ public class PaSiMapPanel extends GPaSiMapPanel private static final int MIN_HEIGHT = 250; + private final int GAP_OPEN_COST = 100; + + private final int GAP_EXTEND_COST = 5; + private RotatableCanvas rc; AlignmentPanel ap; @@ -78,6 +85,8 @@ public class PaSiMapPanel extends GPaSiMapPanel private IProgressIndicator progressBar; + private long progId; + private boolean working; /** @@ -96,7 +105,7 @@ public class PaSiMapPanel extends GPaSiMapPanel this.ap = alignPanel; boolean nucleotide = av.getAlignment().isNucleotide(); - progressBar = new ProgressBar(statusPanel, statusBar); + //progressBar = new ProgressBar(statusPanel, statusBar); addInternalFrameListener(new InternalFrameAdapter() { @@ -122,7 +131,7 @@ public class PaSiMapPanel extends GPaSiMapPanel ScoreModelI scoreModel = ScoreModels.getInstance() .getScoreModel(modelName, ap); setPasimapModel( - new PaSiMapModel(av, seqs, nucleotide, scoreModel, params)); + new PaSiMapModel(av, seqs, nucleotide, scoreModel)); PaintRefresher.Register(this, av.getSequenceSetId()); setRotatableCanvas(new RotatableCanvas(alignPanel)); @@ -171,18 +180,31 @@ public class PaSiMapPanel extends GPaSiMapPanel public void run() { working = true; - long progId = System.currentTimeMillis(); - IProgressIndicator progress = this; + progId = System.currentTimeMillis(); + progressBar = this; String message = MessageManager.getString("label.pasimap_recalculating"); if (getParent() == null) { - progress = ap.alignFrame; + progressBar = ap.alignFrame; message = MessageManager.getString("label.pasimap_calculating"); } - progress.setProgressBar(message, progId); + progressBar.setProgressBar(message, progId); try { - getPasimapModel().calculate(); + //&! remove big seqs + for (SequenceI seq : av.getAlignment().getSequencesArray()) + { + if (seq.getLength() > 20000) + { + //TODO add warning dialog + av.getAlignment().deleteSequence(seq); + } + } + + PairwiseAlignPanel pap = new PairwiseAlignPanel(av, true, GAP_OPEN_COST, GAP_EXTEND_COST, false); +System.out.println(pap != null); + setPairwiseAlignPanel(pap); + getPasimapModel().calculate(pap); xCombobox.setSelectedIndex(0); yCombobox.setSelectedIndex(1); @@ -199,7 +221,7 @@ public class PaSiMapPanel extends GPaSiMapPanel return; } finally { - progress.setProgressBar("", progId); + progressBar.setProgressBar("", progId); } repaint(); @@ -638,6 +660,45 @@ public class PaSiMapPanel extends GPaSiMapPanel // validate(); } + /* + * make the progressBar determinate and update its progress + */ + public void updateProgressBar(int lengthOfTask, int progress) + { + JProgressBar pBar = progressBar.getProgressBar(progId); + if (pBar.isIndeterminate()) + { + pBar.setMaximum(lengthOfTask); + pBar.setValue(0); + pBar.setIndeterminate(false); + } + updateProgressBar(progress); + } + public void updateProgressBar(int progress) + { + JProgressBar pBar = progressBar.getProgressBar(progId); + pBar.setValue(progress); + pBar.repaint(); + } + + //&! + public void setPairwiseAlignPanel(PairwiseAlignPanel pap) + { + pap.addPropertyChangeListener(new PropertyChangeListener() + { + @Override + public void propertyChange(PropertyChangeEvent pcEvent) + { + if (PairwiseAlignPanel.PROGRESS.equals(pcEvent.getPropertyName())) + { + updateProgressBar((int) pcEvent.getNewValue()); + } else if (PairwiseAlignPanel.TOTAL.equals(pcEvent.getPropertyName())) { + updateProgressBar((int) pcEvent.getNewValue(), 0); + } + } + }); + } + @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) @@ -791,4 +852,10 @@ public class PaSiMapPanel extends GPaSiMapPanel getRotatableCanvas().ap = panel; PaintRefresher.Register(PaSiMapPanel.this, panel.av.getSequenceSetId()); } + + @Override + public JProgressBar getProgressBar(long id) + { + return progressBar.getProgressBar(id); + } } diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index ced9cb9..087d7f6 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -30,8 +30,10 @@ import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.math.MiscMath; +import java.beans.PropertyChangeListener; import java.awt.event.ActionEvent; import java.util.Vector; +import javax.swing.event.SwingPropertyChangeSupport; /** * DOCUMENT ME! @@ -52,16 +54,27 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel private int GAP_EXTEND_COST; - //&! - private long total = 0l; - private long ccount = 0l; - AlignmentViewport av; Vector sequences; private String alignmentOutput; + private boolean suppressTextbox; + + private boolean discardAlignments; + + private boolean endGaps; + + // for listening + public static final String TOTAL = "total"; + + public static final String PROGRESS = "progress"; + + private int total; + + private int progress; + /** * Creates a new PairwiseAlignPanel object. * @@ -71,37 +84,53 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel */ public PairwiseAlignPanel(AlignmentViewport viewport) { - this(viewport, false, 120, 20); // default penalties used in AlignSeq + this(viewport, false, 120, 20, true); // default penalties used in AlignSeq } public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost) { + this(viewport, endGaps, gapOpenCost, gapExtendCost, true); + } + public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost, boolean run) + { super(); this.av = viewport; + this.GAP_OPEN_COST = gapOpenCost; + this.GAP_EXTEND_COST = gapExtendCost; + this.endGaps = endGaps; + this.total = MiscMath.combinations(av.getAlignment().getHeight(), 2); + + if (run) + calculate(); +System.out.println("Creating pap"); + } + public void calculate() + { + + SequenceGroup selectionGroup = av.getSelectionGroup(); StringBuilder sb = new StringBuilder(1024); sequences = new Vector(); - SequenceGroup selectionGroup = viewport.getSelectionGroup(); boolean isSelection = selectionGroup != null && selectionGroup.getSize() > 0; - AlignmentView view = viewport.getAlignmentView(isSelection); - // String[] seqStrings = viewport.getViewAsString(true); + AlignmentView view = av.getAlignmentView(isSelection); + // String[] seqStrings = av.getViewAsString(true); String[] seqStrings = view - .getSequenceStrings(viewport.getGapCharacter()); + .getSequenceStrings(av.getGapCharacter()); SequenceI[] seqs; if (isSelection) { seqs = (SequenceI[]) view - .getAlignmentAndHiddenColumns(viewport.getGapCharacter())[0]; + .getAlignmentAndHiddenColumns(av.getGapCharacter())[0]; } else { seqs = av.getAlignment().getSequencesArray(); } - String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA + String type = (av.getAlignment().isNucleotide()) ? AlignSeq.DNA : AlignSeq.PEP; float[][] scores = new float[seqs.length][seqs.length]; @@ -109,22 +138,22 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel double totscore = 0D; int count = seqs.length; boolean first = true; - //AlignSeq as = new AlignSeq(seqs[1], seqStrings[1], seqs[0], seqStrings[0], type, gapOpenCost, gapExtendCost); -//&! -this.total = (long) MiscMath.permutations(count,2) / 2; + + progress = 0; + firePropertyChange(TOTAL, 0, total); + + suppressTextbox = count<10; + discardAlignments = count<15; for (int i = 1; i < count; i++) { // fill diagonal alignmentScores with Float.NaN - alignmentScores[i-1][i-1] = Float.NaN; + alignmentScores[i - 1][i - 1] = Float.NaN; for (int j = 0; j < i; j++) { AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], - seqStrings[j], type, gapOpenCost, gapExtendCost); -// as.seqInit(seqs[i], seqStrings[i], seqs[j], seqStrings[j], type); + seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST); -System.out.println(String.format("%d / %d", ccount, total)); -this.ccount++; if (as.s1str.length() == 0 || as.s2str.length() == 0) { continue; @@ -141,24 +170,33 @@ this.ccount++; if (!first) { - //System.out.println(DASHES); + System.out.println(DASHES); textarea.append(DASHES); sb.append(DASHES); } first = false; - //as.printAlignment(System.out); + if (discardAlignments) { + as.printAlignment(System.out); + } scores[i][j] = as.getMaxScore() / as.getASeq1().length; -//System.out.println(String.format("%s x %s -> [%d][%d] (%f)", seqs[i].getName(), seqs[j].getName(), i, j, as.getAlignmentScore())); alignmentScores[i][j] = as.getAlignmentScore(); totscore = totscore + scores[i][j]; - textarea.append(as.getOutput()); - sb.append(as.getOutput()); - sequences.add(as.getAlignedSeq1()); - sequences.add(as.getAlignedSeq2()); + if (suppressTextbox) + { + textarea.append(as.getOutput()); + sb.append(as.getOutput()); + } + if (discardAlignments) + { + sequences.add(as.getAlignedSeq1()); + sequences.add(as.getAlignedSeq2()); + } + + firePropertyChange(PROGRESS, progress, ++progress); } } - alignmentScores[count-1][count-1] = Float.NaN; + alignmentScores[count - 1][count - 1] = Float.NaN; this.scores = scores; this.alignmentScores = alignmentScores; @@ -254,4 +292,14 @@ this.ccount++; MessageManager.getString("label.pairwise_aligned_sequences"), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); } + + public long getTotal() + { + return total; + } + + public long getProgress() + { + return progress; + } } diff --git a/src/jalview/gui/ProgressBar.java b/src/jalview/gui/ProgressBar.java index 011d810..bee50b3 100644 --- a/src/jalview/gui/ProgressBar.java +++ b/src/jalview/gui/ProgressBar.java @@ -267,4 +267,17 @@ public class ProgressBar implements IProgressIndicator }); } + /* + * + */ + public JProgressBar getProgressBar(long id) + { + for (Component component : progressBars.get(id).getComponents()) + { + if (component.getClass().equals(JProgressBar.class)) + return (JProgressBar) component; + } + return null; + } + } diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 28038a5..042f178 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -749,11 +749,11 @@ public class RotatableCanvas extends JPanel { SequencePoint sp = sequencePoints.get(i); int tmp1 = (int) (((sp.coord.x - centre[0]) * getScaleFactor()) - * (getWidth() / 2.0) + * (getWidth() / 3.15) + (getWidth() / 2.0)); float pre1 = ((sp.coord.x - centre[0]) * getScaleFactor()); int tmp2 = (int) (((sp.coord.y - centre[1]) * getScaleFactor()) - * (getHeight() / 2.0) + * (getHeight() / 1.70) + (getHeight() / 2.0)); float pre2 = ((sp.coord.y - centre[1]) * getScaleFactor()); diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 6fce984..b17aac9 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -40,6 +40,7 @@ import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; +import javax.swing.JProgressBar; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.table.AbstractTableModel; @@ -1827,4 +1828,10 @@ public class StructureChooser extends GStructureChooser } } + + @Override + public JProgressBar getProgressBar(long id) + { + return progressBar.getProgressBar(id); + } } diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index 7eeee9a..cbe8221 100644 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -38,6 +38,7 @@ import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JInternalFrame; import javax.swing.JPanel; +import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; @@ -945,4 +946,10 @@ public class WebserviceInfo extends GWebserviceInfo { return progressBar.operationInProgress(); } + + @Override + public JProgressBar getProgressBar(long id) + { + return progressBar.getProgressBar(id); + } } diff --git a/src/jalview/jbgui/GCutAndPasteTransfer.java b/src/jalview/jbgui/GCutAndPasteTransfer.java index 3cd52ae..5daea78 100755 --- a/src/jalview/jbgui/GCutAndPasteTransfer.java +++ b/src/jalview/jbgui/GCutAndPasteTransfer.java @@ -60,6 +60,8 @@ public class GCutAndPasteTransfer extends JInternalFrame JMenuItem pasteMenu = new JMenuItem(); + JMenuItem fontSizeMenu = new JMenuItem(); + BorderLayout borderLayout2 = new BorderLayout(); protected JPanel inputButtonPanel = new JPanel(); @@ -190,6 +192,15 @@ public class GCutAndPasteTransfer extends JInternalFrame pasteMenu_actionPerformed(e); } }); + fontSizeMenu.setText(MessageManager.getString("action.change_font")); + fontSizeMenu.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + fontSizeMenu_actionPerformed(e); + } + }); copyItem.setText(MessageManager.getString("action.copy")); copyItem.addActionListener(new ActionListener() { @@ -205,6 +216,7 @@ public class GCutAndPasteTransfer extends JInternalFrame editMenu.add(selectAll); editMenu.add(copyItem); editMenu.add(pasteMenu); + editMenu.add(fontSizeMenu); this.getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER); inputButtonPanel.add(ok); inputButtonPanel.add(cancel); @@ -243,6 +255,14 @@ public class GCutAndPasteTransfer extends JInternalFrame } /** + * shows a menu for changing the font + * @param e + */ + public void fontSizeMenu_actionPerformed(ActionEvent e) + { + } + + /** * DOCUMENT ME! * * @param e diff --git a/src/jalview/math/MiscMath.java b/src/jalview/math/MiscMath.java index 7593cb0..b5218d5 100755 --- a/src/jalview/math/MiscMath.java +++ b/src/jalview/math/MiscMath.java @@ -345,4 +345,37 @@ public class MiscMath return result; } + /** + * calculate all unique combinations of n elements into r sized groups + * @param n + * @param r + * + * @return + */ + public static int combinations(int n, int r) + { + int result = 1; + for (int i = 0; i < r; i++) + { + result *= (n-1); + } + return (int) (result / MiscMath.factorial(r)); + } + + /** + * calculate the factorial of n (n >= 0) + * @param n + * + * @return + */ + public static int factorial(int n) + { + int result = 1; + for (int i = 0; i < n; i++) + { + result *= (n - i); + } + return result; + } + } diff --git a/src/jalview/viewmodel/PaSiMapModel.java b/src/jalview/viewmodel/PaSiMapModel.java index ba9ad6a..47329c9 100644 --- a/src/jalview/viewmodel/PaSiMapModel.java +++ b/src/jalview/viewmodel/PaSiMapModel.java @@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentView; import jalview.datamodel.Point; import jalview.datamodel.SequenceI; import jalview.datamodel.SequencePoint; +import jalview.gui.PairwiseAlignPanel; import jalview.viewmodel.AlignmentViewport; import java.util.List; @@ -42,8 +43,6 @@ public class PaSiMapModel private final SequenceI[] seqs; - private final SimilarityParamsI similarityParams; - /* * options - score model, nucleotide / protein */ @@ -71,22 +70,21 @@ public class PaSiMapModel * @param params */ public PaSiMapModel(AlignmentViewport seqData, SequenceI[] sqs, boolean nuc, - ScoreModelI modelName, SimilarityParamsI params) + ScoreModelI modelName) { inputData = seqData; seqs = sqs; nucleotide = nuc; scoreModel = modelName; - similarityParams = params; } /** * Performs the PaSiMap calculation (in the same thread) and extracts result data * needed for visualisation by PaSiMapPanel */ - public void calculate() + public void calculate(PairwiseAlignPanel pap) { - pasimap = new PaSiMap(inputData, scoreModel, similarityParams); + pasimap = new PaSiMap(inputData, scoreModel, pap); pasimap.run(); // executes in same thread, wait for completion // Now find the component coordinates @@ -226,16 +224,6 @@ public class PaSiMapModel this.scoreModel = sm; } - /** - * Answers the parameters configured for pairwise similarity calculations - * - * @return - */ - public SimilarityParamsI getSimilarityParameters() - { - return similarityParams; - } - public List getSequencePoints() { return points;