Skip to content

Commit ba746f4

Browse files
author
Andreas Prlic
committed
first version of new tutorial
1 parent c97813a commit ba746f4

File tree

6 files changed

+348
-0
lines changed

6 files changed

+348
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
.profile
3+
.settings

structure/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The Protein Structure Modules of BioJava
2+
=====================================================
3+
4+
A tutorial for the protein structure modules of BioJava
5+
6+
## Index
7+
8+
9+
This tutorial is split into several chapters.
10+
11+
Chapter 1 - The [BioJava data model](structure-data-model.md) for the representation of macromolecular structures.
12+
13+
Chapter 2 - The [Chemical Component Dictionary](chemcomp.md)
14+
15+
Chapter X - How to [work with mmCIF/PDBx files](mmcif.md).
16+

structure/chemcomp.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
The Chemical Component Dictionary
2+
=================================
3+
4+
The [Chemical Components Dictionary](http://www.wwpdb.org/ccd.html) is an external reference file describing all residue and small molecule components found in PDB entries. This dictionary contains detailed chemical descriptions for standard and modified amino acids/nucleotides, small molecule ligands, and solvent molecules.
5+
6+
### How does BioJava decide what groups are amino acids?
7+
8+
<table>
9+
<tr><td>
10+
11+
![Selenomethionine is a naturally occurring amino acid containing selenium](img/143px-Selenomethionine-from-xtal-3D-balls.png "Selenomethionine is a naturally occurring amino acid containing selenium source: wikipedia")
12+
13+
</td>
14+
<td>Selenomethionine is a naturally occurring amino acid containing selenium source: wikipedia
15+
</td>
16+
</tr>
17+
</table>
18+
BioJava utilizes the Chem. Comp. Dictionary to achieve a chemically correct representation of each group. To make it clear how this can work, let's take a look at how [Selenomethionine](http://en.wikipedia.org/wiki/Selenomethionine) and water is dealt with:
19+
20+
21+
22+
23+
<pre>
24+
Structure structure = StructureIO.getStructure("1A62");
25+
26+
for (Chain chain : structure.getChains()){
27+
for (Group group : chain.getAtomGroups()){
28+
if ( group.getPDBName().equals("MSE") || group.getPDBName().equals("HOH")){
29+
System.out.println(group.getPDBName() + " is a group of type " + group.getType());
30+
}
31+
}
32+
}
33+
</pre>
34+
35+
This should give this output:
36+
37+
<pre>
38+
MSE is a group of type amino
39+
MSE is a group of type amino
40+
MSE is a group of type amino
41+
HOH is a group of type hetatm
42+
HOH is a group of type hetatm
43+
HOH is a group of type hetatm
44+
...
45+
</pre>
46+
47+
As you can see, although MSE is flaged as HETATM in the PDB file, BioJava still represents it correctly as an amino acid. They key is that the [definition file for MSE](http://www.rcsb.org/pdb/files/ligand/MSE.cif) flags it as "L-PEPTIDE LINKING", which is being used by BioJava.
48+
49+
50+
### How to access Chemical Component definitions
51+
Bye default BioJava ships with a minimal representation of standard amino acids, however if you want to parse the whole PDB archive, it is good to tell the library to either
52+
53+
1. fetch missing Chemical Component definitions on the fly (small download and parsing delays every time a new chemical compound is found), or
54+
2. Load all definitions at startup (slow startup, but then no further delays later on, requires more memory)
55+
56+
You can enable the first behaviour by doing using the [FileParsingParameters](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/FileParsingParameters.html) class:
57+
58+
<pre>
59+
AtomCache cache = new AtomCache();
60+
61+
// by default all files are stored at a temporary location.
62+
// you can set this either via at startup with -DPDB_DIR=/path/to/files/
63+
// or hard code it this way:
64+
cache.setPath("/tmp/");
65+
66+
FileParsingParameters params = new FileParsingParameters();
67+
68+
params.setLoadChemCompInfo(true);
69+
cache.setFileParsingParams(params);
70+
71+
StructureIO.setAtomCache(cache);
72+
73+
Structure structure = StructureIO.getStructure(...);
74+
</pre>
75+
76+
If you want to enable the second behaviour (slow loading of all chem comps at startup, but no further small delays later on) you can use the same code but change the behaviour by switching the [ChemCompProvider](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/mmcif/ChemCompProvider.html) implementation in the [ChemCompGroupFactory](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/mmcif/ChemCompGroupFactory.html)
77+
78+
<pre>
79+
ChemCompGroupFactory.setChemCompProvider(new AllChemCompProvider());
80+
</pre>
19.8 KB
Loading

structure/mmcif.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# How to parse mmCIF files using BioJava
2+
3+
A quick tutorial how to work with mmCIF files.
4+
5+
## What is mmCIF?
6+
7+
The Protein Data Bank (PDB) has been distributing its archival files as PDB files for a long time. The PDB file format is based on "punchcard"-style rules how to store data in a flat file. With the increasing complexity of macromolecules that have are being resolved experimentally, this file format can not be used any more to represent some or the more complex structures. As such, the wwPDB recently announced the transition from PDB to mmCIF/PDBx as the principal deposition and dissemination file format (see
8+
[here](http://www.wwpdb.org/news/news_2013.html#22-May-2013) and
9+
[here](http://wwpdb.org/workshop/wgroup.html)).
10+
11+
The mmCIF file format has been around for some time (see [Westbrook 2000][] and [Westbrook 2003][] ) [BioJava](http://www.biojava.org) has been supporting mmCIF already for several years. This tutorial is meant to provide a quick introduction into how to parse mmCIF files using [BioJava](http://www.biojava.org)
12+
13+
## The basics
14+
15+
BioJava provides you with both a mmCIF parser and a data model that reads PDB and mmCIF files into a biological and chemically meaningful data model (BioJava supports the [Chemical Components Dictionary](http://www.wwpdb.org/ccd.html)). If you don't want to use that data model, you can still use BioJava's file parsers, and more on that later, let's start first with the most basic way of loading a protein structure.
16+
17+
## Quick Installation
18+
19+
Before we start, just one quick paragraph of how to get access to BioJava.
20+
21+
BioJava is open source and you can get the code from [Github](https://github.com/biojava/biojava), however it might be easier this way:
22+
23+
BioJava uses [Maven](http://maven.apache.org/) as a build and distribution system. If you are new to Maven, take a look at the [Getting Started with Maven](http://maven.apache.org/guides/getting-started/index.html) guide.
24+
25+
We are providing a BioJava specific Maven repository at (http://biojava.org/download/maven/) .
26+
27+
You can add the BioJava repository by adding the following XML to your project pom.xml file:
28+
```xml
29+
<repositories>
30+
...
31+
<repository>
32+
<id>biojava-maven-repo</id>
33+
<name>BioJava repository</name>
34+
<url>http://www.biojava.org/download/maven/</url>
35+
</repository>
36+
</repositories>
37+
<dependencies>
38+
...
39+
<dependency>
40+
<!-- This imports the latest SNAPSHOT builds from the protein structure modules of BioJava
41+
-->
42+
<groupId>org.biojava</groupId>
43+
<artifactId>biojava3-structure</artifactId>
44+
<version>3.0.7-SNAPSHOT</version>
45+
</dependency>
46+
<!-- other biojava jars as needed -->
47+
</dependencies>
48+
```
49+
50+
If you run 'mvn package' on your project, the BioJava dependencies will be automatically downloaded and installed for you.
51+
52+
## First steps
53+
54+
The simplest way to load a PDB file is by using the [StructureIO](http://www.biojava.org/docs/api/org/biojava3/structure/StructureIO.html) class.
55+
56+
<pre>
57+
Structure structure = StructureIO.getStructure("4HHB");
58+
// and let's print out how many atoms are in this structure
59+
System.out.println(StructureTools.getNrAtoms(structure));
60+
</pre>
61+
62+
63+
64+
BioJava automatically downloaded the PDB file for hemoglobin [4HHB](http://www.rcsb.org/pdb/explore.do?structureId=4HHB) and copied it into a temporary location. This demonstrates two things:
65+
66+
+ BioJava can automatically download and install files locally
67+
+ BioJava by default writes those files into a temporary location (The system temp directory "java.io.tempdir").
68+
69+
If you already have a local PDB installation, you can configure where BioJava should read the files from by setting the PDB_DIR system property
70+
71+
<pre>
72+
-DPDB_DIR=/wherever/you/want/
73+
</pre>
74+
75+
## From PDB to mmCIF
76+
77+
By default BioJava is using the PDB file format for parsing data. In order to switch it to use mmCIF, we can take control over the underlying [AtomCache](http://www.biojava.org/docs/api/org/biojava/bio/structure/align/util/AtomCache.html) which manages your PDB (and btw. also SCOP, CATH) installations.
78+
79+
<pre>
80+
AtomCache cache = new AtomCache();
81+
82+
cache.setUseMmCif(true);
83+
84+
// if you struggled to set the PDB_DIR property correctly in the previous step,
85+
// you could set it manually like this:
86+
cache.setPath("/tmp/");
87+
88+
StructureIO.setAtomCache(cache);
89+
90+
Structure structure = StructureIO.getStructure("4HHB");
91+
92+
// and let's count how many chains are in this structure.
93+
System.out.println(structure.getChains().size());
94+
</pre>
95+
96+
As you can see, the AtomCache will again download the missing mmCIF file for 4HHB in the background.
97+
98+
## Low level access
99+
100+
If you want to learn how to use the BioJava mmCIF parser to populate your own data structure, let's first take a look this lower-level code:
101+
102+
<pre>
103+
InputStream inStream = new FileInputStream(fileName);
104+
105+
MMcifParser parser = new SimpleMMcifParser();
106+
107+
SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();
108+
109+
// The Consumer builds up the BioJava - structure object.
110+
// you could also hook in your own and build up you own data model.
111+
parser.addMMcifConsumer(consumer);
112+
113+
try {
114+
parser.parse(new BufferedReader(new InputStreamReader(inStream)));
115+
} catch (IOException e){
116+
e.printStackTrace();
117+
}
118+
119+
// now get the protein structure.
120+
Structure cifStructure = consumer.getStructure();
121+
</pre>
122+
123+
The parser operates similar to a XML parser by triggering "events". The [SimpleMMcifConsumer](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/mmcif/SimpleMMcifConsumer.html) listens to new categories being read from the file and then builds up the BioJava data model.
124+
125+
To re-use the parser for your own datamodel, just implement the [MMcifConsumer](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/mmcif/MMcifConsumer.html) interface and add it to the [SimpleMMcifParser](http://www.biojava.org/docs/api/org/biojava/bio/structure/io/mmcif/SimpleMMcifParser.html).
126+
<pre>
127+
parser.addMMcifConsumer(myOwnConsumerImplementation);
128+
</pre>
129+
130+
## I loaded a Structure object, what now?
131+
132+
BioJava provides a number of algorithms and visualisation tools that you can use to further analyse the structure, or look at it. Here a couple of suggestions for further reads:
133+
134+
+ [The BioJava Cookbook for protein structures](http://biojava.org/wiki/BioJava:CookBook#Protein_Structure)
135+
+ How does BioJava [represent the content](structure-data-model.md) of a PDB/mmCIF file?
136+
+ [How to calculate a protein structure alignment using BioJava](http://biojava.org/wiki/BioJava:CookBook:PDB:align)
137+
+ [How to work with Groups (AminoAcid, Nucleotide, Hetatom)](http://biojava.org/wiki/BioJava:CookBook:PDB:groups)
138+
139+
140+
141+
<!-- References -->
142+
143+
144+
[Westbrook 2000]: http://www.ncbi.nlm.nih.gov/pubmed/10842738 "Westbrook JD and Bourne PE. STAR/mmCIF: an ontology for macromolecular structure. Bioinformatics 2000 Feb; 16(2) 159-68. pmid:10842738."
145+
146+
[Westbrook 2003]: http://www.ncbi.nlm.nih.gov/pubmed/12647386 "Westbrook JD and Fitzgerald PM. The PDB format, mmCIF, and other data formats. Methods Biochem Anal 2003; 44 161-79. pmid:12647386."
147+

structure/structure-data-model.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# The BioJava-structure data model
2+
3+
A biologically and chemically meaningful data representation of PDB/mmCIF.
4+
5+
## The basics
6+
7+
BioJava at its core is a collection of file parsers and (in some cases) data models to represent frequently used biological data. The protein-structure modules represent macromolecular data in a way that should make it easy to work with. The representation is essentially independ of the underlying file format and the user can chose to work with either PDB or mmCIF files and still get an almost identical data representation.
8+
9+
## The main hierarchy
10+
11+
BioJava provides a flexible data structure for managing protein structural data. The
12+
[http://www.biojava.org/docs/api/org/biojava/bio/structure/Structure.html Structure] class is the main container.
13+
14+
A Structure has a hierarchy of sub-objects:
15+
16+
<pre>
17+
Structure
18+
|
19+
Model(s)
20+
|
21+
Chain(s)
22+
|
23+
Group(s) -> Chemical Component Definition
24+
|
25+
Atom(s)
26+
</pre>
27+
28+
All structure objects contain one or more "models". That means also X-ray structures contain an "virtual" model which serves as a container for the chains. The most common way to access chains will be via
29+
30+
<pre>
31+
List<Chain>chains = structure.getChains();
32+
</pre>
33+
34+
This works for both NMR and X-ray based structures and by default the first model is getting accessed.
35+
36+
37+
## Working with atoms
38+
39+
Different ways are provided how to access the data contained in a [Structure](http://www.biojava.org/docs/api/org/biojava/bio/structure/Structure.html).
40+
If you want to directly access an array of [Atoms](http://www.biojava.org/docs/api/org/biojava/bio/structure/Atom.html) you can use the utility class called [StructureTools](http://www.biojava.org/docs/api/org/biojava/bio/structure/StructureTools.html)
41+
42+
<pre>
43+
44+
// get all C-alpha atoms in the structure
45+
Atom[] caAtoms = StructureTools.getAtomCAArray(structure);
46+
</pre>
47+
48+
Alternatively you can access atoms also by their parent-group.
49+
50+
## Working with groups
51+
52+
The [Group](http://www.biojava.org/docs/api/org/biojava/bio/structure/Group.html) interface defines all methods common to a group of atoms. There are 3 types of Groups:
53+
54+
* [AminoAcid](http://www.biojava.org/docs/api/org/biojava/bio/structure/AminoAcid.html)
55+
* [Nucleotide](http://www.biojava.org/docs/api/org/biojava/bio/structure/NucleotideImpl.html)
56+
* [Hetatom](http://www.biojava.org/docs/api/org/biojava/bio/structure/HetatomImpl.html)
57+
58+
In order to get all amino acids that have been observed in a PDB chain, you can use the following utility method:
59+
60+
<pre>
61+
Chain chain = s.getChainByPDB("A");
62+
List<Group> groups = chain.getAtomGroups("amino");
63+
for (Group group : groups) {
64+
AminoAcid aa = (AminoAcid) group;
65+
66+
// do something amino acid specific, e.g. print the secondary structure assignment
67+
System.out.println(aa + " " + aa.getSecStruc());
68+
}
69+
</pre>
70+
71+
72+
In a similar way you can access all nucleotide groups by
73+
<pre>
74+
chain.getAtomGroups("nucleotide");
75+
</pre>
76+
77+
The Hetatom groups are access in a similar fashion:
78+
<pre>
79+
chain.getAtomGroups("hetatm");
80+
</pre>
81+
82+
83+
Since all 3 types of groups are implementing the Group interface, you can also iterate over all groups and check for the instance type:
84+
85+
<pre>
86+
List<Group> allgroups = chain.getAtomGroups();
87+
for (Group group : groups) {
88+
if ( group instanceof AminoAcid) {
89+
AminoAcid aa = (AminoAcid) group;
90+
System.out.println(aa.getSecStruc());
91+
}
92+
}
93+
</pre>
94+
95+
96+
97+
98+
99+
100+
101+
102+

0 commit comments

Comments
 (0)