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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#setName1() . 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: AFPChainSerialisationTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AFPChain doAlign(String name1, String name2, Atom[] ca1, Atom[] ca2 , boolean doRigid) throws StructureException,IOException{
	FatCatParameters params = new FatCatParameters();

	FatCat fatCat = new FatCat();
	AFPChain afpChain;
	if ( doRigid)
		afpChain = fatCat.alignRigid(ca1,ca2,params);
	else
		afpChain = fatCat.alignFlexible(ca1,ca2,params);

	afpChain.setName1(name1);
	afpChain.setName2(name2);
	return afpChain;

}
 
Example 2
Source File: FarmJobRunnable.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String alignPair(String name1, String name2, String algorithmName)
	throws StructureException, IOException {

	// 	make sure each thread has an independent instance of the algorithm object ...

	StructureAlignment algorithm = getAlgorithm(algorithmName);

	// we are running with default parameters

	if ( verbose ) {
		logger.debug("aligning {} against {}", name1, name2);
	}

	long startTime = System.currentTimeMillis();

	if ( prevName1 == null)
		initMaster(name1);

	if ( ! prevName1.equals(name1) ) {
		// we need to reload the master
		initMaster(name1);
	}

	// get a copy of the atoms, but clone them, since they will be rotated...
	Atom[] ca2 =  cache.getAtoms(name2);

	AFPChain afpChain = algorithm.align(ca1, ca2);

	afpChain.setName1(name1);
	afpChain.setName2(name2);

	try {
		// add tmScore
		double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2);
		afpChain.setTMScore(tmScore);
	} catch (RuntimeException e){
		logger.error("ca1 size: {} ca2 length: {} {}  {}", ca1.length, ca2.length, afpChain.getName1(), afpChain.getName2(), e);

	}
	long endTime = System.currentTimeMillis();

	long calcTime = (endTime-startTime);
	if ( verbose ){
		boolean isCP = !AlignmentTools.isSequentialAlignment(afpChain, false);
		String msg = "finished alignment: " + name1 + " vs. " + name2 + " in " + (calcTime) / 1000.0 + " sec.";
		msg += " algo: " + algorithmName + " v:" + version + " " + afpChain;

		if ( isCP ) msg += "HAS A CIRCULAR PERMUTATION!!!";
		logger.debug(msg);
	}
	if (verbose){
		printMemory();
	}
	afpChain.setCalculationTime(calcTime);

	return AFPChainXMLConverter.toXML(afpChain, ca1, ca2);
}
 
Example 3
Source File: FlipAFPChainTest.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void align (StructureAlignment algorithm, String name1, String name2)
		throws StructureException, IOException{


	AtomCache cache = new AtomCache();
	Atom[] ca1 = cache.getAtoms(name1);
	Atom[] ca2 = cache.getAtoms(name2);


	AFPChain afpChain = algorithm.align(ca1,ca2);
	afpChain.setName1(name1);
	afpChain.setName2(name2);
	double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2);
	afpChain.setTMScore(tmScore);

	String xml = AFPChainXMLConverter.toXML(afpChain, ca1, ca2);

	AFPChain newC    = AFPChainXMLParser.fromXML(xml, ca1, ca2);
	//System.out.println(xml);
	//System.out.println(AFPChainXMLConverter.toXML(newC));
	AFPChain flipped = AFPChainFlipper.flipChain(newC);

	Assert.assertEquals(afpChain.getName1(), flipped.getName2());
	Assert.assertEquals(afpChain.getName2(), flipped.getName1());
	Assert.assertEquals(afpChain.getCa1Length(), flipped.getCa2Length());
	Assert.assertEquals(afpChain.getCa2Length(), flipped.getCa1Length());
	Assert.assertEquals(String.format("%.2f", afpChain.getTMScore()), String.format("%.2f", flipped.getTMScore()));
	Assert.assertTrue(afpChain.getTMScore() != -1);

	String xmlNew = AFPChainXMLConverter.toXML(flipped, ca2, ca1);
	//System.out.println(xmlNew);
	AFPChain backChain = AFPChainXMLParser.fromXML(xmlNew, ca2, ca1);
	AFPChain origFlip  = AFPChainFlipper.flipChain(backChain);

	Assert.assertNotNull("Got null, instead of an AFPChain object!", origFlip);

	Assert.assertNotNull("could not get nr. of eqr: ", afpChain.getNrEQR());
	Assert.assertNotNull("could not get nr. of eqr: ", origFlip.getNrEQR());

	Assert.assertTrue("The nr. of equivalent positions is not equal!", afpChain.getNrEQR() == origFlip.getNrEQR());

	Atom shift1 = afpChain.getBlockShiftVector()[0];
	Atom shift2 = origFlip.getBlockShiftVector()[0];

	Assert.assertTrue("The shift vectors are not similar!", Calc.getDistance(shift1, shift2) < 0.1);

	//assert the RMSD in the flipped alignment is small
	double rmsd1 = getRMSD(afpChain,ca1,ca2);
	double rmsd2 = getRMSD(flipped,ca2,ca1);
	//System.out.println("rmsd:" +rmsd1 + " " + rmsd2);
	Assert.assertTrue("The RMSD are vastly different!", Math.abs(rmsd1 - rmsd2) < 0.01);


	// this can;t work any more because there is minor after comma mismatches..
	//String xmlBack = AFPChainXMLConverter.toXML(origFlip);
	//if ( ! xmlBack.equals(xml)){
	//	printFirstMismatch(xmlBack, xml);
	//}
	//assertEquals("The alignment representations are not the same!" , xmlBack, xml);
	AFPAlignmentDisplay.getAlign(origFlip, ca1, ca2);
	String img1 = AfpChainWriter.toDBSearchResult(afpChain);
	String img2 = AfpChainWriter.toDBSearchResult(origFlip);
	Assert.assertEquals("The alignment images do not match!", img1, img2);

	//System.out.println(xml);
	//System.out.println(xmlNew);



}
 
