Skip to content

Commit c803408

Browse files
rvosayeban
authored andcommitted
Adding tests for matrix row implementation
1 parent 7c75cbb commit c803408

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

test/org/nexml/model/TestAnnotationTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testXsdType () {
105105
public void parseMetaTypes() {
106106
String nexmlRoot = System.getenv("NEXML_ROOT");
107107
if ( nexmlRoot == null ) {
108-
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
108+
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
109109
}
110110
File file = new File(nexmlRoot+"/examples/meta_types.xml");
111111
Document doc = null;

test/org/nexml/model/TestFileParse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class TestFileParse {
2121
public void parseCharacters() {
2222
String nexmlRoot = System.getenv("NEXML_ROOT");
2323
if ( nexmlRoot == null ) {
24-
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
24+
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
2525
}
26-
File file = new File(nexmlRoot+"/examples/trees.xml");
26+
File file = new File(nexmlRoot+"/examples/characters.xml");
2727
Document doc = null;
2828
try {
2929
doc = DocumentFactory.parse(file);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.nexml.model;
2+
3+
import java.net.URI;
4+
5+
import org.junit.Test;
6+
7+
8+
public class TestMatrixRows {
9+
URI tbTermsUri = URI.create("http://purl.org/phylo/treebase/2.0/terms#");
10+
11+
@Test
12+
public void testCreateDNAMatrix () {
13+
14+
// create a document
15+
Document doc = DocumentFactory.safeCreateDocument();
16+
17+
// create a taxa block with 5 taxa
18+
OTUs otus = doc.createOTUs();
19+
for ( int i = 1; i <= 5; i++ ) {
20+
OTU otu = otus.createOTU();
21+
otu.setLabel("Taxon_"+i);
22+
}
23+
24+
// create a DNA matrix for the taxa
25+
MolecularMatrix matrix = doc.createMolecularMatrix(otus, MolecularMatrix.DNA);
26+
CharacterStateSet stateSet = matrix.getCharacterStateSet();
27+
28+
29+
// populate
30+
String[] symbols = { "A", "C", "G", "T" };
31+
for ( OTU otu : otus.getAllOTUs() ) {
32+
StringBuffer sb = new StringBuffer();
33+
34+
for ( int i = 0; i <= 9; i++ ) {
35+
Long l = new Long(Math.round(Math.random()*(symbols.length-1)));
36+
sb.append(symbols[l.intValue()]);
37+
matrix.createCharacter(stateSet);
38+
}
39+
MatrixRow<CharacterState> row = matrix.getRowObject(otu);
40+
Annotation annotation = row.addAnnotationValue("tb:rowSegment", tbTermsUri,new String());
41+
annotation.addAnnotationValue("tb:segmentStart", tbTermsUri, 1);
42+
annotation.addAnnotationValue("tb:segmentEnd", tbTermsUri, 10);
43+
annotation.addAnnotationValue("tb:accession", tbTermsUri, "DC567254");
44+
row.setSeq(sb.toString());
45+
}
46+
47+
// print document
48+
System.out.println(doc.getXmlString());
49+
50+
}
51+
52+
}

test/org/nexml/model/TestParseTrees.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TestParseTrees {
1818
public void parseFloatTree() throws Throwable {
1919
String nexmlRoot = System.getenv("NEXML_ROOT");
2020
if ( nexmlRoot == null ) {
21-
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
21+
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
2222
}
2323
Document document = DocumentFactory.parse(new File(nexmlRoot+"/examples/trees.xml"));
2424
//System.out.println(document.getXmlString());
@@ -49,7 +49,7 @@ public void parseFloatTree() throws Throwable {
4949
public void parseIntTree() throws Throwable {
5050
String nexmlRoot = System.getenv("NEXML_ROOT");
5151
if ( nexmlRoot == null ) {
52-
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
52+
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
5353
}
5454
Document document = DocumentFactory.parse(new File(nexmlRoot+
5555
"/examples/02_dogfish_no_taxrefs.xml"));

0 commit comments

Comments
 (0)