Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File PairwiseAlignPanel.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
35% of files have more coverage

Code metrics

24
53
3
1
196
117
16
0.3
17.67
3
5.33

Classes

Class Line # Actions
PairwiseAlignPanel 41 53 16 38
0.52552.5%
 

Contributing tests

This file is covered by 2 tests. .

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.gui;
22   
23    import jalview.analysis.AlignSeq;
24    import jalview.datamodel.Alignment;
25    import jalview.datamodel.AlignmentView;
26    import jalview.datamodel.SequenceGroup;
27    import jalview.datamodel.SequenceI;
28    import jalview.jbgui.GPairwiseAlignPanel;
29    import jalview.util.MessageManager;
30    import jalview.viewmodel.AlignmentViewport;
31   
32    import java.awt.event.ActionEvent;
33    import java.util.Vector;
34   
35    /**
36    * DOCUMENT ME!
37    *
38    * @author $author$
39    * @version $Revision$
40    */
 
41    public class PairwiseAlignPanel extends GPairwiseAlignPanel
42    {
43   
44    private static final String DASHES = "---------------------\n";
45   
46    AlignmentViewport av;
47   
48    Vector<SequenceI> sequences;
49   
50    /**
51    * Creates a new PairwiseAlignPanel object.
52    *
53    * @param viewport
54    * DOCUMENT ME!
55    */
 
56  2 toggle public PairwiseAlignPanel(AlignmentViewport viewport)
57    {
58  2 super();
59  2 this.av = viewport;
60   
61  2 sequences = new Vector<SequenceI>();
62   
63  2 SequenceGroup selectionGroup = viewport.getSelectionGroup();
64  2 boolean isSelection = selectionGroup != null
65    && selectionGroup.getSize() > 0;
66  2 AlignmentView view = viewport.getAlignmentView(isSelection);
67    // String[] seqStrings = viewport.getViewAsString(true);
68  2 String[] seqStrings = view.getSequenceStrings(viewport
69    .getGapCharacter());
70   
71  2 SequenceI[] seqs;
72  2 if (isSelection)
73    {
74  1 seqs = (SequenceI[]) view.getAlignmentAndHiddenColumns(viewport
75    .getGapCharacter())[0];
76    }
77    else
78    {
79  1 seqs = av.getAlignment().getSequencesArray();
80    }
81   
82  2 String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA
83    : AlignSeq.PEP;
84   
85  2 float[][] scores = new float[seqs.length][seqs.length];
86  2 double totscore = 0D;
87  2 int count = seqs.length;
88  2 boolean first = true;
89   
90  4 for (int i = 1; i < count; i++)
91    {
92  4 for (int j = 0; j < i; j++)
93    {
94  2 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
95    seqStrings[j], type);
96   
97  2 if (as.s1str.length() == 0 || as.s2str.length() == 0)
98    {
99  0 continue;
100    }
101   
102  2 as.calcScoreMatrix();
103  2 as.traceAlignment();
104   
105  2 if (!first)
106    {
107  0 System.out.println(DASHES);
108  0 textarea.append(DASHES);
109    }
110  2 first = false;
111  2 as.printAlignment(System.out);
112  2 scores[i][j] = as.getMaxScore()
113    / as.getASeq1().length;
114  2 totscore = totscore + scores[i][j];
115   
116  2 textarea.append(as.getOutput());
117  2 sequences.add(as.getAlignedSeq1());
118  2 sequences.add(as.getAlignedSeq2());
119    }
120    }
121   
122  2 if (count > 2)
123    {
124  0 printScoreMatrix(seqs, scores, totscore);
125    }
126    }
127   
128    /**
129    * Prints a matrix of seqi-seqj pairwise alignment scores to sysout
130    *
131    * @param seqs
132    * @param scores
133    * @param totscore
134    */
 
135  0 toggle protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,
136    double totscore)
137    {
138  0 System.out
139    .println("Pairwise alignment scaled similarity score matrix\n");
140   
141  0 for (int i = 0; i < seqs.length; i++)
142    {
143  0 System.out.println(String.format("%3d %s", i + 1,
144    seqs[i].getDisplayId(true)));
145    }
146   
147    /*
148    * table heading columns for sequences 1, 2, 3...
149    */
150  0 System.out.print("\n ");
151  0 for (int i = 0; i < seqs.length; i++)
152    {
153  0 System.out.print(String.format("%7d", i + 1));
154    }
155  0 System.out.println();
156   
157  0 for (int i = 0; i < seqs.length; i++)
158    {
159  0 System.out.print(String.format("%3d", i + 1));
160  0 for (int j = 0; j < i; j++)
161    {
162    /*
163    * as a fraction of tot score, outputs are 0 <= score <= 1
164    */
165  0 System.out.print(String.format("%7.3f", scores[i][j] / totscore));
166    }
167  0 System.out.println();
168    }
169   
170  0 System.out.println("\n");
171    }
172   
173    /**
174    * DOCUMENT ME!
175    *
176    * @param e
177    * DOCUMENT ME!
178    */
 
179  0 toggle @Override
180    protected void viewInEditorButton_actionPerformed(ActionEvent e)
181    {
182  0 SequenceI[] seq = new SequenceI[sequences.size()];
183   
184  0 for (int i = 0; i < sequences.size(); i++)
185    {
186  0 seq[i] = sequences.elementAt(i);
187    }
188   
189  0 AlignFrame af = new AlignFrame(new Alignment(seq),
190    AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
191   
192  0 Desktop.addInternalFrame(af,
193    MessageManager.getString("label.pairwise_aligned_sequences"),
194    AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
195    }
196    }