Example 4
Source File: AbstractUserArgumentProcessor.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void runAlignPairs(AtomCache cache, String alignPairs,
		String outputFile) {
	try {
		File f = new File(alignPairs);

		BufferedReader is = new BufferedReader (new InputStreamReader(new FileInputStream(f)));

		BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true));

		StructureAlignment algorithm =  getAlgorithm();

		String header = "# algorithm:" + algorithm.getAlgorithmName();
		out.write(header);
		out.write(newline);

		out.write("#Legend: " + newline );
		String legend = getDbSearchLegend();
		out.write(legend + newline );
		System.out.println(legend);
		String line = null;
		while ( (line = is.readLine()) != null){
			if ( line.startsWith("#"))
				continue;

			String[] spl = line.split(" ");

			if ( spl.length != 2) {
				System.err.println("wrongly formattted line. Expected format: 4hhb.A 4hhb.B but found " + line);
				continue;
			}

			String pdb1 = spl[0];
			String pdb2 = spl[1];


			Structure structure1 = cache.getStructure(pdb1);
			Structure structure2 = cache.getStructure(pdb2);

			Atom[] ca1;
			Atom[] ca2;


			ca1 = StructureTools.getRepresentativeAtomArray(structure1);
			ca2 = StructureTools.getRepresentativeAtomArray(structure2);

			Object jparams = getParameters();

			AFPChain afpChain;

			afpChain = algorithm.align(ca1, ca2, jparams);
			afpChain.setName1(pdb1);
			afpChain.setName2(pdb2);

			String result = getDbSearchResult(afpChain);
			out.write(result);
			System.out.print(result);

			checkWriteFile(afpChain,ca1,ca2,true);
		}

		out.close();
		is.close();
	} catch(Exception e){
		e.printStackTrace();
	}
}
 
