Skip to content

Commit 38b2c37

Browse files
committed
Add CookBook demo for creating a phylogenetic tree from MSA
1 parent 63ab529 commit 38b2c37

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package demo;
2+
3+
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
4+
import org.biojava.nbio.core.sequence.ProteinSequence;
5+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
6+
import org.biojava.nbio.phylo.TreeConstructionAlgorithm;
7+
import org.biojava.nbio.phylo.ProgressListenerStub;
8+
import org.biojava.nbio.phylo.TreeConstructor;
9+
import org.biojava.nbio.phylo.TreeType;
10+
11+
/**
12+
* This demo contains the CookBook examples to create a phylogenetic tree from a
13+
* given multiple sequence alignment (MSA).
14+
*
15+
* @author Aleix Lafita
16+
*
17+
*/
18+
public class DemoTreeConstructor {
19+
20+
public static void main(String[] args) throws Exception {
21+
22+
MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msa = new
23+
MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound>();
24+
25+
ProteinSequence pSeq1 = new ProteinSequence(
26+
"RER-RDGGGNSRKYDDRRSPRDGE---IDYDERTVSHYQRQFQDERISDGM"
27+
+ "LNTLKQSLKGLDCQPIHLKDSKANRSIMIDEIHTGTADSVTFEQKLPDGEMKL");
28+
ProteinSequence pSeq2 = new ProteinSequence(
29+
"RDRHRD---DRHRYDEDRDHRRDQRNVSDYDSEELRKFEEDYKSDRLGQYV"
30+
+ "FSDLNSAVKGLVVQPIHL-NKEVNRTVIIDSICKESAEKVRFEFGKGEDAREI");
31+
ProteinSequence pSeq3 = new ProteinSequence(
32+
"RPTH---GGLSLNIDVSTTMILEPGPVIEF-----LKANQSVETPRQIDWI"
33+
+ "-----KAAKML--KHMRVKATHRNMEFKIIGLSSKPCNQQLFSMKIKDGEREV");
34+
35+
msa.addAlignedSequence(pSeq1);
36+
msa.addAlignedSequence(pSeq2);
37+
msa.addAlignedSequence(pSeq3);
38+
39+
TreeConstructor<ProteinSequence, AminoAcidCompound> treeConstructor =
40+
new TreeConstructor<ProteinSequence, AminoAcidCompound>(
41+
msa, TreeType.NJ, TreeConstructionAlgorithm.PID,
42+
new ProgressListenerStub());
43+
treeConstructor.process();
44+
String newick = treeConstructor.getNewickString(true, true);
45+
46+
System.out.println(newick);
47+
}
48+
}

biojava-phylo/src/main/java/org/biojava/nbio/phylo/ProgressListenerStub.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ProgressListenerStub implements NJTreeProgressListener {
3838
private static final Logger logger = LoggerFactory.getLogger(ProgressListenerStub.class);
3939

4040
String priorState = "";
41+
4142
@Override
4243
public void progress(Object njtree,String state, int percentageComplete) {
4344
if(!priorState.equals(state)){

0 commit comments

Comments
 (0)