Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package jalview.analysis

File Connectivity.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

10
22
2
1
110
62
7
0.32
11
2
3.5

Classes

Class Line # Actions
Connectivity 34 22 7
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.analysis;
22   
23    import jalview.datamodel.SequenceI;
24    import jalview.gui.Desktop;
25    import jalview.gui.JvOptionPane;
26    import jalview.viewmodel.AlignmentViewport;
27   
28    import java.util.Hashtable;
29   
30    /**
31    * @Author MorellThomas
32    */
33   
 
34    public class Connectivity
35    {
 
36  0 toggle public static Hashtable<SequenceI, Integer> getConnectivityForAlignmentView(
37    AlignmentViewport av, float[][] scores, byte dim)
38    {
39  0 boolean isSelection = av.getSelectionGroup() != null
40    && av.getSelectionGroup().getSize() > 0;
41  0 SequenceI[] sequences;
42  0 if (isSelection)
43    {
44  0 sequences = (SequenceI[]) av.getAlignmentView(isSelection)
45    .getAlignmentAndHiddenColumns(av.getGapCharacter())[0];
46    }
47    else
48    {
49  0 sequences = av.getAlignment().getSequencesArray();
50    }
51   
52  0 return Connectivity.getConnectivity(sequences, scores, dim);
53    }
54   
55    /**
56    * Returns the number of unique connections for each sequence only connections
57    * with a score of above 0 count
58    *
59    * @param av
60    * sequences
61    * @param scores
62    * alignment scores
63    *
64    * @return connectivity
65    */
 
66  0 toggle public static Hashtable<SequenceI, Integer> getConnectivity(
67    SequenceI[] sequences, float[][] scores, byte dim)
68    throws RuntimeException
69    {
70  0 Hashtable<SequenceI, Integer> connectivity = new Hashtable<SequenceI, Integer>();
71    // for each unique connection
72  0 for (int i = 0; i < sequences.length; i++)
73    {
74  0 connectivity.putIfAbsent(sequences[i], 0);
75  0 for (int j = 0; j < i; j++)
76    {
77  0 connectivity.putIfAbsent(sequences[j], 0);
78  0 int iOld = connectivity.get(sequences[i]);
79  0 int jOld = connectivity.get(sequences[j]);
80    // count the connection if its score is not NaN
81    // System.out.println(String.format("%s - %s : %f",
82    // sequences[i].getName(), sequences[j].getName(), scores[i][j]));
83  0 if (!Float.isNaN(scores[i][j]))
84    {
85  0 connectivity.put(sequences[i], ++iOld);
86  0 connectivity.put(sequences[j], ++jOld);
87    }
88    }
89    }
90   
91    // if a sequence has too few connections, abort
92  0 connectivity.forEach((sequence, connection) -> {
93  0 System.out.println(
94    String.format("%s: %d", sequence.getName(), connection));
95  0 if (connection < dim)
96    {
97  0 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
98    String.format(
99    "Insufficient number of connections for %s (%d, should be %d or more)",
100    sequence.getName(), connection, dim),
101    "Connectivity Error", JvOptionPane.WARNING_MESSAGE);
102  0 throw new ConnectivityException(sequence.getName(), connection,
103    dim);
104    }
105    });
106   
107  0 return connectivity;
108    }
109   
110    }