From 9a000e0149a64e19000e8bfa3f1a2e97cddd8cb7 Mon Sep 17 00:00:00 2001 From: MorellThomas Date: Fri, 12 Apr 2024 10:03:52 +0200 Subject: [PATCH] inlcude progress --- src/jalview/analysis/AlignSeq.java | 39 +++++++++++++++++++++++++++++++ src/jalview/analysis/PaSiMap.java | 33 +++++++++++++++++++++----- src/jalview/gui/PairwiseAlignPanel.java | 15 +++++++++--- src/jalview/math/MiscMath.java | 21 +++++++++++++++++ 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 1b5dab4..bcb7bd5 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -145,6 +145,11 @@ public class AlignSeq * @param type * molecule type, either AlignSeq.PEP or AlignSeq.DNA */ + public AlignSeq(int opencost, int extcost) + { + GAP_OPEN_COST = opencost; + GAP_EXTEND_COST = extcost; + } public AlignSeq(SequenceI s1, SequenceI s2, String type) { seqInit(s1, s1.getSequenceAsString(), s2, s2.getSequenceAsString(), @@ -1459,4 +1464,38 @@ public class AlignSeq float minScore = 0f; this.alignmentScore = (score <= minScore) ? Float.NaN : score; } + + public void clear() + { + score = null; + alignmentScore = 0f; + E = null; + F = null; + traceback = null; // todo is this actually used? + seq1 = null; + seq2 = null; + s1 = null; + s2 = null; + s1str = null; + s2str = null; + maxi = 0; + maxj = 0; + aseq1 = null; + aseq2 = null; + astr1 = ""; + astr2 = ""; + indelfreeAstr1 = ""; + indelfreeAstr2 = ""; + seq1start = 0; + seq1end = 0; + seq2start = 0; + seq2end = 0; + count = 0; + maxscore = 0f; + meanScore = 0f; //needed for PaSiMap + hypotheticMaxScore = 0; // needed for PaSiMap + prev = 0; + StringBuffer output = new StringBuffer(); + String type = null; // AlignSeq.PEP or AlignSeq.DNA + } } diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index de89953..8e8d423 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -31,9 +31,9 @@ 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; @@ -58,6 +58,17 @@ public class PaSiMap implements Runnable final private byte dim = 3; + final private int openCost = 100; + + final private int extendCost = 5; + + /* + * other + */ + private long total; // total number of combinations + + private long count; // current iteration number + /* * outputs */ @@ -81,6 +92,9 @@ public class PaSiMap implements Runnable 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; } /** @@ -213,11 +227,12 @@ 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) > 300f) // heap full at 341 + 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); @@ -237,8 +252,8 @@ System.out.println(String.format("%d -> %d splits into %d seqs", nSeqs, nSplits, } pairwiseScores = new Matrix(scores); pairwiseScores.print(System.out, "%1.4f "); +*/ -/* alignment = new PairwiseAlignPanel(seqs, true, 100, 5); float[][] scores = alignment.getAlignmentScores(); //bigger index first -- eg scores[14][13] @@ -246,7 +261,6 @@ pairwiseScores.print(System.out, "%1.4f "); pairwiseScores = new Matrix(scores); pairwiseScores.print(System.out, "%1.4f "); -*/ pairwiseScores.fillDiagonal(); eigenMatrix = pairwiseScores.copy(); @@ -341,6 +355,7 @@ System.out.println(String.format("%s x %s -> [%d][%d] (%f)", sgArray[s1].getName // 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) { @@ -377,6 +392,7 @@ System.out.println(String.format("subsplitN %d, nextSplit %d, %d > %d * %d", sub //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 @@ -410,12 +426,17 @@ System.out.println(String.format("%s x %s -> [%d][%d] (%f)", sgArray[s1].getName seqStrings[0] = seqs[i].getSequenceAsString(); seqStrings[1] = seqs[j].getSequenceAsString(); - AlignSeq as = new AlignSeq(seqs[i], seqStrings[0], seqs[j], seqStrings[1], AlignSeq.PEP); + 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); + //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; diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 2379e27..ced9cb9 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -28,6 +28,7 @@ import jalview.datamodel.SequenceI; import jalview.jbgui.GPairwiseAlignPanel; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.math.MiscMath; import java.awt.event.ActionEvent; import java.util.Vector; @@ -51,6 +52,10 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel private int GAP_EXTEND_COST; + //&! + private long total = 0l; + private long ccount = 0l; + AlignmentViewport av; Vector sequences; @@ -105,6 +110,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel 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; for (int i = 1; i < count; i++) { @@ -116,6 +123,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel seqStrings[j], type, gapOpenCost, gapExtendCost); // as.seqInit(seqs[i], seqStrings[i], seqs[j], seqStrings[j], type); +System.out.println(String.format("%d / %d", ccount, total)); +this.ccount++; if (as.s1str.length() == 0 || as.s2str.length() == 0) { continue; @@ -132,14 +141,14 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel if (!first) { - System.out.println(DASHES); + //System.out.println(DASHES); textarea.append(DASHES); sb.append(DASHES); } first = false; - as.printAlignment(System.out); + //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())); +//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]; diff --git a/src/jalview/math/MiscMath.java b/src/jalview/math/MiscMath.java index d3cec30..7593cb0 100755 --- a/src/jalview/math/MiscMath.java +++ b/src/jalview/math/MiscMath.java @@ -324,4 +324,25 @@ public class MiscMath return cnt; } + /** + * recursively calculates the permutations of total n items with r items per combination + * according to n!/(n-r)! by only multiplying the relevant terms + * @param n + * @param r + * + * @return permutations + */ + public static long permutations(int n, int r) + { + if (n < r) + return permutations(r, n); + + long result = 1l; + for (int i = 0; i < r; i++) + { + result *= (n-i); + } + return result; + } + } -- 1.7.10.2