Пример #1
0
void addChainT(struct chrom *chrom, struct chrom *otherChrom, struct chain *chain)
/* Add T side of chain to fill/gap tree of chromosome. 
 * This is the easier case since there are no strand
 * issues to worry about. */
{
struct slRef *spaceList;
struct slRef *ref;
struct cBlock *startBlock, *block, *nextBlock;
struct gap *gap;

spaceList = findSpaces(chrom->spaces,chain->tStart,chain->tEnd);
startBlock = chain->blockList;
for (ref = spaceList; ref != NULL; ref = ref->next)
    {
    struct space *space = ref->val;
    struct fill *fill;
    int gapStart, gapEnd;
    for (;;)
        {
	nextBlock = startBlock->next;
	if (nextBlock == NULL)
	    break;
	gapEnd = nextBlock->tStart;
	if (gapEnd > space->start)
	    break;
	startBlock = nextBlock;
	}
    if ((fill = fillSpace(chrom, space, chain, startBlock, FALSE)) != NULL)
	{
	for (block = startBlock; ; block = nextBlock)
	    {
	    nextBlock = block->next;
	    if (nextBlock == NULL)
		break;
	    gapStart = block->tEnd;
	    gapEnd = nextBlock->tStart;
	    if (strictlyInside(space->start, space->end, gapStart, gapEnd))
		{
		int qs = block->qEnd;
		int qe = nextBlock->qStart;
		if (chain->qStrand == '-')
		    reverseIntRange(&qs, &qe, chain->qSize);
		gap = gapNew(gapStart, gapEnd, qs, qe);
		addSpaceForGap(chrom, gap);
		slAddHead(&fill->gapList, gap);
		}
	    }
	freez(&ref->val);	/* aka space */
	}
    }
slFreeList(&spaceList);
}
Пример #2
0
void addChainQ(struct chrom *chrom, struct chrom *otherChrom, struct chain *chain)
/* Add Q side of chain to fill/gap tree of chromosome. 
 * For this side we have to cope with reverse strand
 * issues. */
{
struct slRef *spaceList;
struct slRef *ref;
struct cBlock *startBlock, *block, *nextBlock;
int gapStart, gapEnd;
struct gap *gap;
boolean isRev = (chain->qStrand == '-'); 
int qStart = chain->qStart, qEnd = chain->qEnd;

if (isRev)
    {
    reverseIntRange(&qStart, &qEnd, chain->qSize);
    reverseBlocksQ(&chain->blockList, chain->qSize);
    }
spaceList = findSpaces(chrom->spaces,qStart,qEnd);
startBlock = chain->blockList;

for (ref = spaceList; ref != NULL; ref = ref->next)
    {
    struct space *space = ref->val;
    struct fill *fill;
    for (;;)
        {
	nextBlock = startBlock->next;
	if (nextBlock == NULL)
	    break;
	gapEnd = nextBlock->qStart;
	if (gapEnd > space->start)
	    break;
	startBlock = nextBlock;
	}
    if ((fill = fillSpace(chrom, space, chain, startBlock, TRUE)) 
    	!= NULL)
	{
	for (block = startBlock; ; block = nextBlock)
	    {
	    nextBlock = block->next;
	    if (nextBlock == NULL)
		break;
	    gapStart = block->qEnd;
	    gapEnd = nextBlock->qStart;
	    if (strictlyInside(space->start, space->end, gapStart, gapEnd))
		{
		int ts, te;
		if (chain->qStrand == '+')
		    {
		    ts = block->tEnd;
		    te = nextBlock->tStart;
		    }
		else
		    {
		    ts = nextBlock->tStart;
		    te = block->tEnd;
		    }
		gap = gapNew(gapStart, gapEnd, ts, te);
		addSpaceForGap(chrom, gap);
		slAddHead(&fill->gapList, gap);
		}
	    }
	freez(&ref->val);	/* aka space */
	}
    }
slFreeList(&spaceList);
if (isRev)
    reverseBlocksQ(&chain->blockList, chain->qSize);
}
std::shared_ptr<INodeSystem> NodeSystemBuilder::create() {

	for (auto& link: me->links) {

		if (!me->useExtraNodes) {
			me->linkBuildNodes(link.first, link.second);
			me->putSpring(link.first, link.second);
			continue;
		}

		// both linked nodes
		auto nodeFrom = me->model->getNode(link.first);
		auto nodeTo = me->model->getNode(link.second);

		size_t subNodeCount = 1;

		if (me->useConstantNumberOfExtraNodes) {
			subNodeCount = me->defaultExtraNodesPerEdge;
		}
		else {
			double length = glm::length(nodeTo->getPosition() - nodeFrom->getPosition());
			subNodeCount = (size_t) glm::round(length / me->defaultUnitsPerExtraNode);
		}

		if(subNodeCount == 0)
			std::cout << "subnodes cannot be placed" << "\n";

		// fill space between two nodes by adding a number of extra nodes
		auto points = fillSpace(nodeFrom->getPosition(), nodeTo->getPosition(), subNodeCount);
		std::vector<size_t> subNodeIds;

		for (glm::dvec3& point: points) {
			std::cout << "sn:" << point.x << " " << point.y << "\n";
			subNodeIds.push_back(addNode(me->defaultSubNodeMass, point));
		}

		if(subNodeCount == 0)
		{
			std::cout << "subnodesCount = 0 after fillSpace" << "\n";
			continue;
		}

		// link all nodes to make a chain
		for (size_t i = 0; i < subNodeIds.size() - 1; ++i) {
			me->linkBuildNodes(subNodeIds[i], subNodeIds[i + 1]);
			me->putSpring(subNodeIds[i], subNodeIds[i + 1]);
		}
		// link main nodes with head and tail of list of sub-nodes
		me->linkBuildNodes(link.first, subNodeIds.front());
		me->linkBuildNodes(subNodeIds.back(), link.second);

		std::cout << "connect subnodes to link edges" << "\n";
		me->putSpring(link.first, subNodeIds.front());
		me->putSpring(subNodeIds.back(), link.second);
	}
	std::cout << "Torsion springs mounting" << "\n";
	for (auto& center: me->buildNodes) {
		for (auto& left: center->prev) {
			for (auto& right: center->next) {
				me->putTorsionSpring(left, center->id, right);
			}
		}
	}

	// mount contstraints
	for (auto& constraint: me->model->constraints)
		constraint->assignToSystem(me->model);

	me->model->grip->assignToSystem(me->model);

	return me->model;
}