Example #1
0
CGraph* CreateRandomGraphWithToyQMRSpecific(int num_nodes, 
    int num_indep_nodes, int max_size_family)
{
    PNL_CHECK_LEFT_BORDER( num_nodes, 10 );
    PNL_CHECK_RANGES( num_indep_nodes, 1, num_nodes-1 );
    PNL_CHECK_RANGES( max_size_family, 2, num_nodes );
    
    int i, j, k;
    
    CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL);
    PNL_CHECK_IF_MEMORY_ALLOCATED( pGraph );
    
    srand((unsigned int)time(NULL));

    pGraph->AddNodes(num_nodes);
    
    int num_parents;
    int ind_parent;
    intVector prev_nodes(0);
    for ( i = num_indep_nodes; i < num_nodes; i++)
    {
        prev_nodes.resize(0);
        for ( j = 0; j < num_indep_nodes; j++) 
            prev_nodes.push_back(j);

        num_parents = rand() % (max_size_family - 1);
        num_parents += 1;
        num_parents = (num_parents > i) ? i : num_parents;
    
        for ( j = 0; j < num_parents; j++)
        {
            ind_parent = rand() % prev_nodes.size();
            pGraph->AddEdge(prev_nodes[ind_parent], i, 1);
            prev_nodes.erase(prev_nodes.begin() + ind_parent);
        }
    }

    return pGraph;
}
Example #2
0
CGraph* CreateRandomAndSpecificForIDNetGraph(int num_nodes,
  int num_indep_nodes, int max_size_family)
{
  PNL_CHECK_LEFT_BORDER(num_nodes, 10);
  PNL_CHECK_RANGES(num_indep_nodes, 1, num_nodes-1);
  PNL_CHECK_RANGES(max_size_family, 2, num_nodes);
  
  int i, j, k;
  
  CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL);
  PNL_CHECK_IF_MEMORY_ALLOCATED(pGraph);
  
  srand((unsigned int)time(NULL));
  
  pGraph->AddNodes(num_nodes);
  
  int num_parents;
  int ind_parent;
  intVector prev_nodes(0);
  for (i = num_indep_nodes; i < num_nodes; i++)
  {
    prev_nodes.resize(0);
    for (j = 0; j < i; j++)
      prev_nodes.push_back(j);
    
    num_parents = rand() % (max_size_family - 1);
    num_parents += 1;
    num_parents = (num_parents > i) ? i : num_parents;
    
    for (j = 0; j < num_parents; j++)
    {
      ind_parent = rand() % prev_nodes.size();
      pGraph->AddEdge(prev_nodes[ind_parent], i, 1);
      prev_nodes.erase(prev_nodes.begin() + ind_parent);
    }
  }
  
  intVector parents(0);
  intVector childs(0);
  for (i = 0; i < num_nodes; i++)
  {
    if (pGraph->GetNumberOfChildren(i) == 0)
    {
      pGraph->GetParents(i, &parents);
      for (j = 0; j < parents.size(); j++)
      {
        pGraph->GetChildren(parents[j], &childs);
        for (k = 0; k < childs.size(); k++)
          if ((childs[k] != i) && 
            (pGraph->GetNumberOfChildren(childs[k]) == 0) &&
            (pGraph->GetNumberOfParents(childs[k]) == 1))
          {
            if (i < childs[k])
            {
              pGraph->RemoveEdge(parents[j], childs[k]);
              pGraph->AddEdge(i, childs[k], 1);
            }
            else
            {
              pGraph->AddEdge(childs[k], i, 1);
            }
          }
      }
    }
  }
  
  return pGraph;
}
Example #3
0
void Caller::create_node_calls(const NodePileup& np) {
    
    int n = _node->sequence().length();
    const string& seq = _node->sequence();
    int cur = 0;
    int cat = call_cat(_node_calls[cur]);
    NodePair prev_nodes(-1, -1);

    // scan contiguous chunks of a node with same call
    // (note: snps will always be 1-base -- never merged)
    for (int next = 1; next <= n; ++next) {
        int next_cat = next == n ? -1 : call_cat(_node_calls[next]);
        if (cat == 2 || cat != next_cat) {
            NodePair new_nodes(-1, -1);
            bool secondary_snp = false;

            // process first genotype if it's not missing
            if (_node_calls[cur].first == '.') {
                // add single node for stretch of reference node
                string new_seq = seq.substr(cur, next - cur);
                new_nodes.first = ++_max_id;
                _call_graph.create_node(new_seq, new_nodes.first);
            } else if (_node_calls[cur].first != '-') {
                // add snp node
                assert(next - cur == 1);
                string new_seq(1, _node_calls[cur].first);
                new_nodes.first = ++_max_id;
                _call_graph.create_node(new_seq, new_nodes.first);
                create_snp_path(new_nodes.first, secondary_snp);
                secondary_snp = true;
            }

            // process second genotype if difference from first
            if (_node_calls[cur].second != _node_calls[cur].first) {
                if (_node_calls[cur].second == '.') {
                    // add single node for stretch of reference node
                    string new_seq = seq.substr(cur, next - cur);
                    new_nodes.second = ++_max_id;
                    _call_graph.create_node(new_seq, new_nodes.second);
                } else if (_node_calls[cur].second != '-') {
                    // add snp node
                    assert(next - cur == 1);
                    string new_seq(1, _node_calls[cur].second);
                    new_nodes.second = ++_max_id;
                    _call_graph.create_node(new_seq, new_nodes.second);
                    create_snp_path(new_nodes.second, secondary_snp);
                }
            }
            
            // update maps if new node abuts end of original node
            // so that edges can be updated later on:
            if (new_nodes.first != -1 || new_nodes.second != -1) {
                if (cur == 0) {
                    _start_node_map[_node->id()] = new_nodes;
                }
                if (next == n) {
                    _end_node_map[_node->id()] = new_nodes;
                }
            }

            // add edges
            if (prev_nodes.first != -1 && new_nodes.first != -1) {
                _call_graph.create_edge(prev_nodes.first, new_nodes.first);
            }
            if (prev_nodes.first != -1 && new_nodes.second != -1) {
                _call_graph.create_edge(prev_nodes.first, new_nodes.second);
            }
            if (prev_nodes.second != -1 && new_nodes.first != -1) {
                _call_graph.create_edge(prev_nodes.second, new_nodes.first);
            }
            if (prev_nodes.second != -1 && new_nodes.second != -1) {
                _call_graph.create_edge(prev_nodes.second, new_nodes.second);
            }

            // shift right
            cur = next;
            cat = next_cat;
            prev_nodes = new_nodes;
        }
    }
}