*/
package org.vamsas.test.objects;
-import org.vamsas.objects.core.Alignment;
-import org.vamsas.objects.core.AlignmentSequence;
-import org.vamsas.objects.core.DataSet;
-import org.vamsas.objects.core.Sequence;
-import org.vamsas.objects.core.VAMSAS;
-import org.vamsas.objects.utils.Seq;
-import org.vamsas.objects.utils.SymbolDictionary;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.vamsas.objects.core.*;
+import org.vamsas.objects.utils.*;
+import org.vamsas.objects.utils.document.*;
+import org.vamsas.test.simpleclient.ArchiveReports;
/**
* @author jim
* test XSD-Java binding classes in org.vamsas.objects.core
*/
public class Core {
+ static Log log = LogFactory.getLog("org.vamsas.test.objects.Core");
+
/**
*
* complete any automatically completable entries in the dataset
* @param ds
*/
+ public static String user = "org.vamsas.test.objects.Core";
+
public static void complete(DataSet ds) {
Sequence[] q = ds.getSequence();
for (int i=0,j=q.length; i<j; i++) {
VAMSAS v=new VAMSAS();
DataSet ds = new DataSet();
ds.addSequence(Seq.newSequence("Dummy1","ASDFLEQ",SymbolDictionary.STANDARD_AA, 5, 11));
+ ds.addSequence(Seq.newSequence("Dummy2","ASFLEQ",SymbolDictionary.STANDARD_AA, 5, 10));
+ ds.addSequence(Seq.newSequence("Dummy3","ADFEQ",SymbolDictionary.STANDARD_AA, 3, 7));
+ ds.setProvenance(ProvenanceStuff.newProvenance(user, "constructed some dummy sequences"));
complete(ds);
v.addDataSet(ds);
Alignment al = new Alignment();
-
- al.addAlignmentSequence(new AlignmentSequence());
+ al.setProvenance(ProvenanceStuff.newProvenance(user, "Created dummy alignment"));
+ // rely on newAlignmentSequence to set start/end correctly
+ al.addAlignmentSequence(Seq.newAlignmentSequence("Aligned1", "ASDFLEQ", ds.getSequence(0), -1, -1));
+ al.addAlignmentSequence(Seq.newAlignmentSequence("Aligned2", "AS-FLEQ", ds.getSequence(1), -1, -1));
+ al.addAlignmentSequence(Seq.newAlignmentSequence("Aligned3", "A-DF-EQ", ds.getSequence(2), -1, -1));
+ al.setGapChar("-");
+ ds.addAlignment(al);
+ // TODO: create annotations
+ // TODO: create tree
return v;
}
/**
* @param args
*/
public static void main(String[] args) {
- // TODO Auto-generated method stub
-
+ VamsasDocument doc = DocumentStuff.newVamsasDocument(new VAMSAS[] { getDemoVamsas() },
+ ProvenanceStuff.newProvenance("org.vamsas.objects.test.Core", "Created demo vamsasDocument"),
+ VersionEntries.latestVersion());
+ ArchiveReports.reportDocument(doc, null, true);
}
-
}
import java.io.InputStream;
import org.vamsas.client.simpleclient.VamsasArchiveReader;
+import org.vamsas.objects.core.Alignment;
import org.vamsas.objects.core.ApplicationData;
+import org.vamsas.objects.core.DataSet;
+import org.vamsas.objects.core.Entry;
+import org.vamsas.objects.core.Provenance;
+import org.vamsas.objects.core.Tree;
import org.vamsas.objects.core.VAMSAS;
import org.vamsas.objects.core.VamsasDocument;
-
+/**
+ * this class contains static methods for writing info to stdout about a vamsas document
+ * Methods have a 'cascade' switch to indicate if sub-objects should have info printed on them.
+ * Methods return true or false - indicating if the object was valid or not
+ * TODO: LATER: propagate true/false return so that an invalid vamsas object invalidates the whole document
+ * @author jimp
+ *
+ */
public class ArchiveReports {
/**
* print an informative summary on a VamsasDocument
* @param archive - document source archive for resolving any appData refs
* @return
*/
- public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive) {
+ public static boolean reportProvenance(Provenance p) {
+ if (p==null) {
+ System.out.println("No Provenance");
+ return false;
+ }
+ Entry[] pe = p.getEntry();
+ for (int i=0; i<pe.length; i++)
+ System.out.println(pe[i].getDate()+"\t'"+pe[i].getUser()+"'\t"+pe[i].getAction());
+ return true;
+ }
+ public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive, boolean cascade) {
if (document!=null) {
- System.out.print("Vamsas Document version '"+document.getVersion()+"'");
+ System.out.println("Vamsas Document version '"+document.getVersion()+"'");
+ reportProvenance(document.getProvenance());
System.out.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" elements.\n");
+ if (document.getVAMSASCount()>0 && cascade)
+ rootReport(document.getVAMSAS(), true);
if (document.getApplicationDataCount()>0) {
System.out.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n");
ApplicationData appd[] = document.getApplicationData();
/**
* summarises all the datasets in a vamsas document.
* @param roots
+ * @param cascade TODO
* @return
*/
- public static boolean rootReport(VAMSAS[] roots) {
+ public static boolean rootReport(VAMSAS[] roots, boolean cascade) {
if (roots!=null) {
for (int i=0; i<roots.length; i++) {
VAMSAS r = roots[i];
+ int ds, tr;
System.out.print("Vamsas Root "+i+" (id="
+((r.getId()!=null) ? r.getId():"<none>")
- +") contains "+r.getDataSetCount()+" DataSets, "
- + r.getTreeCount()+" Global trees");
+ +") contains "+(ds=r.getDataSetCount())+" DataSets, "
+ + (tr=r.getTreeCount())+" Global trees\n");
+ if (cascade) {
+ for (int j=0; j<ds; j++) {
+ System.out.println("Dataset "+j);
+ cascade = datasetReport(r.getDataSet(j), true) && cascade ;
+ }
+ for (int j=0; j<tr; j++) {
+ System.out.println("Global tree "+j);
+ cascade = treeReport(r.getTree(j), true) && cascade;
+ }
+ }
}
return true;
}
return false;
}
+ public static boolean datasetReport(DataSet ds, boolean cascade) {
+ if (cascade)
+ reportProvenance(ds.getProvenance());
+ System.out.println("Dataset contains : "+ds.getSequenceCount()
+ +" sequences, "+ds.getAlignmentCount()+" alignments and "+ds.getTreeCount()+" trees.");
+ if (cascade)
+ alignmentReport(ds.getAlignment(), true);
+ return true;
+ }
+ public static boolean alignmentReport(Alignment[] al, boolean cascade) {
+ boolean val=true;
+ if (al!=null && al.length>0) {
+ for (int i=0; i<al.length; i++) {
+ System.out.println("Alignment "+i);
+ if (cascade)
+ reportProvenance(al[i].getProvenance());
+ System.out.println("Involves "+al[i].getAlignmentSequenceCount()+" sequences, has "
+ +al[i].getAlignmentAnnotationsCount()+" annotations and "+al[i].getTreeCount()+" trees.");
+ if (cascade) {
+ for (int t=0; t<al[i].getTreeCount(); t++)
+ treeReport(al[i].getTree(t), true);
+ }
+ }
+ }
+ return val;
+ }
+ public static boolean treeReport(Tree t, boolean cascade) {
+ System.out.println("Tree: '"+t.getTitle()+"'");
+ return !cascade || reportProvenance(t.getProvenance());
+ }
}