add graph attributes to graphml writer
This commit is contained in:
@@ -18,7 +18,18 @@ public class GraphMLFileWriter {
|
|||||||
|
|
||||||
String filename;
|
String filename;
|
||||||
SimpleWeightedGraph graph;
|
SimpleWeightedGraph graph;
|
||||||
|
GraphWithMapData data;
|
||||||
|
Map<String, Attribute> graphAttributes = new HashMap<>();
|
||||||
|
|
||||||
|
public GraphMLFileWriter(String filename, GraphWithMapData data) {
|
||||||
|
if(!filename.matches(".*\\.graphml")){
|
||||||
|
filename = filename + ".graphml";
|
||||||
|
}
|
||||||
|
this.filename = filename;
|
||||||
|
this.data = data;
|
||||||
|
this.graph = data.getGraph();
|
||||||
|
createGraphAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
public GraphMLFileWriter(String filename, SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph) {
|
public GraphMLFileWriter(String filename, SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph) {
|
||||||
if(!filename.matches(".*\\.graphml")){
|
if(!filename.matches(".*\\.graphml")){
|
||||||
@@ -28,6 +39,23 @@ public class GraphMLFileWriter {
|
|||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createGraphAttributes(){
|
||||||
|
//Sample plate filename
|
||||||
|
graphAttributes.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
|
||||||
|
// Number of wells
|
||||||
|
graphAttributes.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
|
||||||
|
//Well populations
|
||||||
|
Integer[] wellPopulations = data.getWellPopulations();
|
||||||
|
StringBuilder populationsStringBuilder = new StringBuilder();
|
||||||
|
populationsStringBuilder.append(wellPopulations[0].toString());
|
||||||
|
for(int i = 1; i < wellPopulations.length; i++){
|
||||||
|
populationsStringBuilder.append(", ");
|
||||||
|
populationsStringBuilder.append(wellPopulations[i].toString());
|
||||||
|
}
|
||||||
|
String wellPopulationsString = populationsStringBuilder.toString();
|
||||||
|
graphAttributes.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
|
||||||
|
}
|
||||||
|
|
||||||
public void writeGraphToFile() {
|
public void writeGraphToFile() {
|
||||||
try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW);
|
try(BufferedWriter writer = Files.newBufferedWriter(Path.of(filename), StandardOpenOption.CREATE_NEW);
|
||||||
){
|
){
|
||||||
@@ -35,6 +63,8 @@ public class GraphMLFileWriter {
|
|||||||
GraphMLExporter<Vertex, SimpleWeightedGraph<Vertex, DefaultWeightedEdge>> exporter = new GraphMLExporter<>(Vertex::getVertexLabel);
|
GraphMLExporter<Vertex, SimpleWeightedGraph<Vertex, DefaultWeightedEdge>> exporter = new GraphMLExporter<>(Vertex::getVertexLabel);
|
||||||
//set to export weights
|
//set to export weights
|
||||||
exporter.setExportEdgeWeights(true);
|
exporter.setExportEdgeWeights(true);
|
||||||
|
//Set graph attributes
|
||||||
|
exporter.setGraphAttributeProvider( () -> graphAttributes);
|
||||||
//set type, sequence, and occupancy attributes for each vertex
|
//set type, sequence, and occupancy attributes for each vertex
|
||||||
exporter.setVertexAttributeProvider( v -> {
|
exporter.setVertexAttributeProvider( v -> {
|
||||||
Map<String, Attribute> attributes = new HashMap<>();
|
Map<String, Attribute> attributes = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user