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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#toFatcat() . 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: TestDNAAlignment.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test1() throws IOException {
	String name1="1l3s.A";
	String name2="1t7p.P";

	AtomCache cache = new AtomCache();
	try {
		Atom[] ca1 = cache.getAtoms(name1);
		Atom[] ca2 = cache.getAtoms(name2);
		CeMain ce = new CeMain();
		AFPChain afpChain = ce.align(ca1,ca2);
		assertNotNull(afpChain);

	  String txt = afpChain.toFatcat(ca1, ca2);

	  assertNotNull(txt);

	} catch (StructureException e){
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 2
Source File: AFPChainSerialisationTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String[] align (String name1, String name2, Atom[] ca1, Atom[] ca2 , boolean doRigid) throws StructureException,IOException{

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


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

		String[] result = new String[2];
		result[0] = fatcat;
		result[1] = xml;
		return result;
	}
 
Example 3
Source File: AFPChainSerialisationTest.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@org.junit.Test
public void testMulti() throws IOException, StructureException {
	Atom[] ca1 = null;
	Atom[] ca2 = null;
	Atom[] ca3 = null;
	Atom[] ca4 = null;
	Atom[] ca5 = null;
	Atom[] ca6 = null;
	String[] result1 = null;
	String[] result2 = null;

	String name1 = "5pti.A";
	String name2 = "1znf.A";

	String name3 ="1hiv.A";
	String name4 ="1a4w.H";
	Structure s1 = getStructure("5pti","A");
	Structure s2 = getStructure("1znf","A");
	ca1 = StructureTools.getRepresentativeAtomArray(s1);
	ca2 = StructureTools.getRepresentativeAtomArray(s2);
	ca3 = StructureTools.cloneAtomArray(ca2);

	result1 = align(name1,name2,ca1, ca2,true);

	Structure s3 = getStructure("1hiv","A");
	Structure s4 = getStructure("1a4w","H");
	ca4 = StructureTools.getRepresentativeAtomArray(s3);
	ca5 = StructureTools.getRepresentativeAtomArray(s4);
	ca6 = StructureTools.cloneAtomArray(ca5);

	result2 = align(name3,name4,ca4, ca5,true);




	String xmlNew = "<multi>"+result1[1]+ result2[1] +"</multi>";
	//System.out.println(xmlNew);

	testSaxParser(xmlNew,name1,name2,result1,ca1,ca3,name3,name4,result2,ca4,ca6);


	//WARNING: THE ORDER CAN CHANGE: order of elements in XML is not necessarily the same!
	AFPChain[] chains = AFPChainXMLParser.parseMultiXML(xmlNew);

	assertTrue(chains.length == 2);

	// recreate the correct chains...
	AFPChain new1 = getAfpFor(name1,chains);
	AFPChain new2 = getAfpFor(name3,chains);

	assertNotNull(new1);
	assertNotNull(new2);

	assertTrue(new1.getName1().equals(name1));
	//System.out.println(new2.getName1() + " " + new2.getName2() + " "+ name3);
	assertTrue(new2.getName1().equals(name3));


	AFPChainXMLParser.rebuildAFPChain(new1, ca1, ca3);
	String fatcat1 = new1.toFatcat(ca1, ca3);
	assertEquals(fatcat1, result1[0]);
	String xmlnew1 = AFPChainXMLConverter.toXML(new1, ca1, ca3);
	assertTrue(xmlnew1.equals(result1[1]));

	AFPChainXMLParser.rebuildAFPChain(new2, ca4, ca6);
	String fatcat2 = new2.toFatcat(ca4, ca6);

	assertEquals(fatcat2,result2[0]);
	String xmlnew2 = AFPChainXMLConverter.toXML(new2, ca4, ca6);
	assertEquals(xmlnew2,result2[1]);



}
 
Example 4
Source File: AFPChainSerialisationTest.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
private void testAlignment(String name1, String name2, Atom[] ca1, Atom[] ca2, boolean doRigid) throws StructureException,IOException{


		Atom[] ca3 = StructureTools.cloneAtomArray(ca2);


		AFPChain afpChain = doAlign(name1, name2, ca1,ca2,doRigid);



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


		//System.out.println(xml);
		AFPChain newChain = AFPChainXMLParser.fromXML (xml, ca1, ca3);

		// test blockNum and optLen arrays
		int blockNum = afpChain.getBlockNum();
		int[] optLen = afpChain.getOptLen();

		assertTrue("The nr of aligned blocks is not the same! " + blockNum + " " + newChain.getBlockNum() , blockNum == newChain.getBlockNum());



		for ( int i =0 ; i < blockNum ; i++){
			int newLenI = newChain.getOptLen()[i];
			assertTrue("The values in the optLen field don't match! pos:" + i + " orig:" + optLen[i] + " new:" +  newLenI,optLen[i] == newLenI);
		}

		// test the internal optAlign data structure:

		int[][][] optAln1 = afpChain.getOptAln();
		int[][][] optAln2 = newChain.getOptAln();

		for(int i = 0; i < blockNum; i ++)  {
			for(int j = 0; j < optLen[i]; j ++) {
				int p1 = optAln1[i][0][j];
				int p2 = optAln1[i][1][j];

				int n1 = optAln2[i][0][j];
				int n2 = optAln2[i][1][j];

				assertTrue(p1 == n1);
				assertTrue(p2 == n2);

			}
		}

		String fatcat2 = newChain.toFatcat(ca1, ca3);
		//System.out.println("*** RESULT2 "+result2);

		assertEquals(fatcat,fatcat2);

		String xml2 = AFPChainXMLConverter.toXML(newChain, ca1, ca3);
		assertEquals(xml, xml2);

	}