All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.biojava.nbio.structure.align.gui.DotPlotPanel Maven / Gradle / Ivy

/*
 *                    PDB web development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 *
 * Created on Jul 28, 2009
 * Created by ap3
 *
 */

package org.biojava.nbio.structure.align.gui;

import org.biojava.nbio.structure.Atom;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.align.StructureAlignmentFactory;
import org.biojava.nbio.structure.align.ce.CeCPMain;
import org.biojava.nbio.structure.align.ce.CeMain;
import org.biojava.nbio.structure.align.ce.CeParameters;
import org.biojava.nbio.structure.align.helper.JointFragments;
import org.biojava.nbio.structure.align.model.AFP;
import org.biojava.nbio.structure.align.model.AFPChain;
import org.biojava.nbio.structure.align.pairwise.AlternativeAlignment;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.gui.ScaleableMatrixPanel;
import org.biojava.nbio.structure.jama.Matrix;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Displays the dot plot trace for an alignment.
 *
 * This class adapts ScaleableMatrixPanel, which uses code from org.biojava.nbio.structure.align.pairwise,
 * with more BioJava-friendly methods based off AFPChains.
 *
 * @author Spencer Bliven
 *
 */
public class DotPlotPanel extends ScaleableMatrixPanel {

	private static final long serialVersionUID = -7641953255857483895L;

	/**
	 *
	 * @param alignment The alignment to plot
	 * @param background [Optional]A matrix of 'background colors' over which to draw the alignment.
	 *
	 *	Originally designed as a matrix of RMSD values between AFPs, so it is colorized
	 *	accordingly from red (0) to black (>10).
	 *
	 *  If this set to null, the background is set to black.
	 */
	public DotPlotPanel(AFPChain alignment ){
		super();

		final double defaultBackground = 100.;

		// Convert the AFPChain alignment into the MatrixPanel format
		AlternativeAlignment[] aligns = new AlternativeAlignment[alignment.getBlockNum()];
		int alignNumber = 0;

		//One alternative alignment for each block
		int[][][] optAln = alignment.getOptAln(); // [block #][{0,1} chain index][pos]

		for(;alignNumber < optAln.length;alignNumber++) {
			List alignPairs = new ArrayList();
			for(int pos = 0; pos afps = alignment.getAfpSet();
		List alignPairs = new ArrayList();
		for(AFP afp : afps) {
			int start1 = afp.getP1();
			int start2 = afp.getP2();
			for(int i=0;imax)
						max = y;
				}
			}
			System.out.format("[%f, %f]\n", min, max);
			*/

			//afpChain.setDistanceMatrix(mat);
			showDotPlotJFrame(afpChain);

			//StructureAlignmentJmol jmol = new StructureAlignmentJmol(afpChain, ca1, ca2);
//			jmol.setStructure(cache.getStructure(name1));


			//////////////////////////
			// Now make it circular
			ceA = (CeMain) StructureAlignmentFactory.getAlgorithm(CeCPMain.algorithmName);

			System.out.format("Aligning %s[%d] with %s[%d] with CPs\n",name1,ca1.length,name2,ca2.length);
			afpChain = ceA.align(ca1,ca2);
			afpChain.setName1(name1);
			afpChain.setName2(name2+"-"+name2);
			for ( AFP afpI : afpChain.getAfpSet()){
				System.out.println(afpI);
			}

			/*/ Reuse mat from the non-cp case, for simplicity

			// Get background distances
			Atom[] ca2clone = new Atom[ca2.length*2];
			int pos = 0;
			for (Atom a : ca2){
				Group g = (Group)a.getParent().clone(); // works because each group has only a CA atom

				ca2clone[pos] = g.getAtom(StructureTools.caAtomName);

				pos++;
			}
			for (Atom a : ca2){
				Group g = (Group)a.getParent().clone();

				ca2clone[pos] = g.getAtom(StructureTools.caAtomName);

				pos++;
			}
			m = calculator.initSumOfDistances(ca1.length, ca2clone.length, params.getWinSize(), winSizeComb1, ca1, ca2clone);
			//m = calculator.getMatMatrix();
			mat = new Matrix(m);/*ca2.length,ca1.length);
			for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy