我想使用 BGL 布局 RNA 折叠图,它具有保证的平面结构,并且所有边都应该具有相同的长度(有两种边:正常序列和红色键),如下所示:
rna 二级结构 http://www.ncrna.org/frnadb/sec_structure/png/FR096703.png
namespace boost {
enum vertex_position_t { vertex_position };
BOOST_INSTALL_PROPERTY(vertex, position);
};
template<class PairIterator>
void layout(std::string seq, PairIterator begin, PairIterator end) {
using namespace boost; using namespace std;
// backbone edges + bonding edges
vector<pair<size_t,size_t>> edge_list(begin, end);
for(size_t i = 0 ; i < seq.size() - 1 ; i++)
edge_list.push_back(make_pair(i, i + 1));
typedef rectangle_topology<> topology;
typedef topology::point_type point;
boost::minstd_rand random;
topology space(random, -1000, -1000, 2000, 2000);
adjacency_list<vecS, vecS, undirectedS,
property<vertex_position_t, point>
> g(edge_list.begin(), edge_list.end(), seq.size());
random_graph_layout(g, get(vertex_position, g), space);
fruchterman_reingold_force_directed_layout(g, get(vertex_position, g), space,
cooling(linear_cooling<double>(100)));
// draw
}
但是,这给了我一个非常随机的布局(冷却时间为 100、200、400)。更长的冷却时间只需将顶点压入角落(图像显示完整的布局)。边缘似乎一直太长......
我想为边缘指定一个目标长度,并且在达到一定余量之前不要停止模拟。
我的代码是从 boost 示例中拼凑而成的,但我不需要坚持属性映射等,我只想要一个布局而不必求助于 GraphViz。