Example 5
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 6
Source File: AlignmentTools.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Fundamentally, an alignment is just a list of aligned residues in each
 * protein. This method converts two lists of ResidueNumbers into an
 * AFPChain.
 *
 * <p>Parameters are filled with defaults (often null) or sometimes
 * calculated.
 *
 * <p>For a way to modify the alignment of an existing AFPChain, see
 * {@link AlignmentTools#replaceOptAln(AFPChain, Atom[], Atom[], Map)}
 * @param ca1 CA atoms of the first protein
 * @param ca2 CA atoms of the second protein
 * @param aligned1 A list of aligned residues from the first protein
 * @param aligned2 A list of aligned residues from the second protein.
 *  Must be the same length as aligned1.
 * @return An AFPChain representing the alignment. Many properties may be
 *  null or another default.
 * @throws StructureException if an error occured during superposition
 * @throws IllegalArgumentException if aligned1 and aligned2 have different
 *  lengths
 * @see AlignmentTools#replaceOptAln(AFPChain, Atom[], Atom[], Map)
 */
public static AFPChain createAFPChain(Atom[] ca1, Atom[] ca2,
									  ResidueNumber[] aligned1, ResidueNumber[] aligned2 ) throws StructureException {
	//input validation
	int alnLen = aligned1.length;
	if(alnLen != aligned2.length) {
		throw new IllegalArgumentException("Alignment lengths are not equal");
	}

	AFPChain a = new AFPChain(AFPChain.UNKNOWN_ALGORITHM);
	try {
		a.setName1(ca1[0].getGroup().getChain().getStructure().getName());
		if(ca2[0].getGroup().getChain().getStructure() != null) {
			// common case for cloned ca2
			a.setName2(ca2[0].getGroup().getChain().getStructure().getName());
		}
	} catch(Exception e) {
		// One of the structures wasn't fully created. Ignore
	}
	a.setBlockNum(1);
	a.setCa1Length(ca1.length);
	a.setCa2Length(ca2.length);

	a.setOptLength(alnLen);
	a.setOptLen(new int[] {alnLen});


	Matrix[] ms = new Matrix[a.getBlockNum()];
	a.setBlockRotationMatrix(ms);
	Atom[] blockShiftVector = new Atom[a.getBlockNum()];
	a.setBlockShiftVector(blockShiftVector);

	String[][][] pdbAln = new String[1][2][alnLen];
	for(int i=0;i<alnLen;i++) {
		pdbAln[0][0][i] = aligned1[i].getChainName()+":"+aligned1[i];
		pdbAln[0][1][i] = aligned2[i].getChainName()+":"+aligned2[i];
	}

	a.setPdbAln(pdbAln);

	// convert pdbAln to optAln, and fill in some other basic parameters
	AFPChainXMLParser.rebuildAFPChain(a, ca1, ca2);

	return a;

	// Currently a single block. Split into several blocks by sequence if needed
	//		return AlignmentTools.splitBlocksByTopology(a,ca1,ca2);
}
 
Example 7
Source File: CallableStructureAlignment.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public AFPChain call() throws Exception {

	//Prepare the alignment algorithm
	StructureAlignment algorithm = StructureAlignmentFactory.getAlgorithm(algorithmName);
	if (params!=null) algorithm.setParameters(params);

	AFPChain afpChain = null;
	try {
		//Download the Atoms if they are not provided from the outisde (DB searches usually)
		if (ca1 == null) {
			Structure structure1 = cache.getStructure(pair.getName1());
			ca1 =  StructureTools.getRepresentativeAtomArray(structure1);
		} else ca1 = StructureTools.cloneAtomArray(ca1);

		Structure structure2 = null;
		if (ca2 == null) {
			structure2 = cache.getStructure(pair.getName2());
			ca2 = StructureTools.getRepresentativeAtomArray(structure2);
		} else ca2 = StructureTools.cloneAtomArray(ca2);

		afpChain = algorithm.align(ca1, ca2);

		if (pair!=null){
			afpChain.setName1(pair.getName1());
			afpChain.setName2(pair.getName2());
		}

		//Do not output anything if there is no File information
		if (outFile != null && outFileDir != null){
			String desc2 = structure2.getPDBHeader().getDescription();
			if ( desc2 == null)
				desc2="";
			afpChain.setDescription2(desc2);
			String result = afpChain.toDBSearchResult();
			logger.info("{}", result);

			outFile.write(result);

			String xml = AFPChainXMLConverter.toXML(afpChain, ca1, ca2);
			writeXML(outFileDir,pair.getName1(), pair.getName2(), xml);
		}

	} catch ( Exception e){
		logger.error("Exception: ", e);
	}
	return afpChain;
}
 
Example 8
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));
			}
		}
	}
}
 
