/** * 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].getChainId() + ":" + aligned1[i]; pdbAln[0][1][i] = aligned2[i].getChainId() + ":" + 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); }
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( "alinment ID is < 0.95 ! (" + afpChainOrig.getIdentity() + ")", afpChainOrig.getIdentity() > 0.95); assertTrue( "alignment ID is > 0.96 ! (" + afpChainOrig.getIdentity() + ")", afpChainOrig.getIdentity() < 0.96); 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); }