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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#setVersion() . 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: FatCatFlexible.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2) throws StructureException {

	AFPChain afpChain = alignFlexible(ca1, ca2, params);
	afpChain.setAlgorithmName(algorithmName);
	afpChain.setVersion(VERSION+"");
	return afpChain;
}
 
Example 2
Source File: FatCatFlexible.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2, Object param)
throws StructureException {

	if ( ! (param instanceof FatCatParameters)){
		throw new IllegalArgumentException("FatCat algorithm needs FatCatParameters object as argument.");
	}

	params = (FatCatParameters) param;

	AFPChain afpChain= alignFlexible(ca1, ca2, params);
	afpChain.setAlgorithmName(algorithmName);
	afpChain.setVersion(VERSION+"");
	return afpChain;
}
 
Example 3
Source File: FatCat.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AFPChain alignRigid(Atom[] ca1, Atom[] ca2, FatCatParameters params) throws StructureException{

		AFPChain afpChain = align(ca1,ca2,params,true);
		afpChain.setAlgorithmName(FatCatRigid.algorithmName);
		afpChain.setVersion(VERSION+"");
		return afpChain;
	}
 
Example 4
Source File: FatCat.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AFPChain alignFlexible(Atom[] ca1, Atom[] ca2, FatCatParameters params) throws StructureException{

		AFPChain afpChain = align(ca1,ca2,params,false);
		afpChain.setAlgorithmName(FatCatFlexible.algorithmName);
		afpChain.setVersion(VERSION+"");
		return afpChain;
	}
 
Example 5
Source File: FatCatRigid.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2) throws StructureException {

	AFPChain afpChain = alignRigid(ca1, ca2, params);
	afpChain.setAlgorithmName(algorithmName);
	afpChain.setVersion(VERSION+"");
	return afpChain;
}
 
Example 6
Source File: FatCatRigid.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2, Object param)
throws StructureException {

	if ( ! (param instanceof FatCatParameters)){
		throw new IllegalArgumentException("FatCat algorithm needs FatCatParameters object as argument.");
	}

	params = (FatCatParameters) param;

	AFPChain afpChain= alignRigid(ca1, ca2, params);
	afpChain.setAlgorithmName(algorithmName);
	afpChain.setVersion(VERSION+"");
	return afpChain;
}
 
Example 7
Source File: CeSymm.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static Matrix align(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
		CESymmParameters params, Matrix origM, CECalculator calculator,
		int counter) throws StructureException {

	int fragmentLength = params.getWinSize();
	Atom[] ca2clone = StructureTools.cloneAtomArray(ca2);

	int rows = ca1.length;
	int cols = ca2.length;

	// Matrix that tracks similarity of a fragment of length fragmentLength
	// starting a position i,j.

	int blankWindowSize = fragmentLength;
	if (origM == null) {

		// Build alignment ca1 to ca2-ca2
		afpChain = calculator.extractFragments(afpChain, ca1, ca2clone);

		origM = SymmetryTools.blankOutPreviousAlignment(afpChain, ca2,
				rows, cols, calculator, null, blankWindowSize);

	} else {
		// we are doing an iteration on a previous alignment
		// mask the previous alignment
		origM = SymmetryTools.blankOutPreviousAlignment(afpChain, ca2,
				rows, cols, calculator, origM, blankWindowSize);
	}

	Matrix clone = (Matrix) origM.clone();

	// that's the matrix to run the alignment on..
	calculator.setMatMatrix(clone.getArray());

	calculator.traceFragmentMatrix(afpChain, ca1, ca2clone);

	final Matrix origMfinal = (Matrix) origM.clone();
	// Add a matrix listener to keep the blacked zones in max.
	calculator.addMatrixListener(new MatrixListener() {

		@Override
		public double[][] matrixInOptimizer(double[][] max) {

			// Check every entry of origM for blacked out regions
			for (int i = 0; i < max.length; i++) {
				for (int j = 0; j < max[i].length; j++) {
					if (origMfinal.getArray()[i][j] > 1e9) {
						max[i][j] = -origMfinal.getArray()[i][j];
					}
				}
			}
			return max;
		}

		@Override
		public boolean[][] initializeBreakFlag(boolean[][] brkFlag) {

			return brkFlag;
		}
	});

	calculator.nextStep(afpChain, ca1, ca2clone);

	afpChain.setAlgorithmName(algorithmName);
	afpChain.setVersion(version);

	afpChain.setDistanceMatrix(origM);

	return origMfinal;

}
 
