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

The following examples show how to use org.biojava.nbio.structure.align.model.AFPChain#getNrEQR() . 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: DemoCE.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void printScores(AFPChain afpChain) {
	System.out.println("=====================");
	System.out.println("The main scores for the alignment:");

	System.out.println("EQR       :\t" + afpChain.getNrEQR() + "\t The number of residues on structurally equivalent positions.")  ;
	System.out.println("RMSD      :\t" + String.format("%.2f",afpChain.getTotalRmsdOpt() )+ "\t The RMSD of the alignment");
	System.out.println("Z-score   :\t" + afpChain.getProbability() + "\t The Z-score of the alignment (CE)");
	System.out.println("TM-score  :\t" + String.format("%.2f",afpChain.getTMScore()) + "\t The TM-score of the alignment.");
	System.out.println("");
	System.out.println("Other scores:");
	System.out.println("Identity  :\t" + String.format("%.2f",afpChain.getIdentity())   + "\t The percent of residues that are sequence-identical in the alignment.");
	System.out.println("Similarity:\t" + String.format("%.2f",afpChain.getSimilarity()) + "\t The percent of residues in the alignment that are sequence-similar.");
	System.out.println("Coverage1 :\t" + afpChain.getCoverage1() + " %\t Percent of protein 1 that is covered with the alignment.");
	System.out.println("Coverage2 :\t" + afpChain.getCoverage2() + " %\t Percent of protein 2 that is covered with the alignment.");
	int dab = afpChain.getCa1Length()+afpChain.getCa2Length() - 2 * afpChain.getNrEQR();
	System.out.println("Distance  :\t" + dab + "\t Distance between folds a,b ");
	double sab = 2 * afpChain.getNrEQR() / (double)( afpChain.getCa1Length() + afpChain.getCa2Length());
	System.out.println("Rel. Sim. :\t" + String.format("%.2f",sab) + "\t Relative similarity");



}
 
Example 2
Source File: DisplayAFP.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Create a "fake" Structure objects that contains the two sets of atoms aligned on top of each other.
 *
 * @param afpChain the container of the alignment
 * @param ca1 atoms for protein 1
 * @param ca2 atoms for protein 2
 * @return a protein structure with 2 models.
 * @throws StructureException
 */
public static Structure createArtificalStructure(AFPChain afpChain, Atom[] ca1,
		Atom[] ca2) throws StructureException{


	if ( afpChain.getNrEQR() < 1){
		return AlignmentTools.getAlignedStructure(ca1, ca2);
	}

	Group[] twistedGroups = AlignmentTools.prepareGroupsForDisplay(afpChain,ca1, ca2);

	List<Atom> twistedAs = new ArrayList<Atom>();

	for ( Group g: twistedGroups){
		if ( g == null )
			continue;
		if ( g.size() < 1)
			continue;
		Atom a = g.getAtom(0);
		twistedAs.add(a);
	}
	Atom[] twistedAtoms = twistedAs.toArray(new Atom[twistedAs.size()]);

	List<Group> hetatms  = StructureTools.getUnalignedGroups(ca1);
	List<Group> hetatms2 = StructureTools.getUnalignedGroups(ca2);

	Atom[] arr1 = DisplayAFP.getAtomArray(ca1, hetatms);
	Atom[] arr2 = DisplayAFP.getAtomArray(twistedAtoms, hetatms2);

	Structure artificial = AlignmentTools.getAlignedStructure(arr1,arr2);
	return artificial;
}
 
Example 3
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 4
Source File: AFPAlignmentDisplay.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 *
 * @param afpChain
 * @param ca1
 * @param ca2
 * @return
 * @throws ClassNotFoundException If an error occurs when invoking jmol
 * @throws NoSuchMethodException If an error occurs when invoking jmol
 * @throws InvocationTargetException If an error occurs when invoking jmol
 * @throws IllegalAccessException If an error occurs when invoking jmol
 * @throws StructureException
 */
