void ReadContainer::addUpstreamRead ( const Genome& genome, const chr_num_t chr, const chr_pos_t pos ) {
  assume(pos <= 0, "3' ends need to be given as negative numbers!");
  int ipos = pos - 1; // fix difference in one-based offsets
  auto upstr = genome.getReadAt(chr, ipos); // 3' ends are linked at negative indices
  if (upstr != nullptr) {

    // check if this is a multistrand splice junction
    if (genome.multistrand != nullptr &&
	(upstr->chromosome != chromosome || (upstr->flags & MULTISTRAND) == MULTISTRAND)) {
      upstr->flags |= MULTISTRAND;
      flags |= MULTISTRAND;
      genome.multistrand->insert(shared_from_this());
      genome.multistrand->insert(upstr);
    }
    
    int link = findLink(upstr, false); // search link  upstr <= this
    int backLink = upstr->findLink(shared_from_this()); // search link upstr => this

    if (link == -1) { // upstr <= this unknown yet
      fivePrimeRead->push_back(upstr);
    }

    if (backLink >= 0) { // upstr => this known
      upstr->threePrimeRefs->at(backLink)++;
    }
    else { // upstr => this new
      upstr->threePrimeRead->push_back(shared_from_this());
      upstr->threePrimeRefs->push_back(1);
    }
  }
}
Example #2
0
BOOL COMM_ListRemoveAtIndex(COMM_List *list, void **obj, int index) {
	Link *l;
	if(index>=list->currentSize || index<0) return FALSE;

	//find the link
	l = findLink(list, index);
	if(obj!=NULL) *obj = l->obj;

	//remove it
	if(l->prev!=NULL)  l->prev->next = l->next;
	if(l->next!=NULL)  l->next->prev = l->prev;
	if(list->start==l) list->start   = l->next;
	if(list->end==l)   list->end     = l->prev;

	//adjust our saved index
	if(index < list->lastIndex) {
		list->lastIndex--;
	}
	else if(index == list->lastIndex) {
		list->lastIndex--;
		list->last = l->prev;
		if(list->last==NULL) list->lastIndex = -4;
	}

	list->currentSize--;

	//we removed it, now free it
	NTPfree(l);
	return TRUE;
}
/**
 *  This function unlinks this node from other.
 *
 *  @param other        The node to unlink from.
 */