Example 9
Source File: TestWebStartClient.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("unused")
private void align(String name1, String name2, StructureAlignment algorithm)
throws StructureException, IOException {
	if ( algorithm.getAlgorithmName().startsWith("Smith")) {
		System.err.println("not testing SW, no need to run that on server...");
		return;
	}

	//System.out.println("testing " + name1 + " " + name2 + " " + algorithm.getAlgorithmName());
	AtomCache cache = new AtomCache();


	Atom[] ca1 = cache.getAtoms(name1);
	Atom[] ca2 = cache.getAtoms(name2);


	AFPChain afpChain = algorithm.align(ca1,ca2);
	afpChain.setName1(name1);
	afpChain.setName2(name2);

	Assert.assertNotNull(afpChain);
	Assert.assertNotNull(afpChain.getAlgorithmName());
	Assert.assertTrue(afpChain.getAlgorithmName().equals(algorithm.getAlgorithmName()));

	String xml = AFPChainXMLConverter.toXML(afpChain,ca1,ca2);

	/// SERVER part
	String serverLocation = "http://beta.rcsb.org/pdb/rest/";
	AFPChain afpServer = JFatCatClient.getAFPChainFromServer(serverLocation,algorithm.getAlgorithmName(), name1, name2, ca1, ca2, 5000);
	Assert.assertNotNull(afpServer);

	Assert.assertTrue("Algorithm names don't match!", afpServer.getAlgorithmName().equals(algorithm.getAlgorithmName()));
	Assert.assertTrue("Alignment blockNum < 1", afpServer.getBlockNum() >= 1);

	String xml2 = AFPChainXMLConverter.toXML(afpServer, ca1, ca2);
	//System.err.println(" tmp disabled comparison of server and client XML, a minor rounding diff...");
	Assert.assertEquals("The server and the locally calculated XML representations don;t match!", xml, xml2);

	AFPChain afpFlip = AFPChainFlipper.flipChain(afpChain);
	String xmlFlipped = AFPChainXMLConverter.toXML(afpFlip, ca2, ca1);
	//System.out.println(xmlFlipped);
	AFPChain fromXmlFlipped = AFPChainXMLParser.fromXML(xmlFlipped, ca2, ca1);
	Assert.assertEquals("The alignment lengths don't match", afpFlip.getNrEQR(), fromXmlFlipped.getNrEQR());

	String xmlFromFlippled = AFPChainXMLConverter.toXML(fromXmlFlipped,ca2,ca1);
	Assert.assertEquals("The XML of the flipped and the recreated from that XML don't match!", xmlFlipped, xmlFromFlippled);

	AFPChain afpBackToOrig = AFPChainFlipper.flipChain(fromXmlFlipped);
	//String xml5 = AFPChainXMLConverter.toXML(afpBackToOrig, ca1, ca2);
	// ok in the double flipping there are some minor after comma mismatches.

	String xmlShortOrig = getShortXML(afpChain,ca1, ca2);
	String xmlShortFinal = getShortXML(afpBackToOrig, ca1, ca2);
	Assert.assertEquals("The 2 x flipped alignment does not match the original", xmlShortOrig, xmlShortFinal);




}
 
Example 10
Source File: TestFlexibleRotationMatrices.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private AFPChain getAlignment (String name1, String name2, Atom[] ca1, Atom[] ca2 , boolean doRigid) throws StructureException,IOException{
	FatCatParameters params = new FatCatParameters();

	StructureAlignment fatCat ;

	if ( doRigid)
		fatCat = new FatCatRigid();
	else
		fatCat = new FatCatFlexible();

	AFPChain afpChain = fatCat.align(ca1,ca2,params);

	afpChain.setName1(name1);
	afpChain.setName2(name2);

	// flexible original results:
	//String fatcat = afpChain.toFatcat(ca1,ca2);
	//System.out.println(result1);


	//String xml = AFPChainXMLConverter.toXML(afpChain,ca1,ca2);


	return afpChain;
}
 
Example 11
Source File: FlipAFPChainTest.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
private void flip(String name1, String name2, String algorithmName) throws StructureException, IOException{

		AtomCache cache = new AtomCache();

		Structure s1 = cache.getStructure(name1);
		Structure s2 = cache.getStructure(name2);

		Atom[] ca1 = StructureTools.getRepresentativeAtomArray(s1);
		Atom[] ca2 = StructureTools.getRepresentativeAtomArray(s2);

		StructureAlignment algorithm = StructureAlignmentFactory.getAlgorithm(algorithmName );
		AFPChain afpChain = algorithm.align(ca1,ca2);
		afpChain.setName1(name1);
		afpChain.setName2(name2);

		afpChain.setCalculationTime(0);

		String xml = AFPChainXMLConverter.toXML(afpChain, ca1, ca2);

		AFPChain newC    = AFPChainXMLParser.fromXML(xml, ca1, ca2);
		AFPChain flipped = AFPChainFlipper.flipChain(newC);

		assertEquals(afpChain.getName1(), flipped.getName2());
		assertEquals(afpChain.getName2(),flipped.getName1());
		assertEquals(afpChain.getCa1Length(),flipped.getCa2Length());
		assertEquals(afpChain.getCa2Length(),flipped.getCa1Length());
		assertEquals(afpChain.getAlgorithmName(),flipped.getAlgorithmName());
		assertEquals(afpChain.getVersion(), flipped.getVersion());


		String xmlNew = AFPChainXMLConverter.toXML(flipped, ca2, ca1);

		AFPChain backChain = AFPChainXMLParser.fromXML(xmlNew, ca2, ca1);

		AFPChain origFlip  = AFPChainFlipper.flipChain(backChain);
		//AFPChainXMLParser.rebuildAFPChain(origFlip, ca1, ca2);
		origFlip.setCalculationTime(0);

		String xmlBack = AFPChainXMLConverter.toXML(origFlip);
		if ( ! xmlBack.equals(xml)){
			printFirstMismatch(xmlBack, xml);
		}


		double rmsd1 = getRMSD(afpChain,ca1,ca2);
		double rmsd2 = getRMSD(flipped,ca2,ca1);
		//System.out.println("rmsd:" +rmsd1 + " " + rmsd2);
		assertTrue("The RMSD are vastly different!", Math.abs(rmsd1-rmsd2) < 0.01);

		double rmsd3 = getRMSD(origFlip, ca1,ca2);
		assertTrue("The RMSD are vastly different!", Math.abs(rmsd1-rmsd3) < 0.01);
		//assertEquals(xmlBack, xml);



	}
 