Example 8
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 9
Source File: CeMain.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Align ca2 onto ca1.
 */
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2, Object param) throws StructureException{
	if ( ! (param instanceof CeParameters))
		throw new IllegalArgumentException("CE algorithm needs an object of call CeParameters as argument.");

	params = (CeParameters) param;

	// we don't want to rotate input atoms, do we?
	ca2clone = new Atom[ca2.length];

	int pos = 0;
	for (Atom a : ca2){
		Group g = (Group)a.getGroup().clone(); // works because each group has only a CA atom

		ca2clone[pos] = g.getAtom(a.getName());

		pos++;
	}

	calculator = new CECalculator(params);

	//Build alignment ca1 to ca2-ca2
	AFPChain afpChain = new AFPChain(algorithmName);
	afpChain = calculator.extractFragments(afpChain, ca1, ca2clone);
	calculator.traceFragmentMatrix( afpChain,ca1, ca2clone);
	calculator.nextStep( afpChain,ca1, ca2clone);

	afpChain.setAlgorithmName(getAlgorithmName());
	afpChain.setVersion(version);

	// Try to guess names

	if (ca1.length!=0 && ca1[0].getGroup().getChain()!=null && ca1[0].getGroup().getChain().getStructure()!=null)
		afpChain.setName1(ca1[0].getGroup().getChain().getStructure().getName());

	if (ca2.length!=0 && ca2[0].getGroup().getChain()!=null && ca2[0].getGroup().getChain().getStructure()!=null)
		afpChain.setName2(ca2[0].getGroup().getChain().getStructure().getName());

	if ( afpChain.getNrEQR() == 0)
	   return afpChain;

	// Set the distance matrix

	int winSize = params.getWinSize();
	int winSizeComb1 = (winSize-1)*(winSize-2)/2;
	double[][] m = calculator.initSumOfDistances(ca1.length, ca2.length, winSize, winSizeComb1, ca1, ca2clone);
	afpChain.setDistanceMatrix(new Matrix(m));
	afpChain.setSequentialAlignment(true);

	return afpChain;
}
 
Example 10
Source File: TestAFPChainConversion.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testAFPconversion() throws Exception{

	//Fill an AFPChain with the general information
	AFPChain afp = new AFPChain("algorithm");
	afp.setName1("name1");
	afp.setName2("name2");
	afp.setVersion("1.0");
	afp.setCalculationTime(System.currentTimeMillis());
	//Generate a optimal alignment with 3 blocks and 5 residues per block
	int[][][] optAln = new int[3][][];
	for (int b=0; b<optAln.length; b++){
		int[][] block = new int[2][];
		for (int c=0; c<block.length; c++){
			int[] residues = {b+5,b+6,b+7,b+8,b+9};
			block[c] = residues;
		}
		optAln[b] = block;
	}
	afp.setOptAln(optAln);
	afp.setBlockNum(optAln.length);
	//Set the rotation matrix and shift to random numbers
	double[][] mat = {{0.13,1.5,0.84},{1.3,0.44,2.3},{1.0,1.2,2.03}};
	Matrix rot = new Matrix(mat);
	Atom shift = new AtomImpl();
	shift.setX(0.44);
	shift.setY(0.21);
	shift.setZ(0.89);
	Matrix[] blockRot = {rot,rot,rot};
	afp.setBlockRotationMatrix(blockRot);
	Atom[] blockShift = {shift,shift,shift};
	afp.setBlockShiftVector(blockShift);

	//Convert the AFPChain into a MultipleAlignment (without Atoms)
	MultipleAlignmentEnsemble ensemble =
			new MultipleAlignmentEnsembleImpl(afp,null,null,true);
	MultipleAlignment msa = ensemble.getMultipleAlignment(0);

	//Test for all the information
	assertEquals(afp.getName1(),ensemble.getStructureIdentifiers().get(0).getIdentifier());
	assertEquals(afp.getName2(), ensemble.getStructureIdentifiers().get(1).getIdentifier());
	assertEquals(afp.getAlgorithmName(), ensemble.getAlgorithmName());
	assertEquals(afp.getVersion(),ensemble.getVersion());
	assertTrue(ensemble.getCalculationTime().equals(
			afp.getCalculationTime()));
	assertEquals(afp.getBlockNum(), msa.getBlockSets().size());
	for (int b = 0; b<afp.getBlockNum(); b++){
		assertEquals(Calc.getTransformation(
				afp.getBlockRotationMatrix()[b],
				afp.getBlockShiftVector()[b]),
				msa.getBlockSet(b).getTransformations().get(1));
	}

	//Test for the scores
	assertEquals(msa.getScore(MultipleAlignmentScorer.CE_SCORE),
			(Double) afp.getAlignScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.AVGTM_SCORE),
			(Double) afp.getTMScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.RMSD),
			(Double) afp.getTotalRmsdOpt());


	//Test for the optimal alignment
	for (int b=0; b<3; b++){
		for (int c=0; c<2; c++){
			for (int res=0; res<5; res++){
				Integer afpRes = afp.getOptAln()[b][c][res];
				assertEquals(afpRes, msa.getBlock(b).
						getAlignRes().get(c).get(res));
			}
		}
	}
}