From: Jim Procter Date: Tue, 21 May 2024 17:18:20 +0000 (+0100) Subject: JAL-4159 connectivity should be computed for the sequences analysed with PAsiMap... X-Git-Tag: Release_2_11_4_0~31^2~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=85a98fd6dbc992939850e3f49a3ed6902f7140d9;p=jalview.git JAL-4159 connectivity should be computed for the sequences analysed with PAsiMap, not the alignment --- diff --git a/src/jalview/analysis/Connectivity.java b/src/jalview/analysis/Connectivity.java index a4cbc3a..c65c170 100644 --- a/src/jalview/analysis/Connectivity.java +++ b/src/jalview/analysis/Connectivity.java @@ -20,17 +20,12 @@ */ package jalview.analysis; -//import jalview.datamodel.AlignmentView; -import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.viewmodel.AlignmentViewport; -import java.util.Comparator; import java.util.Hashtable; -import java.util.HashSet; -import java.util.TreeSet; /** * @Author MorellThomas @@ -38,27 +33,40 @@ import java.util.TreeSet; public class Connectivity { - - /** - * Returns the number of unique connections for each sequence - * only connections with a score of above 0 count - * - * @param av sequences - * @param scores alignment scores - * - * @return connectivity - */ - public static Hashtable getConnectivity(AlignmentViewport av, float[][] scores, byte dim) throws RuntimeException + public static Hashtable getConnectivityForAlignmentView( + AlignmentViewport av, float[][] scores, byte dim) { - boolean isSelection = av.getSelectionGroup() != null && av.getSelectionGroup().getSize() > 0; + boolean isSelection = av.getSelectionGroup() != null + && av.getSelectionGroup().getSize() > 0; SequenceI[] sequences; if (isSelection) { - sequences = (SequenceI[]) av.getAlignmentView(isSelection).getAlignmentAndHiddenColumns(av.getGapCharacter())[0]; - } else { + sequences = (SequenceI[]) av.getAlignmentView(isSelection) + .getAlignmentAndHiddenColumns(av.getGapCharacter())[0]; + } + else + { sequences = av.getAlignment().getSequencesArray(); } + return Connectivity.getConnectivity(sequences, scores, dim); + } + + /** + * Returns the number of unique connections for each sequence only connections + * with a score of above 0 count + * + * @param av + * sequences + * @param scores + * alignment scores + * + * @return connectivity + */ + public static Hashtable getConnectivity( + SequenceI[] sequences, float[][] scores, byte dim) + throws RuntimeException + { Hashtable connectivity = new Hashtable(); // for each unique connection for (int i = 0; i < sequences.length; i++) @@ -67,28 +75,34 @@ public class Connectivity for (int j = 0; j < i; j++) { connectivity.putIfAbsent(sequences[j], 0); - int iOld = connectivity.get(sequences[i]); - int jOld = connectivity.get(sequences[j]); + int iOld = connectivity.get(sequences[i]); + int jOld = connectivity.get(sequences[j]); // count the connection if its score is not NaN -//System.out.println(String.format("%s - %s : %f", sequences[i].getName(), sequences[j].getName(), scores[i][j])); - if (!Float.isNaN(scores[i][j])) - { - connectivity.put(sequences[i], ++iOld); - connectivity.put(sequences[j], ++jOld); - } + // System.out.println(String.format("%s - %s : %f", + // sequences[i].getName(), sequences[j].getName(), scores[i][j])); + if (!Float.isNaN(scores[i][j])) + { + connectivity.put(sequences[i], ++iOld); + connectivity.put(sequences[j], ++jOld); + } } } // if a sequence has too few connections, abort - connectivity.forEach((sequence, connection) -> - { - System.out.println(String.format("%s: %d", sequence.getName(), connection)); + connectivity.forEach((sequence, connection) -> { + System.out.println( + String.format("%s: %d", sequence.getName(), connection)); if (connection < dim) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, String.format("Insufficient number of connections for %s (%d, should be %d or more)", sequence.getName(), connection, dim), "Connectivity Error", JvOptionPane.WARNING_MESSAGE); - throw new ConnectivityException(sequence.getName(), connection, dim); + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + String.format( + "Insufficient number of connections for %s (%d, should be %d or more)", + sequence.getName(), connection, dim), + "Connectivity Error", JvOptionPane.WARNING_MESSAGE); + throw new ConnectivityException(sequence.getName(), connection, + dim); } - } ); + }); return connectivity; } diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index 7c1c24a..86888ee 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -205,8 +205,8 @@ public class PaSiMap implements Runnable //alignment = new PairwiseAlignPanel(seqs, true, 100, 5); alignment.calculate(); float[][] scores = alignment.getAlignmentScores(); //bigger index first -- eg scores[14][13] - - seqs.calculateConnectivity(scores, dim); + SequenceI[] iseqs = alignment.getInputSequences(); + Connectivity.getConnectivity(iseqs, scores, dim); pairwiseScores = new Matrix(scores); pairwiseScores.fillDiagonal(); diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 4708888..d26f023 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -3294,9 +3294,4 @@ public abstract class AlignmentViewport + savedUpToDate); return savedUpToDate; } - - public Hashtable calculateConnectivity(float[][] scores, byte dim) - { - return Connectivity.getConnectivity(this, scores, dim); - } }