|
1 | 1 | package demo; |
2 | 2 |
|
| 3 | +import java.io.InputStream; |
| 4 | +import java.util.LinkedHashMap; |
| 5 | + |
3 | 6 | import org.biojava.nbio.core.sequence.MultipleSequenceAlignment; |
4 | 7 | import org.biojava.nbio.core.sequence.ProteinSequence; |
5 | 8 | import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; |
| 9 | +import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet; |
| 10 | +import org.biojava.nbio.core.sequence.io.FastaReader; |
| 11 | +import org.biojava.nbio.core.sequence.io.GenericFastaHeaderParser; |
| 12 | +import org.biojava.nbio.core.sequence.io.ProteinSequenceCreator; |
6 | 13 | import org.biojava.nbio.phylo.TreeConstructionAlgorithm; |
7 | 14 | import org.biojava.nbio.phylo.ProgressListenerStub; |
8 | 15 | import org.biojava.nbio.phylo.TreeConstructor; |
9 | 16 | import org.biojava.nbio.phylo.TreeType; |
10 | 17 |
|
11 | 18 | /** |
12 | | - * This demo contains the CookBook examples to create a phylogenetic tree from a |
| 19 | + * This demo contains the CookBook example to create a phylogenetic tree from a |
13 | 20 | * given multiple sequence alignment (MSA). |
14 | 21 | * |
| 22 | + * @author Scooter Willis |
15 | 23 | * @author Aleix Lafita |
16 | 24 | * |
17 | 25 | */ |
18 | 26 | public class DemoTreeConstructor { |
19 | 27 |
|
20 | 28 | public static void main(String[] args) throws Exception { |
21 | 29 |
|
22 | | - MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msa = new |
23 | | - MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound>(); |
| 30 | + InputStream inStream = TreeConstructor.class |
| 31 | + .getResourceAsStream("/PF00104_small.fasta"); |
24 | 32 |
|
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"); |
| 33 | + FastaReader<ProteinSequence, AminoAcidCompound> fastaReader = |
| 34 | + new FastaReader<ProteinSequence, AminoAcidCompound>( |
| 35 | + inStream, new GenericFastaHeaderParser<ProteinSequence, |
| 36 | + AminoAcidCompound>(), new ProteinSequenceCreator( |
| 37 | + AminoAcidCompoundSet.getAminoAcidCompoundSet())); |
| 38 | + |
| 39 | + LinkedHashMap<String, ProteinSequence> proteinSequences = |
| 40 | + fastaReader.process(); |
| 41 | + |
| 42 | + inStream.close(); |
34 | 43 |
|
35 | | - msa.addAlignedSequence(pSeq1); |
36 | | - msa.addAlignedSequence(pSeq2); |
37 | | - msa.addAlignedSequence(pSeq3); |
| 44 | + MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msa = |
| 45 | + new MultipleSequenceAlignment<ProteinSequence, |
| 46 | + AminoAcidCompound>(); |
| 47 | + |
| 48 | + for (ProteinSequence proteinSequence : proteinSequences.values()) { |
| 49 | + msa.addAlignedSequence(proteinSequence); |
| 50 | + } |
38 | 51 |
|
| 52 | + long readTime = System.currentTimeMillis(); |
39 | 53 | TreeConstructor<ProteinSequence, AminoAcidCompound> treeConstructor = |
40 | 54 | new TreeConstructor<ProteinSequence, AminoAcidCompound>( |
41 | | - msa, TreeType.NJ, TreeConstructionAlgorithm.PID, |
| 55 | + msa, TreeType.NJ, TreeConstructionAlgorithm.PID, |
42 | 56 | new ProgressListenerStub()); |
43 | 57 |
|
44 | 58 | treeConstructor.process(); |
| 59 | + long treeTime = System.currentTimeMillis(); |
45 | 60 | String newick = treeConstructor.getNewickString(true, true); |
46 | 61 |
|
47 | 62 | System.out.println(newick); |
| 63 | + System.out.println("Tree time {" + (treeTime - readTime) + "}"); |
| 64 | + |
48 | 65 | } |
49 | 66 | } |
0 commit comments