Skip to content

Commit 2fa9ca2

Browse files
committed
Create Multiple Alignment GUI
Analogously as with the pairwise alignments, now it is possible to trigger a multiple structure alignment throw a GUI where the input is made via a JTextField. Any numnber of structures can be analyzed. biojava#281 This required some new classes and the modification of some of the old ones.
1 parent 4fbbd0e commit 2fa9ca2

File tree

14 files changed

+1314
-584
lines changed

14 files changed

+1314
-584
lines changed

biojava-structure-gui/src/main/java/demo/DemoMultipleMC.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public static void main(String[] args) throws IOException, StructureException, I
6666
}
6767

6868
//Here the multiple structural alignment algorithm comes in place to generate the alignment object
69-
MultipleMcMain algorithm = new MultipleMcMain();
69+
MultipleMcMain algorithm = new MultipleMcMain(new CeCPMain());
7070
MultipleMcParameters params = (MultipleMcParameters) algorithm.getParameters();
71-
params.setPairwiseAlgorithm(CeCPMain.algorithmName);
71+
params.setMinBlockLen(10);
7272

7373
MultipleAlignment result = algorithm.align(atomArrays);
7474
result.getEnsemble().setStructureNames(names);

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/AlignmentGui.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package org.biojava.nbio.structure.align.gui;
2424

25-
2625
import org.biojava.nbio.structure.Structure;
2726
import org.biojava.nbio.structure.StructureException;
2827
import org.biojava.nbio.structure.align.StructureAlignment;
@@ -43,7 +42,6 @@
4342
import java.awt.event.ActionEvent;
4443
import java.io.File;
4544

46-
4745
/** A JFrame that allows to trigger a pairwise structure alignment,
4846
* either from files in a directory,
4947
* or after manual upload.
@@ -323,10 +321,9 @@ public void actionPerformed(ActionEvent evt) {
323321
protected void configureParameters() {
324322
StructureAlignment algorithm = getStructureAlignment();
325323
System.out.println("configure parameters for " + algorithm.getAlgorithmName());
326-
324+
327325
// show a new config GUI
328-
new ParameterGUI(algorithm);
329-
326+
new ParameterGUI(algorithm.getParameters(), algorithm.getAlgorithmName());
330327
}
331328

332329

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/MenuCreator.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol;
2626
import org.biojava.nbio.structure.align.model.AFPChain;
27-
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
2827
import org.biojava.nbio.structure.align.util.UserConfiguration;
2928
import org.biojava.nbio.structure.align.webstart.WebStartMain;
3029

@@ -122,6 +121,7 @@ public static JMenuBar initJmolMenu(JFrame frame, AbstractAlignmentJmol parent,
122121
//Exit
123122
JMenuItem exitI = getExitMenuItem();
124123
file.add(exitI);
124+
125125
menu.add(file);
126126

127127
/// ALIGN MENU
@@ -130,7 +130,10 @@ public static JMenuBar initJmolMenu(JFrame frame, AbstractAlignmentJmol parent,
130130
//new Pairwise alignment
131131
JMenuItem pairI = getPairwiseAlignmentMenuItem();
132132
align.add(pairI);
133-
//new Multiple alignment TODO
133+
//new Multiple alignment
134+
JMenuItem multI = getMultipleAlignmentMenuItem();
135+
align.add(multI);
136+
134137
menu.add(align);
135138

136139
/// VIEW MENU
@@ -626,13 +629,21 @@ public void actionPerformed(ActionEvent e) {
626629
}
627630

628631

629-
/** provide a display for the pairwise structure alignment
630-
*
632+
/**
633+
* Provide a display for the pairwise structure alignment.
631634
*/
632635
private static void showPairDialog(){
633636
AlignmentGui gui = AlignmentGui.getInstance();
634637
gui.setVisible(true);
635638
}
639+
640+
/**
641+
* Provide a display for the multiple structure alignment.
642+
*/
643+
private static void showMultipleDialog(){
644+
MultipleAlignmentGUI gui = MultipleAlignmentGUI.getInstance();
645+
gui.setVisible(true);
646+
}
636647

637648
/**
638649
* Show some info about this GUI
@@ -705,7 +716,7 @@ public void actionPerformed(ActionEvent e) {
705716
String cmd = e.getActionCommand();
706717

707718
if ( cmd.equals(MULTIPLE_ALIGN)){
708-
MenuCreator.showPairDialog();
719+
MenuCreator.showMultipleDialog();
709720
}
710721
}
711722
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
* Created on Jul 16, 2006
21+
*
22+
*/
23+
package org.biojava.nbio.structure.align.gui;
24+
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
import org.biojava.nbio.structure.Atom;
29+
import org.biojava.nbio.structure.Structure;
30+
import org.biojava.nbio.structure.StructureException;
31+
import org.biojava.nbio.structure.StructureTools;
32+
import org.biojava.nbio.structure.align.MultipleStructureAligner;
33+
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
36+
37+
/**
38+
* A class that obtains structures via DAS and aligns them.
39+
* This is done in a separate thread.
40+
* It is possible to register Event listeners to get notification of when
41+
* the download has finished.
42+
*
43+
* @author Aleix Lafita
44+
* @since 4.1.1
45+
*
46+
*/
47+
public class MultipleAlignmentCalc implements AlignmentCalculationRunnable {
48+
49+
private static final Logger logger =
50+
LoggerFactory.getLogger(MultipleAlignmentCalc.class);
51+
52+
private boolean interrupted = false;
53+
private List<String> names;
54+
private List<Structure> structures;
55+
56+
private MultipleAlignmentGUI parent;
57+
58+
/**
59+
* Requests an alignment of the pdbs.
60+
* If they are empty strings, they are ignored.
61+
*
62+
* @param parent the gui frame that interacts with this class
63+
* @param structures
64+
* @param names
65+
*/
66+
public MultipleAlignmentCalc(MultipleAlignmentGUI parent,
67+
List<Structure> structures, List<String> names) {
68+
69+
this.parent= parent;
70+
this.structures = structures;
71+
this.names = names;
72+
}
73+
74+
@Override
75+
public void run() {
76+
77+
MultipleStructureAligner algorithm =
78+
parent.getMultipleStructureAligner();
79+
try {
80+
81+
List<Atom[]> atomArrays = new ArrayList<Atom[]>();
82+
for (Structure s:structures){
83+
Atom[] ca = StructureTools.getRepresentativeAtomArray(s);
84+
atomArrays.add(ca);
85+
}
86+
87+
MultipleAlignment msa = algorithm.align(atomArrays);
88+
msa.getEnsemble().setStructureNames(names);
89+
90+
MultipleAlignmentDisplay.display(msa);
91+
92+
} catch (StructureException e) {
93+
e.printStackTrace();
94+
logger.warn(e.getMessage());
95+
}
96+
97+
parent.notifyCalcFinished();
98+
}
99+
100+
@Override
101+
public void interrupt() {
102+
interrupted = true;
103+
}
104+
105+
@Override
106+
public void cleanup() {
107+
108+
parent.notifyCalcFinished();
109+
parent=null;
110+
structures = null;
111+
names = null;
112+
}
113+
114+
@Override
115+
public void setNrCPUs(int useNrCPUs) {
116+
// TODO Auto-generated method stub
117+
}
118+
}

0 commit comments

Comments
 (0)