Example 12
Source File: TestSimilarityCalc.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
@Test
public void testSimilarityDisplay(){

	String name1 = "1CDG.A";
	String name2 = "1TIM.A";

	AtomCache cache = new AtomCache();

	Structure structure1 = null;
	Structure structure2 = null;

	try {

		StructureAlignment algorithm = StructureAlignmentFactory.getAlgorithm(SmithWaterman3Daligner.algorithmName);

		SmithWaterman3DParameters params = new SmithWaterman3DParameters();

		structure1 = cache.getStructure(name1);
		structure2 = cache.getStructure(name2);

		Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
		Atom[] ca2 = StructureTools.getAtomCAArray(structure2);


		AFPChain afpChain = algorithm.align(ca1, ca2, params);

		afpChain.setName1(name1);
		afpChain.setName2(name2);


		assertTrue(afpChain.getAlnLength() == 71);

		assertTrue(afpChain.getAlnLength() == 71);
		assertTrue(afpChain.getSimilarity() > .57);
		assertTrue(afpChain.getSimilarity() <= .6);

		// this calls the internal invalidate method
		afpChain.setOptAln(afpChain.getOptAln());

		assertTrue("wrong similarity score : " + afpChain.getSimilarity(), afpChain.getSimilarity() > .57);
		assertTrue("wrong similarity score : " + afpChain.getSimilarity(), afpChain.getSimilarity() <= .6);

		assertTrue(afpChain.getSimilarity() > .58);
		assertTrue(afpChain.getSimilarity() < .59);
		assertTrue("similarity score is " + afpChain.getSimilarity()  , afpChain.getSimilarity() > .46);


	} catch (Exception e){

		fail(e.getMessage());
	}

}
 
