|
| 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 | +} |
0 commit comments