PDB Alignment Java Code Example with Biojava | Structural alignment tools online run in java
package pdb;
import java.io.FileOutputStream;
import java.io.PrintStream;
import javax.swing.JOptionPane;
import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.align.ClusterAltAligs;
import org.biojava.bio.structure.align.StructurePairAligner;
import org.biojava.bio.structure.align.pairwise.AlternativeAlignment;
import org.biojava.bio.structure.io.PDBFileReader;
/**
*
* @author Usman
*/
public class Alignment {
public static void main(String[] args){
try{
PDBFileReader pdbr = new PDBFileReader();
String ProjectPath= System.getProperties().getProperty("user.dir");
pdbr.setPath(ProjectPath+"/SamplePDB/");
String pdb1 = "12E8";
String pdb2 = "tnf";
String outputfile = "SamplePDB/alig_"+pdb1+"_"+pdb2+".pdb";
// NO NEED TO DO CHANGE ANYTHING BELOW HERE...
StructurePairAligner sc = new StructurePairAligner();
// step1 : read molecules
System.out.println("aligning " + pdb1 + " vs. " + pdb2);
Structure s1 = pdbr.getStructureById(pdb1);
Structure s2 = pdbr.getStructureById(pdb2);
// of course you do not have to use the full structures
// you could also just use any set of atoms of your choice
// step 2 : do the calculations
sc.align(s1,s2);
// if you want more control over the alignment parameters
// use the StrucAligParameters
//StrucAligParameters params = new StrucAligParameters();
//params.setFragmentLength(8);
//sc.align(s1,s2,params);
AlternativeAlignment[] aligs = sc.getAlignments();
//cluster similar results together
ClusterAltAligs.cluster(aligs);
// print the result:
// the AlternativeAlignment object gives access to rotation matrices / shift vectors.
for (int i=0 ; i< aligs.length; i ++){
AlternativeAlignment aa = aligs[i];
System.out.println(aa);
}
// convert AlternativeAlignment 1 to PDB file, so it can be opened with a viewer of your choice
//(e.g. Jmol, Rasmol)
if ( aligs.length > 0) {
AlternativeAlignment aa1 =aligs[0];
String pdbstr = aa1.toPDB(s1,s2);
System.out.println("writing alignment to " + outputfile);
FileOutputStream out= new FileOutputStream(outputfile);
PrintStream p = new PrintStream( out );
JOptionPane.showMessageDialog(null, "Align Sucess");
p.println (pdbstr);
p.close();
out.close();
}
} catch (Exception e){
e.printStackTrace();
}
}
}
package pdb;
import java.io.FileOutputStream;
import java.io.PrintStream;
import javax.swing.JOptionPane;
import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.align.ClusterAltAligs;
import org.biojava.bio.structure.align.StructurePairAligner;
import org.biojava.bio.structure.align.pairwise.AlternativeAlignment;
import org.biojava.bio.structure.io.PDBFileReader;
/**
*
* @author Usman
*/
public class Alignment {
public static void main(String[] args){
try{
PDBFileReader pdbr = new PDBFileReader();
String ProjectPath= System.getProperties().getProperty("user.dir");
pdbr.setPath(ProjectPath+"/SamplePDB/");
String pdb1 = "12E8";
String pdb2 = "tnf";
String outputfile = "SamplePDB/alig_"+pdb1+"_"+pdb2+".pdb";
// NO NEED TO DO CHANGE ANYTHING BELOW HERE...
StructurePairAligner sc = new StructurePairAligner();
// step1 : read molecules
System.out.println("aligning " + pdb1 + " vs. " + pdb2);
Structure s1 = pdbr.getStructureById(pdb1);
Structure s2 = pdbr.getStructureById(pdb2);
// of course you do not have to use the full structures
// you could also just use any set of atoms of your choice
// step 2 : do the calculations
sc.align(s1,s2);
// if you want more control over the alignment parameters
// use the StrucAligParameters
//StrucAligParameters params = new StrucAligParameters();
//params.setFragmentLength(8);
//sc.align(s1,s2,params);
AlternativeAlignment[] aligs = sc.getAlignments();
//cluster similar results together
ClusterAltAligs.cluster(aligs);
// print the result:
// the AlternativeAlignment object gives access to rotation matrices / shift vectors.
for (int i=0 ; i< aligs.length; i ++){
AlternativeAlignment aa = aligs[i];
System.out.println(aa);
}
// convert AlternativeAlignment 1 to PDB file, so it can be opened with a viewer of your choice
//(e.g. Jmol, Rasmol)
if ( aligs.length > 0) {
AlternativeAlignment aa1 =aligs[0];
String pdbstr = aa1.toPDB(s1,s2);
System.out.println("writing alignment to " + outputfile);
FileOutputStream out= new FileOutputStream(outputfile);
PrintStream p = new PrintStream( out );
JOptionPane.showMessageDialog(null, "Align Sucess");
p.println (pdbstr);
p.close();
out.close();
}
} catch (Exception e){
e.printStackTrace();
}
}
}
0 comments:
Post a Comment