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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#setCa1Length() . 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: CeCPMainTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a minimal AFPChain from the specified alignment and proteins
 * @param dupAlign
 * @param ca1
 * @param ca2
 * @return
 */
private AFPChain makeDummyAFPChain(int[][][] dupAlign, Atom[] ca1,Atom[] ca2) {
	AFPChain afp = new AFPChain(AFPChain.UNKNOWN_ALGORITHM);
	afp.setOptAln(dupAlign);
	afp.setOptLength(dupAlign[0][1].length);
	afp.setCa1Length(ca1.length);
	afp.setCa2Length(ca2.length);
	afp.setBlockNum(1);
	afp.setOptLen(new int[] {dupAlign[0][1].length});
	return afp;
}
 
Example 2
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 3
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 4
Source File: FatCatAligner.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
public  void align(Atom[] ca1, Atom[] ca2, boolean doRigid, FatCatParameters params) throws StructureException{

		long tstart = System.currentTimeMillis();

		afpChain = new AFPChain(FatCat.algorithmName);
		afpChain.setCa1Length(ca1.length);
		afpChain.setCa2Length(ca2.length);



		AFPCalculator.extractAFPChains(params, afpChain,ca1, ca2);

		long cend = System.currentTimeMillis();

		if (printTimeStamps)
			System.out.println("calculation took:" + (cend - tstart) + " ms.");


		AFPCalculator.sortAfps(afpChain,ca1,ca2);

		if ( printTimeStamps) {
			long send = System.currentTimeMillis();


			System.out.println("sorting  took:" + (send - cend) + " ms.");
		}

		if ( doRigid)
			this.twistedGroups = rChainAfp(params, afpChain,ca1,ca2);

		else {
			this.twistedGroups = chainAfp(params,afpChain,ca1,ca2);
		}

		// long start = System.currentTimeMillis();
		long end = System.currentTimeMillis();
		afpChain.setCalculationTime(end-tstart);
		if ( printTimeStamps)
			System.out.println("TOTAL calc time: " + (end -tstart) / 1000.0);

	}