public static Structure createArtificalStructure(AFPChain afpChain, Atom[] ca1,
												 Atom[] ca2) throws ClassNotFoundException, NoSuchMethodException,
		InvocationTargetException, IllegalAccessException, StructureException
{

	if ( afpChain.getNrEQR() < 1){
		return GuiWrapper.getAlignedStructure(ca1, ca2);
	}

	Group[] twistedGroups = AlignmentTools.prepareGroupsForDisplay(afpChain,ca1, ca2);

	List<Atom> twistedAs = new ArrayList<Atom>();

	for ( Group g: twistedGroups){
		if ( g == null )
			continue;
		if ( g.size() < 1)
			continue;
		Atom a = g.getAtom(0);
		twistedAs.add(a);
	}
	Atom[] twistedAtoms = twistedAs.toArray(new Atom[twistedAs.size()]);

	List<Group> hetatms  = new ArrayList<Group>();
	List<Group> nucs1    = new ArrayList<Group>();
	Group g1 = ca1[0].getGroup();
	Chain c1 = null;
	if ( g1 != null) {
		c1 = g1.getChain();
		if ( c1 != null){
			hetatms = c1.getAtomGroups(GroupType.HETATM);;
			nucs1  = c1.getAtomGroups(GroupType.NUCLEOTIDE);
		}
	}
	List<Group> hetatms2 = new ArrayList<Group>();
	List<Group> nucs2    = new ArrayList<Group>();
	Group g2 = ca2[0].getGroup();
	Chain c2 = null;
	if ( g2 != null){
		c2 = g2.getChain();
		if ( c2 != null){
			hetatms2 = c2.getAtomGroups(GroupType.HETATM);
			nucs2 = c2.getAtomGroups(GroupType.NUCLEOTIDE);
		}
	}
	Atom[] arr1 = GuiWrapper.getAtomArray(ca1, hetatms, nucs1);
	Atom[] arr2 = GuiWrapper.getAtomArray(twistedAtoms, hetatms2, nucs2);

	return GuiWrapper.getAlignedStructure(arr1,arr2);
}
 
Example 5
Source File: AFPChainScorer.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
public  static double getTMScore(AFPChain align, Atom[] ca1, Atom[] ca2, boolean normalizeMin) throws StructureException
{
	if ( align.getNrEQR() == 0)
		return -1;


	// Create new arrays for the subset of atoms in the alignment.
	Atom[] ca1aligned = new Atom[align.getOptLength()];
	Atom[] ca2aligned = new Atom[align.getOptLength()];
	int pos=0;
	int[] blockLens = align.getOptLen();
	int[][][] optAln = align.getOptAln();
	assert(align.getBlockNum() <= optAln.length);

	for(int block=0;block< align.getBlockNum();block++) {

		if ( ! ( blockLens[block] <= optAln[block][0].length)) {
			logger.warn("AFPChainScorer getTMScore: errors reconstructing alignment block [" + block + "]. Length is " + blockLens[block] + " but should be <=" + optAln[block][0].length);
		}

		for(int i=0;i<blockLens[block];i++) {
			int pos1 = optAln[block][0][i];
			int pos2 = optAln[block][1][i];
			Atom a1 = ca1[pos1];
			Atom a2 = (Atom) ca2[pos2].clone();

			ca1aligned[pos] = a1;
			ca2aligned[pos] = a2;
			pos++;
		}
	}

	// this can happen when we load an old XML serialization which did not support modern ChemComp representation of modified residues.
	if ( pos != align.getOptLength()){
		logger.warn("AFPChainScorer getTMScore: Problems reconstructing alignment! nr of loaded atoms is " + pos + " but should be " + align.getOptLength());
		// we need to resize the array, because we allocated too many atoms earlier on.
		ca1aligned = (Atom[]) resizeArray(ca1aligned, pos);
		ca2aligned = (Atom[]) resizeArray(ca2aligned, pos);
	}
	//Superimpose
	Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(ca1aligned),
			Calc.atomsToPoints(ca2aligned));

	Calc.transform(ca2aligned, trans);

	return Calc.getTMScore(ca1aligned, ca2aligned, ca1.length, ca2.length, normalizeMin);
}