Example 13
Source File: TestSECalignment.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public void testOldSecOutput() throws Exception {

		String fileName = "/ce_1fdo.A_2iv2.X.out";
		InputStream inStream = this.getClass().getResourceAsStream(fileName);
		assertNotNull("Could not find file " + fileName +" in resource path. Config error?", inStream);
		String xml = StringManipulationHelper.convertStreamToString(inStream);

		AtomCache cache = new AtomCache();
		String name1="1FDO.A";
		String name2="2IV2.X";
		Atom[] ca1 = cache.getAtoms(name1);
		Atom[] ca2 = cache.getAtoms(name2);

		assertEquals(715, ca1.length);
		assertEquals(697, ca2.length);

		AFPChain afpChainOrig = AFPChainXMLParser.fromXML(xml, ca1, ca2);

		assertNotNull("Could not get AfpChain object from flat file!", afpChainOrig);

		assertEquals("Could not find alignment string for prot 1","MKKVVTVCPYCASGCKINLVVDNGKIVRAEAAQGKTNQGTLCLKGYYGWDFINDTQILTPRLKTPMIRRQRGGKLEPVSWDEALNYVAERLSAIKEKYGPDAIQTTGSSRGTGNETNYVMQKFARAVIGTNNVDCCARVUHGPSVA-----GLHQSVGNGAMSNAINEIDNTDLVFVFGYNPADSHPIVANHVINAKRNGAKIIVCDPRKIETARIADMHIALKNGSNIALLNAMGHVIIEENLYDKAFVASRTEGFEEYRKIVEGYTPESVEDITGVSASEIRQAARMYAQAKSAAILWGMGVTQFYQGVETVRSLTSLAMLTGNLGKPHAGVNPVRGQNNVQGACDMGALPDTYPGYQYVKDPANREKFAKAWGVESLPAHTGYRISELPHRAAHGEVRAAYIMGEDPLQTDAELSAVRKAFEDLELVIVQDIFMTKTASAADVILPSTSWGEHEGVFTAADRGFQRFFKAVEPKWDLKTDWQIISEIATRMGYPMHYNNTQEIWDELRHLCPDFYGATYEKMGELGFIQWPCRDTSDADQGTSYLFKEKFDTPNGLAQFFTCDWVAPIDKLTDEYPMVLSTVREVGHYSCRSMTGNCAALAALADEPGYAQINTEDAKRLGIEDEALVWVHSRKGKIITRAQVSDRPNKGAIYMTYQWWIGACNELVTENLSPITKTPEYKYCAVRVEPIADQRAAEQYVIDEYNKLKTRLREAALA", new String(afpChainOrig.getAlnseq1(),0,afpChainOrig.getAlnLength()));
		assertEquals("Could not find alignment string for prot 2","MKKVVTVCPYCASGCKINLVVDNGKIVRAEAAQGKTNQGTLCLKGYYGWDFINDTQILTPRLKTPMIRRQRGGKLEPVSWDEALNYVAERLSAIKEKYGPDAIQTTGSSRGTGNETNYVMQKFARAVIGTNNVDCCAR-----VUHGPSVAGLHQSVGNGAMSNAINEIDNTDLVFVFGYNPADSHPIVANHVINAKRNGAKIIVCDPRKIETARIADMHIALKNGSNIALLNAMGHVIIEENLYDKAFVASRTEGFEEYRKIVEGYTPESVEDITGVSASEIRQAARMYAQAKSAAILWGMGVTQFYQGVETVRSLTSLAMLTGNLGKPHAGVNPVRGQNNVQGACDMGALPDTYPGYQYVKDPANREKFAKAWGVESLPAHTGYRISELPHRAAHGEVRAAYIMGEDPLQTDAELSAVRKAFEDLELVIVQDIFMTKTASAADVILPSTSWGEHEGVFTAADRGFQRFFKAVEPKWDLKTDWQIISEIATRMGYPMHYNNTQEIWDELRHLCPDFYGATYEKMGELGFIQWPCRDTSDADQGTSYLFKEKFDTPNGLAQFFTCDWVAPIDKLTDEYPMVLSTVREVGHYSCRSMTGNCAALAALADEPGYAQINTEDAKRLGIEDEALVWVHSRKGKIITRAQVSDRPNKGAIYMTYQWW------------------PEYKYCAVRVEPIADQRAAEQYVIDEYNKLKTRLREAALA", new String(afpChainOrig.getAlnseq2(),0,afpChainOrig.getAlnLength()));

		// calc time is hardware dependent.... overwrite...
		afpChainOrig.setCalculationTime(-1);

		assertEquals("alnLength is wrong! (" + afpChainOrig.getAfpChainLen()+")" ,
				720,afpChainOrig.getAlnLength());
		assertEquals("gapLength is wrong! ("+ afpChainOrig.getGapLen() + ")",
				28, afpChainOrig.getGapLen());

		//identity should be 0.9569
		assertTrue("alignment ID is < 0.95 ! (" + afpChainOrig.getIdentity()+")" , afpChainOrig.getIdentity() > 0.95);
		assertTrue("alignment ID is > 0.999 ! (" + afpChainOrig.getIdentity()+")" , afpChainOrig.getIdentity() < 0.999);

		String xmlComp =  AFPChainXMLConverter.toXML(afpChainOrig, ca1, ca2);

		FlipAFPChainTest t = new FlipAFPChainTest();
		t.printFirstMismatch(xml, xmlComp);
		StringManipulationTestsHelper.assertEqualsIgnoreEndline(xml, xmlComp);
		StructureAlignment ce = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName);


		AFPChain afpChainNew = ce.align(ca1,ca2);
		afpChainNew.setCalculationTime(-1);
		afpChainNew.setName1(name1);
		afpChainNew.setName2(name2);



		String xmlNew = AFPChainXMLConverter.toXML(afpChainNew,ca1,ca2);

		StringManipulationTestsHelper.assertEqualsIgnoreEndline(xml,xmlNew);


	}
 
Example 14
Source File: DBResultTable.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
private void showAlignment( String name1, String name2){


		if ( algorithm == null) {
			initAlgorithm(null);
		}

		try {
			Structure structure1 = null;
			if ( name1.equals("CUSTOM")) {
				// user uploaded a custom PDB file...
				structure1 = loadCustomStructure(userPath,userChain);
			} else {
				structure1 = cache.getStructure(name1);
			}
			Structure structure2 = cache.getStructure(name2);

			Atom[] ca1;
			Atom[] ca2;

			ca1 = StructureTools.getRepresentativeAtomArray(structure1);
			ca2 = StructureTools.getRepresentativeAtomArray(structure2);

			AFPChain afpChain;

			afpChain = algorithm.align(ca1, ca2);
			afpChain.setName1(name1);
			afpChain.setName2(name2);



			StructureAlignmentJmol jmol = StructureAlignmentDisplay.display(afpChain,ca1,ca2);

			//String result = afpChain.toFatcat(ca1, ca2);

			//String rot = afpChain.toRotMat();

			DisplayAFP.showAlignmentPanel(afpChain, ca1,ca2,jmol);


		} catch (Exception e){
			e.printStackTrace();
		}
	}
 
