Skip to content

Commit

Permalink
Adding tests for matrix row implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rvosa authored and yeban committed Mar 19, 2012
1 parent 7c75cbb commit c803408
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/org/nexml/model/TestAnnotationTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testXsdType () {
public void parseMetaTypes() {
String nexmlRoot = System.getenv("NEXML_ROOT");
if ( nexmlRoot == null ) {
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
}
File file = new File(nexmlRoot+"/examples/meta_types.xml");
Document doc = null;
Expand Down
4 changes: 2 additions & 2 deletions test/org/nexml/model/TestFileParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class TestFileParse {
public void parseCharacters() {
String nexmlRoot = System.getenv("NEXML_ROOT");
if ( nexmlRoot == null ) {
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
}
File file = new File(nexmlRoot+"/examples/trees.xml");
File file = new File(nexmlRoot+"/examples/characters.xml");
Document doc = null;
try {
doc = DocumentFactory.parse(file);
Expand Down
52 changes: 52 additions & 0 deletions test/org/nexml/model/TestMatrixRows.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.nexml.model;

import java.net.URI;

import org.junit.Test;


public class TestMatrixRows {
URI tbTermsUri = URI.create("http://purl.org/phylo/treebase/2.0/terms#");

@Test
public void testCreateDNAMatrix () {

// create a document
Document doc = DocumentFactory.safeCreateDocument();

// create a taxa block with 5 taxa
OTUs otus = doc.createOTUs();
for ( int i = 1; i <= 5; i++ ) {
OTU otu = otus.createOTU();
otu.setLabel("Taxon_"+i);
}

// create a DNA matrix for the taxa
MolecularMatrix matrix = doc.createMolecularMatrix(otus, MolecularMatrix.DNA);
CharacterStateSet stateSet = matrix.getCharacterStateSet();


// populate
String[] symbols = { "A", "C", "G", "T" };
for ( OTU otu : otus.getAllOTUs() ) {
StringBuffer sb = new StringBuffer();

for ( int i = 0; i <= 9; i++ ) {
Long l = new Long(Math.round(Math.random()*(symbols.length-1)));
sb.append(symbols[l.intValue()]);
matrix.createCharacter(stateSet);
}
MatrixRow<CharacterState> row = matrix.getRowObject(otu);
Annotation annotation = row.addAnnotationValue("tb:rowSegment", tbTermsUri,new String());
annotation.addAnnotationValue("tb:segmentStart", tbTermsUri, 1);
annotation.addAnnotationValue("tb:segmentEnd", tbTermsUri, 10);
annotation.addAnnotationValue("tb:accession", tbTermsUri, "DC567254");
row.setSeq(sb.toString());
}

// print document
System.out.println(doc.getXmlString());

}

}
4 changes: 2 additions & 2 deletions test/org/nexml/model/TestParseTrees.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestParseTrees {
public void parseFloatTree() throws Throwable {
String nexmlRoot = System.getenv("NEXML_ROOT");
if ( nexmlRoot == null ) {
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
}
Document document = DocumentFactory.parse(new File(nexmlRoot+"/examples/trees.xml"));
//System.out.println(document.getXmlString());
Expand Down Expand Up @@ -49,7 +49,7 @@ public void parseFloatTree() throws Throwable {
public void parseIntTree() throws Throwable {
String nexmlRoot = System.getenv("NEXML_ROOT");
if ( nexmlRoot == null ) {
nexmlRoot = "/Users/rvosa/Documents/workspace/nexml/trunk/nexml";
nexmlRoot = "/Users/rvosa/Dropbox/documents/projects/current/nexml/src/nexml/trunk/nexml";
}
Document document = DocumentFactory.parse(new File(nexmlRoot+
"/examples/02_dogfish_no_taxrefs.xml"));
Expand Down

0 comments on commit c803408

Please sign in to comment.