Java Code Examples for org.biojava.nbio.structure.align.model.AFPChain#getCa1Length()

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#getCa1Length() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoCE.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void printScores(AFPChain afpChain) {
	System.out.println("=====================");
	System.out.println("The main scores for the alignment:");

	System.out.println("EQR       :\t" + afpChain.getNrEQR() + "\t The number of residues on structurally equivalent positions.")  ;
	System.out.println("RMSD      :\t" + String.format("%.2f",afpChain.getTotalRmsdOpt() )+ "\t The RMSD of the alignment");
	System.out.println("Z-score   :\t" + afpChain.getProbability() + "\t The Z-score of the alignment (CE)");
	System.out.println("TM-score  :\t" + String.format("%.2f",afpChain.getTMScore()) + "\t The TM-score of the alignment.");
	System.out.println("");
	System.out.println("Other scores:");
	System.out.println("Identity  :\t" + String.format("%.2f",afpChain.getIdentity())   + "\t The percent of residues that are sequence-identical in the alignment.");
	System.out.println("Similarity:\t" + String.format("%.2f",afpChain.getSimilarity()) + "\t The percent of residues in the alignment that are sequence-similar.");
	System.out.println("Coverage1 :\t" + afpChain.getCoverage1() + " %\t Percent of protein 1 that is covered with the alignment.");
	System.out.println("Coverage2 :\t" + afpChain.getCoverage2() + " %\t Percent of protein 2 that is covered with the alignment.");
	int dab = afpChain.getCa1Length()+afpChain.getCa2Length() - 2 * afpChain.getNrEQR();
	System.out.println("Distance  :\t" + dab + "\t Distance between folds a,b ");
	double sab = 2 * afpChain.getNrEQR() / (double)( afpChain.getCa1Length() + afpChain.getCa2Length());
	System.out.println("Rel. Sim. :\t" + String.format("%.2f",sab) + "\t Relative similarity");



}
 
Example 2
Source File: SigEva.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public double calSigAll(FatCatParameters params, AFPChain afpChain){

		int twist = params.getMaxTra();
		int sparse = params.getSparse();
		int len1 = afpChain.getCa1Length();
		int len2 = afpChain.getCa2Length();
		double score = afpChain.getAlignScore();
		double rmsd = afpChain.getTotalRmsdOpt();
		int optLen = afpChain.getOptLength();
		int r = afpChain.getBlockNum() -1;

		return calSigAll(twist,sparse,len1, len2,score,rmsd,optLen,r);

	}
 
Example 3
Source File: SigEva.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public double calNS(FatCatParameters params, AFPChain afpChain){
	int len1 = afpChain.getCa1Length();
	int len2 = afpChain.getCa2Length();
	double score =afpChain.getAlignScore();
	double rmsd = afpChain.getTotalRmsdOpt();
	int optLen  = afpChain.getOptLength();
	int r = afpChain.getBlockNum() -1;
	return calNS(len1, len2,score,rmsd,optLen,r);
}
 
Example 4
Source File: AFPChainXMLParser.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**  replace the PDB res nums with atom positions:
 *
 * @param afpChain
 * @param ca1
 * @param ca2
 */
public static void rebuildAFPChain(AFPChain afpChain, Atom[] ca1, Atom[] ca2){

	if ( afpChain.getAlgorithmName() == null) {
		afpChain.setAlgorithmName(DEFAULT_ALGORITHM_NAME);
	}
	if ( afpChain.getVersion() == null){
		afpChain.setVersion("1.0");
	}

	int blockNum  = afpChain.getBlockNum();
	int ca1Length = afpChain.getCa1Length();
	int ca2Length = afpChain.getCa2Length();

	int minLength = Math.min(ca1Length, ca2Length);
	int[][][] optAln = new int[blockNum][2][minLength];

	int[][][] blockResList = afpChain.getBlockResList();
	if ( blockResList == null){
		blockResList = new int[blockNum][2][minLength];
	}
	int[] optLen = afpChain.getOptLen();

	String[][][] pdbAln = afpChain.getPdbAln();
	int[] verifiedOptLen = null;
	if ( optLen != null)
	  verifiedOptLen = afpChain.getOptLen().clone();
	else {
		logger.warn("did not find optimal alignment, building up empty alignment.");
		optLen = new int[1];
		optLen[0] = 0;
	}
	for (int blockNr = 0 ; blockNr < blockNum ; blockNr++){

		//System.out.println("got block " + blockNr + " size: " + optLen[blockNr]);
		int verifiedEQR = -1;
		for ( int eqrNr = 0 ; eqrNr < optLen[blockNr] ; eqrNr++ ){
			String pdbResnum1 = pdbAln[blockNr][0][eqrNr];
			String pdbResnum2 = pdbAln[blockNr][1][eqrNr];

			//System.out.println(blockNr + " " + eqrNr + " got resnum: " + pdbResnum1 + " " + pdbResnum2);
			String[] spl1 = pdbResnum1.split(":");
			String[] spl2 = pdbResnum2.split(":");

			String chain1 = spl1[0];
			String pdbres1 = spl1[1];

			String chain2 = spl2[0];
			String pdbres2 = spl2[1];

			int pos1 = getPositionForPDBresunm(pdbres1,chain1,ca1);
			int pos2 = getPositionForPDBresunm(pdbres2,chain2,ca2);

			if ( pos1 == -1 || pos2 == -1 ){
				// this can happen when parsing old files that contained Calcium atoms...
				logger.warn("pos1: {} (residue {}), pos2: {} (residue {}), should never be -1. Probably parsing an old file.",
						pos1, pdbResnum1, pos2, pdbResnum2);
				verifiedOptLen[blockNr]-- ;
				continue;
			}

			verifiedEQR++;
			//System.out.println(blockNr + " " + eqrNr + " " + pos1 + " " + pos2);
			optAln[blockNr][0][verifiedEQR] = pos1;
			optAln[blockNr][1][verifiedEQR] = pos2;
			blockResList[blockNr][0][verifiedEQR] = pos1;
			blockResList[blockNr][1][verifiedEQR] = pos2;
		}
	}

	afpChain.setOptLen(verifiedOptLen);
	afpChain.setOptAln(optAln);
	afpChain.setBlockResList(blockResList);
	// build up alignment image:
	AFPAlignmentDisplay.getAlign(afpChain, ca1, ca2);


}
 