Example 15
Source File: AlignmentCalc.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
@Override
public void run() {

	// both structure have been downloaded, now calculate the alignment ...

	StructureAlignment algorithm = parent.getStructureAlignment();
	//StructurePairAligner aligner = new StructurePairAligner();
	//aligner.setDebug(true);
	try {

		Atom[] ca1 = StructureTools.getRepresentativeAtomArray(structure1);
		Atom[] ca2 = StructureTools.getRepresentativeAtomArray(structure2);

		//System.out.println("ca1 size:" + ca1.length + " ca2 size: " + ca2.length);
		AFPChain afpChain = algorithm.align(ca1, ca2);

		afpChain.setName1(name1);
		afpChain.setName2(name2);

		StructureAlignmentJmol jmol =   StructureAlignmentDisplay.display(afpChain, ca1, ca2);

		String title = jmol.getTitle();
		ConfigStrucAligParams params = algorithm.getParameters();
		if ( params != null)
			title += " " + algorithm.getParameters().toString();
		jmol.setTitle(title);

		DisplayAFP.showAlignmentPanel(afpChain,ca1,ca2,jmol);

		System.out.println(afpChain.toCE(ca1,ca2));

	} catch (StructureException e){
		e.printStackTrace();
		logger.warn(e.getMessage());
	}



	//logger.info("done!");

	parent.notifyCalcFinished();

}
 
Example 16
Source File: DemoFATCAT.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public static void main(String[] args){

		String name1 = "4hhb.A";
		String name2 = "4hhb.B";

		//String name1 = "1cdg.A";
		//String name2 = "1tim.B";



		AtomCache cache = new AtomCache();

		Structure structure1 = null;
		Structure structure2 = null;

		try {

			StructureAlignment algorithm  = StructureAlignmentFactory.getAlgorithm(FatCatRigid.algorithmName);

			structure1 = cache.getStructure(name1);
			structure2 = cache.getStructure(name2);

			Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
			Atom[] ca2 = StructureTools.getAtomCAArray(structure2);

			// get default parameters
			FatCatParameters params = new FatCatParameters();


			AFPChain afpChain = algorithm.align(ca1,ca2,params);

			afpChain.setName1(name1);
			afpChain.setName2(name2);

			// show original FATCAT output:
			System.out.println(afpChain.toFatcat(ca1,ca2));

			// show a nice summary print
			System.out.println(AfpChainWriter.toWebSiteDisplay(afpChain, ca1, ca2));

			// print rotation matrices
			System.out.println(afpChain.toRotMat());
			//System.out.println(afpChain.toCE(ca1, ca2));

			// print XML representation
			//System.out.println(AFPChainXMLConverter.toXML(afpChain,ca1,ca2));

			StructureAlignmentDisplay.display(afpChain, ca1, ca2);

		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}
 
Example 17
Source File: CookBook.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public static void main(String[] args){

		String name1="1HNG.B";
		String name2="1A64.A";


		try {

			// for this example we are going to use the jFatCat-rigid algorithm
			StructureAlignment algorithm = StructureAlignmentFactory.getAlgorithm(FatCatFlexible.algorithmName);

			// the cache takes care of loading the structures
			// Downloads files to a temp dir by default
			AtomCache cache = new AtomCache();


			//////////////////////////////
			// no need to change anything below this line
			// ////////////////////////////

			// load the structures
			Structure structure1 = cache.getStructure(name1);
			Structure structure2 = cache.getStructure(name2);

			// we are only using the CA atoms in the structure for the alignment
			Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
			Atom[] ca2 = StructureTools.getAtomCAArray(structure2);

			// do the actual alignment
			AFPChain afpChain = algorithm.align(ca1,ca2);

			// just name the two molecules
			afpChain.setName1(name1);
			afpChain.setName2(name2);

			// print and display results:


			// flexible original results:
			System.out.println(afpChain.toFatcat(ca1,ca2));

			// show the alignment in 3D in jmol
			StructureAlignmentJmol jmol= StructureAlignmentDisplay.display(afpChain, ca1, ca2);

			// set the display title for the frame
			jmol.setTitle(algorithm.getAlgorithmName() + " : " + name1 + " vs. " + name2);

			// here we open up the alignment - text panel that can interact with the 3D jmol display.
			DisplayAFP.showAlignmentPanel(afpChain, ca1,ca2,jmol);

			// we can print an XML version
			//System.out.println(AFPChainXMLConverter.toXML(afpChain, ca1, ca2));

			// or print the same output as original FATCAT
			System.out.println(AfpChainWriter.toFatCat(afpChain, ca1, ca2));





		} catch (Exception e){
			e.printStackTrace();
		}
	}
 
Example 18
Source File: DemoCE.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public static void main(String[] args){
	//String name1 = "4hhb.A";
	//String name2 = "4hhb.B";

	String name1 = "d1pqsa_";
	String name2 = "d1poha_";

	//String name1 = "5AZQ.A";
	//String name2 = "4ODC.A";

	AtomCache cache = new AtomCache();

	DownloadChemCompProvider prov = new DownloadChemCompProvider();
	prov.setDownloadAll(true);

	ChemCompGroupFactory.setChemCompProvider(prov);

	Structure structure1 = null;
	Structure structure2 = null;

	try {

		StructureAlignment algorithm  = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName);

		structure1 = cache.getStructure(name1);
		structure2 = cache.getStructure(name2);

		Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
		Atom[] ca2 = StructureTools.getAtomCAArray(structure2);

		// get default parameters
		CeParameters params = new CeParameters();

		// add more print
		params.setShowAFPRanges(true);

		// set the maximum gap size to unlimited
		params.setMaxGapSize(-1);

		AFPChain afpChain = algorithm.align(ca1,ca2,params);

		afpChain.setName1(name1);
		afpChain.setName2(name2);

		// show a nice summary print
		System.out.println(AfpChainWriter.toWebSiteDisplay(afpChain, ca1, ca2));

		// print rotation matrices
		System.out.println(afpChain.toRotMat());
		//System.out.println(afpChain.toCE(ca1, ca2));

		// print XML representation
		//System.out.println(AFPChainXMLConverter.toXML(afpChain,ca1,ca2));

		StructureAlignmentDisplay.display(afpChain, ca1, ca2);


		double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2);
		afpChain.setTMScore(tmScore);
		System.out.println(AfpChainWriter.toScoresList(afpChain));

	} catch (Exception e) {
		e.printStackTrace();
		return;
	}
}
 
