30namespace AnnotationGraphs
67 std::map< uint64_t, const AnnotationData::Dumper* > m_dumpFunctions;
76 std::map<StringsPoolIndex, std::multimap<AnnotationGraphVertex, AnnotationGraphVertex> > m_matchings;
93AnnotationDataPrivate::AnnotationDataPrivate() :
100 m_mapVertexAGIannotPropertyMap( get(
vertex_iannot, m_graph) ),
101 m_mapVertexAGSannotPropertyMap( get(
vertex_sannot, m_graph) ),
102 m_mapEdgeAGIannotPropertyMap( get(
edge_iannot, m_graph) ),
104 m_mapVertexAGGannotPropertyMap( get(
vertex_gannot, m_graph) ),
105 m_mapEdgeAGSannotPropertyMap( get(
edge_sannot, m_graph) ),
107 m_mapEdgeAGGannotPropertyMap( get(
edge_gannot, m_graph) ),
113AnnotationDataPrivate::~AnnotationDataPrivate()
115 for (std::map< uint64_t, const AnnotationData::Dumper* >::const_iterator it=m_dumpFunctions.begin();
116 it!=m_dumpFunctions.end();
142 return m_d->m_pool[
static_cast<StringsPoolIndex
>(
annotationId)];
148 return m_d->m_pool[s];
154 return add_vertex(m_d->m_graph);
161 LDEBUG <<
"Creating annotation edge " << s <<
" -> " << t;
163 return add_edge(s, t, m_d->m_graph).first;
172 annotate(v, m_d->m_pool[annot], value);
180 annotate(v, m_d->m_pool[annot], value);
188 annotate(v, m_d->m_pool[annot], value);
195 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
197 annotate(e, m_d->m_pool[annot], value);
203 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
205 annotate(e, m_d->m_pool[annot], value);
211 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
213 annotate(e, m_d->m_pool[annot], value);
224 annotate(e, m_d->m_pool[annot], value);
234 annotate(e, m_d->m_pool[annot], value);
244 annotate(e, m_d->m_pool[annot], value);
250 const uint64_t idx =
const_cast<AnnotationData*
>(
this)->m_d->m_pool[annot];
271 const uint64_t idx =
const_cast<AnnotationData*
>(
this)->m_d->m_pool[annot];
315 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
319 m_d->m_mapVertexAGIannotPropertyMap[v][annot] = value;
322 LDEBUG <<
"Annotating " << v <<
" ("<<m_d->m_pool[StringsPoolIndex(annot)]<<
") : " << value;
328 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
332 m_d->m_mapVertexAGSannotPropertyMap[v][annot] = value;
335 LDEBUG <<
"Annotating " << v <<
" ("<<m_d->m_pool[StringsPoolIndex(annot)]<<
") : " << value;
341 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
345 if (num_vertices(m_d->m_graph) <= v)
347 std::ostringstream oss;
348 oss <<
"Trying to annotate an inexisting vertex: " << v
349 <<
". Graph size in vertices is: " << num_vertices(m_d->m_graph) << std::endl;
350 throw std::range_error(oss.str());
352 std::map< uint64_t, GenericAnnotation > m = m_d->m_mapVertexAGGannotPropertyMap[v];
353 m_d->m_mapVertexAGGannotPropertyMap[v][annot] = value;
356 LDEBUG <<
"Annotating " << v <<
" ("<< m_d->m_pool[StringsPoolIndex(annot)] <<
") : GA";
364 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
369 LDEBUG <<
"Annotating " << vs <<
" -> " << vt <<
" ("<<m_d->m_pool[StringsPoolIndex(annot)]<<
") : " << value;
376 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
384 boost::tie(e, ok) = edge(vs,vt,m_d->m_graph);
392 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
396 m_d->m_mapEdgeAGIannotPropertyMap[e][annot] = value;
401 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
405 m_d->m_mapEdgeAGSannotPropertyMap[e][annot] = value;
410 if (m_d->m_dumpFunctions.find(annot) == m_d->m_dumpFunctions.end())
414 m_d->m_mapEdgeAGGannotPropertyMap[e][annot] = value;
420 return m_d->m_mapVertexAGIannotPropertyMap[v][annot];
425 return m_d->m_mapVertexAGSannotPropertyMap[v][annot];
430 return m_d->m_mapVertexAGGannotPropertyMap[v][annot];
435 return m_d->m_mapVertexAGGannotPropertyMap[v][annot];
441 return m_d->m_mapEdgeAGIannotPropertyMap[e][annot];
446 return m_d->m_mapEdgeAGSannotPropertyMap[e][annot];
451 return (*(m_d->m_mapCEdgeAGGannotPropertyMap[e].find(annot))).second;
456 return m_d->m_mapEdgeAGGannotPropertyMap[e][annot];
464 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
467 std::ostringstream oss;
468 oss <<
"Error trying to access to inexistant edge " << v1 <<
" -> " << v2;
469 throw std::runtime_error(oss.str().c_str());
471 return (*(m_d->m_mapCEdgeAGIannotPropertyMap[e].find(annot))).second;
477 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
480 std::ostringstream oss;
481 oss <<
"Error trying to access to inexistant edge " << v1 <<
" -> " << v2;
482 throw std::runtime_error(oss.str().c_str());
484 return (*(m_d->m_mapCEdgeAGSannotPropertyMap[e].find(annot))).second;
490 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
493 std::ostringstream oss;
494 oss <<
"Error trying to access to inexistant edge " << v1 <<
" -> " << v2;
495 throw std::runtime_error(oss.str().c_str());
497 if (m_d->m_mapCEdgeAGGannotPropertyMap[e].find(annot) == m_d->m_mapCEdgeAGGannotPropertyMap[e].end())
499 std::ostringstream oss;
500 oss <<
"Error trying to access to inexistant edge annotation" << v1 <<
" -> " << v2 <<
", " << annot;
501 throw std::runtime_error(oss.str().c_str());
503 return (*(m_d->m_mapCEdgeAGGannotPropertyMap[e].find(annot))).second;
509 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
512 std::ostringstream oss;
513 oss <<
"Error trying to access to inexistant edge " << v1 <<
" -> " << v2;
514 throw std::runtime_error(oss.str().c_str());
516 if (m_d->m_mapEdgeAGGannotPropertyMap[e].find(annot) == m_d->m_mapEdgeAGGannotPropertyMap[e].end())
518 std::ostringstream oss;
519 oss <<
"Error trying to access to inexistant edge annotation" << v1 <<
" -> " << v2 <<
", " << annot;
520 throw std::runtime_error(oss.str().c_str());
522 return (*(m_d->m_mapEdgeAGGannotPropertyMap[e].find(annot))).second;
575 return (m_d->m_mapCVertexAGIannotPropertyMap[v].find(annot) != m_d->m_mapCVertexAGIannotPropertyMap[v].end());
580 return (m_d->m_mapCVertexAGSannotPropertyMap[v].find(annot) != m_d->m_mapCVertexAGSannotPropertyMap[v].end());
585 return (m_d->m_mapCVertexAGGannotPropertyMap[v].find(annot) != m_d->m_mapCVertexAGGannotPropertyMap[v].end());
591 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
592 if (!ok)
return false;
599 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
600 if (!ok)
return false;
607 boost::tie(e, ok) = edge(v1,v2,m_d->m_graph);
608 if (!ok)
return false;
614 return (m_d->m_mapCEdgeAGIannotPropertyMap[e].find(annot) != m_d->m_mapCEdgeAGIannotPropertyMap[e].end());
619 return (m_d->m_mapCEdgeAGSannotPropertyMap[e].find(annot) != m_d->m_mapCEdgeAGSannotPropertyMap[e].end());
624 return (m_d->m_mapCEdgeAGGannotPropertyMap[e].find(annot) != m_d->m_mapCEdgeAGGannotPropertyMap[e].end());
634 LimaString wannot = QString::fromStdString(annot);
636 if (m_d->m_dumpFunctions.find(annotId) != m_d->m_dumpFunctions.end())
639 LWARN <<
"Replacing dump function for " << annot <<
" annotation. Deleting old one";
640 delete m_d->m_dumpFunctions[annotId];
642 m_d->m_dumpFunctions[annotId] = f;
647 LimaString wannot = QString::fromStdString(annot);
649 if (m_d->m_dumpFunctions.find(annotId) == m_d->m_dumpFunctions.end())
655 return m_d->m_dumpFunctions[annotId];
661 return m_d->m_dumpFunctions[annot];
673 os <<
"no_dump_function_defined";
680 m_d->m_matchings[direction].insert(std::make_pair(firstVx,secondVx));
684const std::map<StringsPoolIndex, std::multimap<AnnotationGraphVertex, AnnotationGraphVertex> >&
AnnotationData::matchings()
const {
return m_d->m_matchings;}
689 const std::string& second,
694 LDEBUG <<
"AnnotationData::addMatching " << first << firstVx
695 << second << secondVx;
698 addMatching( m_d->m_pool[ QString::fromStdString(first + second) ],
700 addMatching( m_d->m_pool[ QString::fromStdString(second + first) ],
709 const std::string& second)
const
711 return matches( m_d->m_pool[ QString::fromStdString(first + second) ], firstVx);
719 return isMatching( m_d->m_pool[ QString::fromStdString(first + second) ], firstVx, secondVx);
725 addMatching( m_d->m_pool[ m_d->m_pool[first] + m_d->m_pool[second] ], firstVx, secondVx);
726 addMatching( m_d->m_pool[ m_d->m_pool[second] + m_d->m_pool[first] ], secondVx, firstVx);
731 const StringsPoolIndex& second)
const
733 return matches( m_d->m_pool[ m_d->m_pool[first] + m_d->m_pool[second] ], firstVx);
739 return isMatching( m_d->m_pool[ m_d->m_pool[first] + m_d->m_pool[second] ], firstVx, secondVx);
745 if (m_d->m_matchings.find(direction) == m_d->m_matchings.end())
747 return std::set< AnnotationGraphVertex >();
751 std::set< AnnotationGraphVertex > result;
752 auto range = m_d->m_matchings[direction].equal_range(firstVx);
753 for (; range.first != range.second; range.first++)
755 result.insert( (*(range.first)).second);
765 if (m_d->m_matchings.find(direction) == m_d->m_matchings.end())
771 std::pair< std::multimap<AnnotationGraphVertex, AnnotationGraphVertex>::iterator, std::multimap<AnnotationGraphVertex, AnnotationGraphVertex>::iterator > range;
772 range =
const_cast< std::map< StringsPoolIndex, std::multimap<AnnotationGraphVertex, AnnotationGraphVertex>
>& >(m_d->m_matchings)[direction].equal_range(firstVx);
773 for (; range.first != range.second; range.first++)
775 if ( (*(range.first)).second == secondVx )
787 std::set< std::string >& excepted)
789 std::set< uint64_t > iexcepted;
790 std::set< std::string >::const_iterator eit, eit_end;
791 eit=excepted.begin(); eit_end = excepted.end();
792 for (; eit!=eit_end; eit++)
794 iexcepted.insert(m_d->m_pool[QString::fromStdString(*eit)]);
797 AGIannotProp& srcimap = m_d->m_mapVertexAGIannotPropertyMap[src];
798 AGIannotProp& tgtimap = m_d->m_mapVertexAGIannotPropertyMap[tgt];
799 for (AGIannotProp::const_iterator iamit=srcimap.begin();
800 iamit != srcimap.end(); iamit++)
802 if (iexcepted.find((*iamit).first) == iexcepted.end())
804 tgtimap.insert(*iamit);
808 std::map< uint64_t, LimaString >& srcsmap = m_d->m_mapVertexAGSannotPropertyMap[src];
809 std::map< uint64_t, LimaString >& tgtsmap = m_d->m_mapVertexAGSannotPropertyMap[tgt];
810 for (std::map< uint64_t, LimaString >::const_iterator samit=srcsmap.begin();
811 samit != srcsmap.end(); samit++)
813 if (iexcepted.find((*samit).first) == iexcepted.end())
815 tgtsmap.insert(*samit);
819 std::map< uint64_t, GenericAnnotation >& srcmap = m_d->m_mapVertexAGGannotPropertyMap[src];
820 std::map< uint64_t, GenericAnnotation >& tgtmap = m_d->m_mapVertexAGGannotPropertyMap[tgt];
821 for (std::map< uint64_t, GenericAnnotation >::const_iterator amit=srcmap.begin();
822 amit != srcmap.end(); amit++)
824 if (iexcepted.find((*amit).first) == iexcepted.end())
826 tgtmap.insert(*amit);
This file is the main header file for the data related to annotation graphs.
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AGVertexProperties, AGEdgeProperties > AnnotationGraph
The graph class.
std::map< uint64_t, uint64_t > AGIannotProp
Property to annotate vertices with integer values.
#define LIMA_ANNOTATIONGRAPH_EXPORT
Holds an annotation graph and gives an API to manipulate it.
AnnotationData()
Default constructor.
void addMatching(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second, AnnotationGraphVertex secondVx)
Adds a symetric matching between two vertices of two graphs identified by the two string parameters.
uint64_t intAnnotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
std::set< AnnotationGraphVertex > matches(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second) const
Gets the set of vertices matched in the second graph by the given vertex of the first graph.
virtual ~AnnotationData()
Default destructor.
const std::map< StringsPoolIndex, std::multimap< AnnotationGraphVertex, AnnotationGraphVertex > > & matchings() const
Access to the underlying raw matching structure.
const GenericAnnotation & annotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
const LimaString & stringAnnotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
AnnotationGraphVertex createAnnotationVertex()
Creates a new annotation vertex in the graph.
void cloneAnnotations(AnnotationGraphVertex src, AnnotationGraphVertex tgt, std::set< std::string > &excepted)
@briefs copies all the annotations of the source annotation vertex onto the target annotation vertex,...
uint64_t annotationId(const LimaString &s)
Gives the id of an annotation name.
bool isMatching(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second, AnnotationGraphVertex secondVx) const
Tests if the two given vertices are matching in the two given graphs.
AnnotationGraphEdge createAnnotationEdge(AnnotationGraphVertex s, AnnotationGraphVertex t)
Creates a new annotation edge in the graph.
const LimaString & annotationName(uint64_t annotationId) const
Gives the name of an annotation id.
Definition of a dummy function suitable to be used as a dumper for the annotations of an annotation g...
virtual int dump(std::ostream &, GenericAnnotation &) const override
Definition of a dummy function suitable to be used as a dumper for the annotations of an annotation g...
This class allows to convert any object into an annotation by inheritance.
AnnotationGraph & getGraph()
void dumpFunction(const std::string &annot, const Dumper *f)
boost::property_map< AnnotationGraph, edge_gannot_t >::type EdgeAGGannotPropertyMap
boost::property_map< AnnotationGraph, edge_iannot_t >::type EdgeAGIannotPropertyMap
boost::property_map< AnnotationGraph, vertex_iannot_t >::const_type CVertexAGIannotPropertyMap
boost::property_map< AnnotationGraph, edge_iannot_t >::const_type CEdgeAGIannotPropertyMap
boost::property_map< AnnotationGraph, edge_sannot_t >::type EdgeAGSannotPropertyMap
boost::property_map< AnnotationGraph, vertex_iannot_t >::type VertexAGIannotPropertyMap
AnnotationGraph::edge_descriptor AnnotationGraphEdge
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
boost::property_map< AnnotationGraph, edge_gannot_t >::const_type CEdgeAGGannotPropertyMap
boost::property_map< AnnotationGraph, edge_sannot_t >::const_type CEdgeAGSannotPropertyMap
boost::property_map< AnnotationGraph, vertex_sannot_t >::const_type CVertexAGSannotPropertyMap
boost::property_map< AnnotationGraph, vertex_gannot_t >::const_type CVertexAGGannotPropertyMap
boost::property_map< AnnotationGraph, vertex_sannot_t >::type VertexAGSannotPropertyMap
boost::property_map< AnnotationGraph, vertex_gannot_t >::type VertexAGGannotPropertyMap
bool hasStringAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
bool hasIntAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
void annotate(AnnotationGraphVertex v, const LimaString &annot, uint64_t value)