Example 5
Source File: CeCPMain.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Swaps the order of structures in an AFPChain
 * @param a
 * @return
 */
public AFPChain invertAlignment(AFPChain a) {
	String name1 = a.getName1();
	String name2 = a.getName2();
	a.setName1(name2);
	a.setName2(name1);

	int len1 = a.getCa1Length();
	a.setCa1Length( a.getCa2Length() );
	a.setCa2Length( len1 );

	int beg1 = a.getAlnbeg1();
	a.setAlnbeg1(a.getAlnbeg2());
	a.setAlnbeg2(beg1);

	char[] alnseq1 = a.getAlnseq1();
	a.setAlnseq1(a.getAlnseq2());
	a.setAlnseq2(alnseq1);

	Matrix distab1 = a.getDisTable1();
	a.setDisTable1(a.getDisTable2());
	a.setDisTable2(distab1);

	int[] focusRes1 = a.getFocusRes1();
	a.setFocusRes1(a.getFocusRes2());
	a.setFocusRes2(focusRes1);

	//What are aftIndex and befIndex used for? How are they indexed?
	//a.getAfpAftIndex()


	String[][][] pdbAln = a.getPdbAln();
	if( pdbAln != null) {
		for(int block = 0; block < a.getBlockNum(); block++) {
			String[] paln1 = pdbAln[block][0];
			pdbAln[block][0] = pdbAln[block][1];
			pdbAln[block][1] = paln1;
		}
	}

	int[][][] optAln = a.getOptAln();
	if( optAln != null ) {
		for(int block = 0; block < a.getBlockNum(); block++) {
			int[] aln1 = optAln[block][0];
			optAln[block][0] = optAln[block][1];
			optAln[block][1] = aln1;
		}
	}
	a.setOptAln(optAln); // triggers invalidate()

	Matrix distmat = a.getDistanceMatrix();
	if(distmat != null)
		a.setDistanceMatrix(distmat.transpose());


	// invert the rotation matrices
	Matrix[] blockRotMat = a.getBlockRotationMatrix();
	Atom[] shiftVec = a.getBlockShiftVector();
	if( blockRotMat != null) {
		for(int block = 0; block < a.getBlockNum(); block++) {
			if(blockRotMat[block] != null) {
				// if y=x*A+b, then x=y*inv(A)-b*inv(A)
				blockRotMat[block] = blockRotMat[block].inverse();

				Calc.rotate(shiftVec[block],blockRotMat[block]);
				shiftVec[block] = Calc.invert(shiftVec[block]);
			}
		}
	}

	return a;
}
 
Example 6
Source File: AFPTwister.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * superimposing according to the optimized alignment
 *
 * @param afpChain
 * @param ca1
 * @param ca2
 * @return Group array twisted.
 * @throws StructureException
 */
