void ProteinsAnchorsSamplingSpace::show(std::ostream &s) const {
  for (std::map<std::string, IntsList>::const_iterator it = paths_map_.begin();
       it != paths_map_.end(); it++) {
    IntsList inds = it->second;
    s << it->first << " " << inds.size() << std::endl;
    for (unsigned j = 0; j < inds.size(); j++) {
      s << inds[j] << std::endl;
    }
  }
}
IntsList
  DensitySegmentationByCommunities::calculate_communities(int num_clusters) {
  //calculate the connected components
  std::vector<int> component(num_vertices(g_));
  int num = boost::connected_components(g_, &component[0]);
  //get the largest connected components
  compatibility::map<int,int> max_comp_list;
  for(int i=0;i<num;i++){
    max_comp_list[i]=0;}
  for(int i=0;i<num;i++){
    max_comp_list[component[i]]+=1;}
  int max_comp=0;
  for(int i=0;i<num;i++){
    if (max_comp_list[i]>max_comp_list[max_comp]){max_comp=i;}
  }
  //remove all nodes not path of the first component
  Ints not_first_comp_indexes;
  for(int i=0;i<(int)component.size();i++) {
    if (component[i] != max_comp) not_first_comp_indexes.push_back(i);
  }
  IMP_LOG(VERBOSE,"removing vertices, starting with "
          <<boost::num_vertices(g_)<<std::endl);
  boost::graph_traits<DensityGraph>::vertex_iterator vi, vi_end, next;
  boost::tie(vi, vi_end) = boost::vertices(g_);
  std::pair<boost::graph_traits<DensityGraph>::out_edge_iterator,
            boost::graph_traits<DensityGraph>::out_edge_iterator> ei;
  int rank0_nodes=0;
  int index=0;
  for(;vi!=vi_end;vi++) {
    if (not_first_comp_indexes[index] != (int)*vi) continue;
    ++index;
    ++rank0_nodes;
    for(ei=boost::out_edges(*vi,g_);
        ei.first!=ei.second;ei.first++) {
      boost::remove_edge(ei.first,g_);
    }
  }
  IMP_LOG(VERBOSE,"rank0 nodes:"<<rank0_nodes
          <<" not in first cc:"<<not_first_comp_indexes.size()<<std::endl);
  boost::property_map<DensityGraph, boost::edge_centrality_t>::type m
    = boost::get(boost::edge_centrality, g_);
  unsigned int n=boost::num_vertices(g_);
  boost::betweenness_centrality_clustering(
                 g_, Done(num_clusters+rank0_nodes, n),
                 m);//we add all the new rank0 nodes
  IMP_LOG(TERSE,"preparing output"<<std::endl);
  std::vector<int> rank(n), parent(n);
  DS ds(&rank[0], &parent[0]);
  boost::initialize_incremental_components(g_, ds);
  boost::incremental_components(g_, ds);
  compatibility::map<int, Ints> sets;
  //voxel indexes correspoding to node indexes for each cluster
  for (unsigned int i=0; i< boost::num_vertices(g_); ++i) {
    int s= ds.find_set(i);
    sets[s].push_back(node2voxel_ind_[node_index_[i]]);
  }
  IntsList clusters;
  for (compatibility::map<int, Ints>::const_iterator it
         = sets.begin(); it != sets.end(); ++it) {
    clusters.push_back(it->second);
  }
  return clusters;
}
Beispiel #3
0
IntsList _pass_ints_list(const IntsList &in) {
  std::cout << "IntsList of length " << in.size();
  return in;
}