void EditorChunkItemLinkable::removeLink(EditorChunkItemLinkable* other)
{
    if (other == NULL)
        return;

    ChunkLinkPtr link = findLink(other);
    if (link != NULL)
        removeLink(link);
}
Example #4
0
IMapping * HashTable::createLink(const void *key)
{
   IMapping * match = findLink(key);
   if (!match)
   {
      match = newMapping(key);
      if (match) add(*match);            // link for hash table
   }
   return match;
}
Example #5
0
BOOL COMM_ListObjectAtIndex(COMM_List *list, void **obj, int index) {
	Link *l;
	if(index>=list->currentSize || index<0) 
	{
		*obj = NULL;
		return FALSE;
	}
	
	//find the link
	l = findLink(list, index);
	*obj = l->obj;

	return TRUE;
}
void ReadContainer::addDownstreamRead ( const Genome& genome, const chr_num_t chr, const chr_pos_t pos ) {
  auto dnstr = genome.getReadAt(chr, pos);
  if (dnstr != nullptr) {
    // check if this is a multistrand splice junction
    if (dnstr->chromosome != chromosome && !(dnstr->flags & MULTISTRAND) ) {
      flags |= MULTISTRAND;
      genome.multistrand->insert(shared_from_this());    // adding one multistrand seed suffices
    }

    int link = findLink(dnstr); // search link this => dnstr
    int backLink = dnstr->findLink(shared_from_this(), false); // search link this <= dnstr

    if (link == -1) { // this => dnstr unknown yet
      threePrimeRead->push_back(dnstr);
      threePrimeRefs->push_back(1);
    }
    else { // this => dnstr known
      threePrimeRefs->at(link)++;
    }
    if (backLink == -1) { // this <= dnstr unknown yet
      dnstr->fivePrimeRead->push_back(shared_from_this());
    }
  }
}
int main(void){
  Node * head, * curr;
  head = NULL;


  for (int i = 0; i < 20; i++){
    curr = (Node *)malloc(sizeof(Node));
    curr->val = rand() % 50;
    curr->next = head;
    head = curr;
  }
  curr = head;

  printList(curr);
  findLink(curr, 4);
  printList(curr);
}
Example #8
0
void CNetwork::readInputFile()
{
    // open the TRAF file
    FILE *file_trf = NULL;
    if (file_trf = fopen(m_traf_input_file, "r"))
    {
        sprintf(out_buf, "Opened file: \"%s\".", m_traf_input_file);
        OutputString(out_buf, strlen(out_buf), SIM_COLOR_RGB, RTE_MESSAGE_RGB);
        // parse the time periods
        processTimePeriods(file_trf);
        rewind(file_trf);
        // create the node list
        getNodes(file_trf);
        rewind(file_trf);
        // create the link list
        getLinks(file_trf);
        rewind(file_trf);
        // find the opposing link for each link, if one exists
        int up = 0;
        int down = 0;
        CLink *link = NULL;
        POSITION pos = m_link_list.GetHeadPosition();
        while (pos != NULL)
        {
            link = m_link_list.GetNext(pos);
            up = link->getOpposingNodeId();
            down = link->m_dn_node->getId();
            CLink *opposing = NULL;
            opposing = findLink(up, down);
            link->setOpposingLink(opposing);
        }
        // create the lanes on each link
        createLanes(file_trf);
        rewind(file_trf);
        // NOTE: create here the signal timings for the nodes to be controlled by the algorithm, if you want
        // create the detectors that exist in the TRAF file
        getDetectors(file_trf);
        // close the stream
        fclose(file_trf);
    }
}
/**
 *  This functions sets whether we can traverse to the other node.  A link is
 *  created if necessary.  Note that calls to this function should be 
 *  symmetric - you should also call other->setLink(this, blah).
 *
 *  @param other        The other node to link to.
 *  @param canTraverse  Can we go from this node to other?
 *
 *  @return             The link from this to other.
 */
ChunkLinkPtr EditorChunkItemLinkable::setLink(EditorChunkItemLinkable *other, bool canTraverse)
{
    if (other == NULL)
        return ChunkLinkPtr();
    
    preloadLinks_[other->guid_] = canTraverse;

    // If there isn't a link, create one:
    bool owns = guid() < other->guid();
    ChunkLinkPtr link = findLink(other);

    if (link == NULL)
    {
        link = createLink();
        if (owns)
        {
			link->startItem(chunkItem());
            link->endItem(other->chunkItem());
        }
        else
        {
            link->startItem(other->chunkItem());
            link->endItem(chunkItem());
        }
        links_.push_back(link);
        other->links_.push_back(link);
        if (owns)
        {
            if (chunkItem()->chunk() != NULL)
				chunkItem()->chunk()->addStaticItem(link);           
        }
        else
        {
            if (other->chunkItem()->chunk() != NULL)
                other->chunkItem()->chunk()->addStaticItem(link);
        }
    }
   
    ChunkLink::Direction dir = link->direction();
    if (canTraverse)
    {
        if (owns)
        {
            link->direction
            (
                (ChunkLink::Direction)(dir | ChunkLink::DIR_START_END)
            );
        }
        else
        {
            link->direction
            (
                (ChunkLink::Direction)(dir | ChunkLink::DIR_END_START)
            );
        }
    }
    else
    {
        if (owns)
        {
            link->direction
            (
                (ChunkLink::Direction)
                (ChunkLink::DIR_BOTH & (dir & ~ChunkLink::DIR_START_END))
            );
        }
        else
        {
            link->direction
            (
                (ChunkLink::Direction)
                (ChunkLink::DIR_BOTH & (dir & ~ChunkLink::DIR_END_START))
            );
        }
    }

    return link;
}