public static Group[] twistOptimized(AFPChain afpChain, Atom[] ca1,
		Atom[] ca2) throws StructureException {

	Atom[] optTwistPdb = new Atom[ca2.length];

	int gPos = -1;
	for (Atom a : ca2) {
		gPos++;
		optTwistPdb[gPos] = a;
	}

	int blockNum = afpChain.getBlockNum();

	int b2 = 0;
	int e2 = 0;
	int focusResn = 0;
	int[] focusRes1 = afpChain.getFocusRes1();
	int[] focusRes2 = afpChain.getFocusRes2();

	if (focusRes1 == null) {
		focusRes1 = new int[afpChain.getCa1Length()];
		afpChain.setFocusRes1(focusRes1);
	}
	if (focusRes2 == null) {
		focusRes2 = new int[afpChain.getCa2Length()];
		afpChain.setFocusRes2(focusRes2);
	}

	int[] optLen = afpChain.getOptLen();
	int[][][] optAln = afpChain.getOptAln();

	for (int bk = 0; bk < blockNum; bk++) {
		// THIS IS TRANSFORMING THE ORIGINAL ca2 COORDINATES, NO CLONING...
		// copies the atoms over to iniTwistPdb later on in modifyCod
		transformOrigPDB(optLen[bk], optAln[bk][0], optAln[bk][1], ca1,
				ca2, afpChain, bk);

		// transform pro2 according to comparison of pro1 and pro2 at give
		// residues
		if (bk > 0) {
			b2 = e2;
		}
		if (bk < blockNum - 1) { // bend at the middle of two consecutive
									// blocks
			e2 = optAln[bk][1][optLen[bk] - 1];
			e2 = (optAln[bk + 1][1][0] - e2) / 2 + e2;
		} else {
			e2 = ca2.length;
		}
		cloneAtomRange(optTwistPdb, ca2, b2, e2);
		for (int i = 0; i < optLen[bk]; i++) {
			focusRes1[focusResn] = optAln[bk][0][i];
			focusRes2[focusResn] = optAln[bk][1][i];
			focusResn++;
		}
	}
	int totalLenOpt = focusResn;
	logger.debug("calrmsdopt for {} residues", focusResn);
	double totalRmsdOpt = calCaRmsd(ca1, optTwistPdb, focusResn, focusRes1,
			focusRes2);
	logger.debug("got opt RMSD: {}", totalRmsdOpt);
	int optLength = afpChain.getOptLength();

	if (totalLenOpt != optLength) {
		logger.warn("Final alignment length is different {} {}",
				totalLenOpt, optLength);
	}
	logger.debug("final alignment length {}, rmsd {}", focusResn,
			totalRmsdOpt);

	afpChain.setTotalLenOpt(totalLenOpt);
	afpChain.setTotalRmsdOpt(totalRmsdOpt);

	return StructureTools.cloneGroups(optTwistPdb);

}
 
Example 7
Source File: DotPlotPanel.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 *
 * @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<int[]> alignPairs = new ArrayList<int[]>();
		for(int pos = 0; pos<optAln[alignNumber][0].length; pos++ ) {
			alignPairs.add( new int[] {
					optAln[alignNumber][0][pos],
					optAln[alignNumber][1][pos] }
			);
		}
		JointFragments frag = new JointFragments();
		frag.setIdxlist(alignPairs);
		aligns[alignNumber] = new AlternativeAlignment();
		aligns[alignNumber].apairs_from_idxlst(frag);

	}

	/* TODO After the AFPSet is fixed in CeMain#filterDuplicateAFPs, maybe include this again
	//add alignment for the AFPs
	List<AFP> afps = alignment.getAfpSet();
	List<int[]> alignPairs = new ArrayList<int[]>();
	for(AFP afp : afps) {
		int start1 = afp.getP1();
		int start2 = afp.getP2();
		for(int i=0;i<afp.getFragLen();i++) {
			alignPairs.add( new int[] { start1+i, start2+i } );
		}
	}
	JointFragments frag = new JointFragments();
	frag.setIdxlist(alignPairs);
	aligns[alignNumber] = new AlternativeAlignment();
	aligns[alignNumber].apairs_from_idxlst(frag);
	*/


	/* AFP boxes are unnecessary.
	// Calculate FragmentPairs based on alignment.
	// These are displayed as a small box around the start of each alignment.
	FragmentPair[] pairs = new FragmentPair[afps.size()];
	for(int i=0;i<pairs.length;i++) {
		AFP afp = afps.get(i);
		pairs[i] = new FragmentPair(afp.getFragLen(), afp.getP1(), afp.getP2());
		pairs[i].setRms(afp.getRmsd());
	}

	this.setFragmentPairs(pairs);
	*/


	// Now the alignments have been build; add it
	this.setAlternativeAligs(aligns);
	this.setSelectedAlignmentPos(0); //color white, not red

	Matrix background = alignment.getDistanceMatrix();
	//Fill with default black background if none given
	if(background == null) {
		background = new Matrix(alignment.getCa1Length(),alignment.getCa2Length());
		for(int i=0;i<background.getRowDimension();i++)
			for(int j=0;j<background.getColumnDimension(); j++) {
				background.set(i, j, defaultBackground);
			}
	}

	// Set parameters
	this.setMatrix(background);
}