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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#setBlockResList() . 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: AFPOptimizer.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * get the afp list and residue list for each block
 */

public static void blockInfo(AFPChain afpChain)
{
	int     i, j, k, a, n;

	int blockNum = afpChain.getBlockNum();

	int[] blockSize =afpChain.getBlockSize();
	int[] afpChainList = afpChain.getAfpChainList();
	int[] block2Afp = afpChain.getBlock2Afp();
	int[][][]blockResList = afpChain.getBlockResList();

	List<AFP>afpSet = afpChain.getAfpSet();
	int[] blockResSize = afpChain.getBlockResSize();

	for(i = 0; i < blockNum; i ++)  {
		n = 0;
		for(j = 0; j < blockSize[i]; j ++)      {
			//the index in afpChainList, not in the whole afp set
			a = afpChainList[block2Afp[i] + j];
			for(k = 0; k < afpSet.get(a).getFragLen(); k ++)     {
				blockResList[i][0][n] = afpSet.get(a).getP1() + k;
				blockResList[i][1][n] = afpSet.get(a).getP2() + k;
				n ++;
			}
		}
		blockResSize[i] = n;
	}

	afpChain.setBlockResSize(blockResSize);
	afpChain.setBlockSize(blockSize);
	afpChain.setAfpChainList(afpChainList);
	afpChain.setBlock2Afp(block2Afp);
	afpChain.setBlockResList(blockResList);
}
 
Example 2
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 3
Source File: AFPCalculator.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static final  void extractAFPChains(FatCatParameters params, AFPChain afpChain,Atom[] ca1,Atom[] ca2) throws StructureException {



		List<AFP> afpSet = new ArrayList<AFP>();
		afpChain.setAfpSet(afpSet);

		if ( debug )
			System.err.println("nr of atoms ca1: " + ca1.length + " ca2: " +  ca2.length);



		int     p1, p2;
		@SuppressWarnings("unused")
		int n0, n, n1, n2;
		double  filter1;
		double rmsd = 0;

		Matrix r = new Matrix(3,3);
		Atom   t = new AtomImpl();


		int sparse = params.getSparse();
		int maxTra = params.getMaxTra();
		int fragLen = params.getFragLen();
		double disFilter = params.getDisFilter();
		double rmsdCut = params.getRmsdCut();
		double badRmsd = params.getBadRmsd();
		double fragScore = params.getFragScore();

		int     add = sparse + 1; //if add > 1, use sparse sampling
		n0 = n = n1 = n2 = 0;

		int minLen = 0;

		int prot1Length = ca1.length;
		int prot2Length = ca2.length;

		if(prot1Length < prot2Length)
			minLen = prot1Length;
		else
			minLen = prot2Length;
		afpChain.setMinLen(minLen);

		afpChain.setBlockResList(new int[maxTra+1][2][minLen]);
		afpChain.setFocusRes1(new int[minLen]);
		afpChain.setFocusRes2(new int[minLen]);

		for(p1 = 0; p1 < prot1Length - fragLen; p1 += add )    {
			for(p2 = 0; p2 < prot2Length - fragLen; p2 += add)     {
				n0 ++;
				filter1 = getEnd2EndDistance(ca1, ca2, p1, p1 + fragLen - 1, p2, p2 + fragLen - 1);
				//difference bewteen end-to-end distances
				if(filter1 > disFilter) { n1 ++; continue; }
				boolean filter2 = filterTerminal(ca1,ca2, p1, p1 + fragLen - 1, p2, p2 + fragLen - 1, fragLen, minLen);
				if(filter2)     {
					n2 ++;
					continue;

				} //be cautious to use this filter !!

				// here FATCAT does a a jacobi transformation
				//rmsd = kearsay(fragLen, ca1[p1], ca2[p2], r, t);
				// we use the BioJava SVD instead...

				//
				rmsd = getRmsd(ca1,ca2,fragLen, p1,p2,r,t);

				if(rmsd < rmsdCut)      {
					AFP     afptmp = new AFP();
					afptmp.setP1(p1);
					afptmp.setP2(p2);
					afptmp.setFragLen(fragLen);
					afptmp.setRmsd(rmsd);
					afptmp.setM(r);
					afptmp.setT(t.getCoords());
					afptmp.setScore(scoreAfp(afptmp,badRmsd,fragScore));
					afpSet.add(afptmp);
					n ++;
				}
			}
		}

		int afpNum = afpSet.size();

		if(debug) {
			String msg = String.format("possible AFP-pairs %d, remain %d after filter 1 remove %d; filter 2 remove %d\n",
					n0, afpNum, n1, n2);
			System.err.println(msg);
		}


	}
 
Example 4
Source File: AlignmentTools.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * It replaces an optimal alignment of an AFPChain and calculates all the new alignment scores and variables.
 */
public static AFPChain replaceOptAln(int[][][] newAlgn, AFPChain afpChain, Atom[] ca1, Atom[] ca2) throws StructureException {

	//The order is the number of groups in the newAlgn
	int order = newAlgn.length;

	//Calculate the alignment length from all the subunits lengths
	int[] optLens = new int[order];
	for(int s=0;s<order;s++) {
		optLens[s] = newAlgn[s][0].length;
	}
	int optLength = 0;
	for(int s=0;s<order;s++) {
		optLength += optLens[s];
	}

	//Create a copy of the original AFPChain and set everything needed for the structure update
	AFPChain copyAFP = (AFPChain) afpChain.clone();

	//Set the new parameters of the optimal alignment
	copyAFP.setOptLength(optLength);
	copyAFP.setOptLen(optLens);
	copyAFP.setOptAln(newAlgn);

	//Set the block information of the new alignment
	copyAFP.setBlockNum(order);
	copyAFP.setBlockSize(optLens);
	copyAFP.setBlockResList(newAlgn);
	copyAFP.setBlockResSize(optLens);
	copyAFP.setBlockGap(calculateBlockGap(newAlgn));

	//Recalculate properties: superposition, tm-score, etc
	Atom[] ca2clone = StructureTools.cloneAtomArray(ca2); // don't modify ca2 positions
	AlignmentTools.updateSuperposition(copyAFP, ca1, ca2clone);

	//It re-does the sequence alignment strings from the OptAlgn information only
	copyAFP.setAlnsymb(null);
	AFPAlignmentDisplay.getAlign(copyAFP, ca1, ca2clone);

	return copyAFP;
}