Пример #1
0
VALUE MethodResultJni::enumerateRubyObjects(VALUE klass)
{
    RAWTRACE("enumerateRubyObjects");

    JNIEnv *env = jniInit();
    if (!env) {
        RAWLOG_ERROR("JNI initialization failed");
        rb_raise(rb_eRuntimeError,"JNI initialization failed");
        return Qnil;;
    }

    if(getResultType(env) == typeList)
    {
        CHoldRubyValue valArray(rho_ruby_create_array());

        HStringVector pIDs = rho_cast<HStringVector>(env, getListResult(env));

        for(HStringVector::element_type::size_type i = 0; i < pIDs->size(); ++i)
        {
            VALUE valObj = rho_ruby_create_object_with_id( klass, (*pIDs)[i].c_str() );
            rho_ruby_add_to_array(valArray, valObj);
        }

        RAWTRACE("has enumerated");
        reset(env);
        return valArray;
    } else
    {
        return toRuby();
    }

}
Пример #2
0
void MultAlignmentFormat::fill(
		const HMultAlignment & src,
		const HStringVector & sequences,
		const ExpansionType & expansion_type )
{
	debug_func_cerr( 5 );
	if (sequences->size() != src->getNumSequences())
		throw AlignlibException("MultAlignmentFormat.cpp: number of sequences in src and sequences do not match");

	for (int x = 0; x < src->getNumSequences(); ++x )
		if ( (*src)[x]->getColTo() > 0 && (*src)[x]->getColTo() > (*sequences)[x].size())
			throw AlignlibException("MultAlignmentFormat.cpp: sequence length in mali longer than in provided sequence");

	mData.clear();
}
Пример #3
0
void writeNewHampshire(
		std::ostream & output,
		const HTree & tree,
		const HStringVector & labels )
{
	debug_func_cerr( 5 );

	Node node;
	std::vector<Node> node_stack;

	Node root = tree->getRoot();

	node_stack.push_back( root ); // push root on stack

	bool docomma = false;

	Node numleaves = tree->getNumLeaves();

	if (labels->size() > 0 && labels->size() != numleaves)
		throw AlignlibException( "writeNewHampshire: number of leaves and number of labels are different");

	Node last_interior_node = 2 * numleaves - 1;
	TreeWeight weight = 0;

	debug_cerr( 5, "starting traversal from root " << root << " with " << numleaves << " leaves" );

	while (!node_stack.empty())
	{

		node = node_stack.back();
		node_stack.pop_back();

		debug_cerr( 5, "Processing node " << node << " root=" << root );

		if (node != root && node < last_interior_node )
			weight = tree->getWeight( node, tree->getParent( node ));


		if (node < numleaves)
		{                   // process leaves: print name:branchlength
			if (docomma)
				output << ",";

			if (labels->size() > 0)
			{
				output << (*labels)[node];
			} else
			{
				output << node;
			}

			output << ":" << weight;
			docomma = true;

		}
		else
		{
			if (node <= last_interior_node)
			{             // process interior nodes
				if (docomma) output << "," << endl;

				// 1) print a '('
				output << "(";

				// 2) push on stack: ), right child, left child

				node_stack.push_back( node + numleaves );
				node_stack.push_back( tree->getRightChild(node) );
				node_stack.push_back( tree->getLeftChild(node) );

				// 3) record branch lengths
				docomma = false;

			}
			else
			{                                      // close interior node
				// print a ):branchlength (if root, just print ")" )
				if (node == root + numleaves)
				{
					output << ")\n";
				}
				else
				{
					node = node - numleaves;
					output << "):" << tree->getWeight( node, tree->getParent(node) );
				}

				docomma = true;
			}
		}
	}
}