Example 19
Source File: DemoCE.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public static void main(String[] args){

		//String name1 = "4hhb.A";
		//String name2 = "4hhb.B";

		String name1 = "1cdg.A";
		String name2 = "1tim.B";



		AtomCache cache = new AtomCache();

		Structure structure1 = null;
		Structure structure2 = null;

		try {

		   StructureAlignment algorithm  = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName);

			structure1 = cache.getStructure(name1);
			structure2 = cache.getStructure(name2);

			Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
			Atom[] ca2 = StructureTools.getAtomCAArray(structure2);

			// get default parameters
			CeParameters params = new CeParameters();

			// add more print
			params.setShowAFPRanges(true);

			// set the maximum gap size to unlimited
			params.setMaxGapSize(-1);

			AFPChain afpChain = algorithm.align(ca1,ca2,params);

			afpChain.setName1(name1);
			afpChain.setName2(name2);

			// flexible original results:
			System.out.println(afpChain.toFatcat(ca1,ca2));

			System.out.println(afpChain.toRotMat());
			//System.out.println(afpChain.toCE(ca1, ca2));

			System.out.println(AFPChainXMLConverter.toXML(afpChain,ca1,ca2));

			double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2);
			afpChain.setTMScore(tmScore);

			//System.out.println(AfpChainWriter.toWebSiteDisplay(afpChain, ca1, ca2));

			printScores(afpChain);
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}
 
Example 20
Source File: DemoFATCAT.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public static void main(String[] args){

		//String name1 = "4hhb.A";
		//String name2 = "4hhb.B";

		String name1 = "1cdg.A";
		String name2 = "1tim.B";



		AtomCache cache = new AtomCache();

		Structure structure1 = null;
		Structure structure2 = null;

		try {

			StructureAlignment algorithm  = StructureAlignmentFactory.getAlgorithm(FatCatRigid.algorithmName);

			structure1 = cache.getStructure(name1);
			structure2 = cache.getStructure(name2);

			Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
			Atom[] ca2 = StructureTools.getAtomCAArray(structure2);

			// the default parameters
			FatCatParameters params = new FatCatParameters();

			AFPChain afpChain = algorithm.align(ca1,ca2,params);

			afpChain.setName1(name1);
			afpChain.setName2(name2);

			// flexible original results:
			System.out.println(afpChain.toFatcat(ca1,ca2));

			System.out.println(afpChain.toRotMat());
			//System.out.println(afpChain.toCE(ca1, ca2));

			//System.out.println(AFPChainXMLConverter.toXML(afpChain,ca1,ca2));

		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}