001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on Jul 16, 2006 021 * 022 */ 023package org.biojava.nbio.structure.gui.util; 024 025 026import org.biojava.nbio.structure.Structure; 027import org.biojava.nbio.structure.StructureException; 028import org.biojava.nbio.structure.align.ClusterAltAligs; 029import org.biojava.nbio.structure.align.StructurePairAligner; 030import org.biojava.nbio.structure.align.gui.AlignmentGui; 031import org.biojava.nbio.structure.align.pairwise.AlternativeAlignment; 032import org.slf4j.Logger; 033import org.slf4j.LoggerFactory; 034 035 036 037/** A class that obtains two structures via DAS and aligns them 038 * This is done in a separate thread. 039 * It is possible to register Event listeners to get notification of when the download has finished. 040 * 041 * @author Andreas Prlic 042 * @since 1.7 043 * @version %I% %G% 044 */ 045public class AlignmentCalc implements Runnable { 046 047 048 private static final Logger logger = LoggerFactory.getLogger(AlignmentCalc.class); 049 050 boolean interrupted = false; 051 052 String pdb1; 053 String pdb2; 054 String chain1; 055 String chain2; 056 057 Structure structure1; 058 Structure structure2; 059 060 AlignmentGui parent; 061 062 063 /** requests an alignment of pdb1 vs pdb 2. 064 * Chain 1 and chain2 are optional. 065 * If they are empty strings, they are ignored 066 * @param parent the alignment gui frame that interacts with this class 067 * @param s1 structure 1 068 * @param s2 structure 2 069 */ 070 public AlignmentCalc(AlignmentGui parent, Structure s1, Structure s2 ) { 071 072 this.parent= parent; 073 074 structure1 = s1; 075 structure2 = s2; 076 077 } 078 079 @Override 080 public void run() { 081 082 // both structure have been downloaded, now calculate the alignment ... 083 084 085 StructurePairAligner aligner = new StructurePairAligner(); 086 087 try { 088 aligner.align(structure1,structure2); 089 } catch (StructureException e){ 090 logger.warn(e.getMessage()); 091 092 } 093 094 095 096 AlternativeAlignment[] aligs = aligner.getAlignments(); 097 //cluster similar results together 098 ClusterAltAligs.cluster(aligs); 099 showAlignment(aligner,aligs); 100 101 //logger.info("done!"); 102 103 parent.notifyCalcFinished(); 104 105 } 106 107 108 109 private void showAlignment(StructurePairAligner alignment, AlternativeAlignment[] aligs) { 110 AlternativeAlignmentFrame frame = new AlternativeAlignmentFrame(structure1, structure2); 111 frame.setStructurePairAligner(alignment); 112 frame.setAlternativeAlignments(aligs); 113 frame.pack(); 114 frame.setVisible(true); 115 116 117 118 } 119 120 /** stops what is currently happening and does not continue 121 * 122 * 123 */ 124 public void interrupt() { 125 interrupted = true; 126 } 127 128 public void cleanup() { 129 130 parent.notifyCalcFinished(); 131 132 parent=null; 133 // cleanup... 134 135 structure1 = null; 136 structure2 = null; 137 138 } 139 140 141 142} 143 144 145 146