#include "TreeDecomposeC.h" #include "CipresHelper.h" #include "CipresRegistry.h" #include #include using namespace std; /* If first arg is "-ns" uses naming service. Next arg is the name of the object we want (eg. "TreeDecompose") Subsequent args identify the Naming Service: eg. -ORBInitRef NameService=corbaloc:iiop:localhost:1050/NameService Otherwise first arg is an ior file name. */ int main(int argc, char *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "orb1"); CORBA::Object_var object; if (argc < 2) { cerr << "usage: " << argv[0] << " iorFileName" << endl; return 1; } if (strcmp(argv[1], "-ns") == 0) { // todo: check for right number of arguments before accessing argv CipresRegistry registry(orb.in()); object = registry.nsFind(argv[2]); } else { fstream f(argv[1], ios::in); CORBA::String_var iorstring; f >> iorstring; cout << "ior is: " << iorstring << endl; object = orb->string_to_object(iorstring); } if (CORBA::is_nil(object.in())) { cout << "Got nil object ref" << endl; return 1; } CipresIDL_api1::TreeDecompose_var td_var = CipresIDL_api1::TreeDecompose::_narrow(object.in()); if (CORBA::is_nil(td_var.in())) { cout << "Narrow to TreeDecompose type failed" << endl; return 1; } CipresIDL_api1::Tree tree; /* tree.m_newick = CORBA::string_dup( "((((a:.1,b:1):1,(t:3.2,g:1):2):1,(c:2,d:1):1):1,(((e:1,f:1):1,u:1):1,v:1.2,(x:0.2,y:1):1):1)"); */ tree.m_newick = CORBA::string_dup( "((((2:.1,3:1):1,(1:3.2,10:1):2):1,(11:2,12:1):1):1,(((14:1,15:1):1,20:1):1,16:1.2,(30:0.2,31:1):1):1)"); CipresIDL_api1::TaxonSeqSeq_var subsets = td_var->leafSetDecompose(tree); cout << "Decomposed tree: " << tree.m_newick.in() << endl; cout << "Into subsets: " << endl; cout << *subsets << endl; cout << "Sending bad tree - missing last ), expect an exception" << endl; try { tree.m_newick = CORBA::string_dup( "((((1:.1,2:1):1,(3:3.2,4:1):2):1,(5:2,6:1):1):1,(((7:1,8:1):1,9:1):1,10:1.2,(11:0.2,12:1):1):1"); subsets = td_var->leafSetDecompose(tree); cout << "Decomposed tree: " << tree.m_newick.in() << endl; cout << "Into subsets: " << endl; cout << *subsets << endl; } catch(CipresIDL_api1::TreeParseException) { cout << "Caught TreeParseException" << endl; } cout << "Sending another good tree - a small one" << endl; tree.m_newick = CORBA::string_dup( "((((1:1,2:2):3.2,(3:5,4:1):7):3.6,(5:1.2,6):2):3.7,((7:5.5,8:3):2.2,9:4):10)"); subsets = td_var->leafSetDecompose(tree); cout << "Decomposed tree: " << tree.m_newick.in() << endl; cout << "Into subsets: " << endl; cout << *subsets << endl; #ifdef NOTDEF CORBA::Object_var object = orb->string_to_object(iorstring); CipresIDL_api1::TreeInfer_var ti_var = CipresIDL_api1::TreeInfer::_narrow(object.in()); CipresIDL_api1::DataMatrix chars; chars.m_symbols= "ACGT"; chars.m_numStates = 4; chars.m_stride = 1; chars.m_numCharacters = 4; chars.m_matrix.length(2); chars.m_matrix[0].length(3); chars.m_matrix[0][0] = 0x01; chars.m_matrix[0][1] = 0x02; chars.m_matrix[0][2] = 0xff; chars.m_matrix[1].length(3); chars.m_matrix[1][0] = 0x01; chars.m_matrix[1][1] = 0x03; chars.m_matrix[1][2] = 0x07; cout << "setting matrix:" << endl; cout << chars << endl; ti_var->setMatrix(chars); #endif cout << "Shutting down dcm3" << endl; td_var->remove(); orb->destroy(); } catch(CORBA::Exception &ex) { cerr << "CORBA Exception raised: " << ex << endl; return 1; } return 0; }