testing graph attributes

This commit is contained in:
2022-02-26 08:58:52 -06:00
parent b3dc10f287
commit 75b2aa9553
4 changed files with 27 additions and 11 deletions

View File

@@ -14,8 +14,8 @@ public class BiGpairSEQ {
private static boolean cachePlate = false;
private static boolean cacheGraph = false;
private static HeapType priorityQueueHeapType = HeapType.FIBONACCI;
private static boolean outputBinary = false;
private static boolean outputGraphML = true;
private static boolean outputBinary = true;
private static boolean outputGraphML = false;
public static void main(String[] args) {
if (args.length == 0) {

View File

@@ -6,11 +6,14 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
public class GraphMLFileReader {
private String filename;
private SimpleWeightedGraph graph;
private final String filename;
private final SimpleWeightedGraph graph;
private final Map<String, String> graphAttributes = new HashMap<>();
public GraphMLFileReader(String filename, SimpleWeightedGraph graph) {
if(!filename.matches(".*\\.graphml")){
@@ -23,6 +26,9 @@ public class GraphMLFileReader {
BufferedReader reader = Files.newBufferedReader(Path.of(filename));
){
GraphMLImporter<Vertex, DefaultWeightedEdge> importer = new GraphMLImporter<>();
importer.addGraphAttributeConsumer((str, attribute) -> {
graphAttributes.put(str, attribute.getValue());
});
importer.addVertexWithAttributesConsumer((vertex, attributes) -> {
vertex.setType(attributes.get("type").getValue());
vertex.setSequence(attributes.get("sequence").getValue());
@@ -38,4 +44,8 @@ public class GraphMLFileReader {
public SimpleWeightedGraph getGraph() { return graph; }
public Map<String, String> getGraphAttributes() { return graphAttributes; }
public String getFilename() {return filename;}
}

View File

@@ -5,6 +5,7 @@ import org.jgrapht.nio.AttributeType;
import org.jgrapht.nio.DefaultAttribute;
import org.jgrapht.nio.graphml.GraphMLExporter;
import org.jgrapht.nio.graphml.GraphMLExporter.AttributeCategory;
import org.w3c.dom.Attr;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -19,7 +20,7 @@ public class GraphMLFileWriter {
String filename;
SimpleWeightedGraph graph;
GraphWithMapData data;
Map<String, Attribute> graphAttributes = new HashMap<>();
Map<String, Attribute> graphAttributes;
public GraphMLFileWriter(String filename, GraphWithMapData data) {
if(!filename.matches(".*\\.graphml")){
@@ -28,7 +29,7 @@ public class GraphMLFileWriter {
this.filename = filename;
this.data = data;
this.graph = data.getGraph();
createGraphAttributes();
graphAttributes = createGraphAttributes();
}
public GraphMLFileWriter(String filename, SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph) {
@@ -39,11 +40,12 @@ public class GraphMLFileWriter {
this.graph = graph;
}
private void createGraphAttributes(){
private Map<String, Attribute> createGraphAttributes(){
Map<String, Attribute> ga = new HashMap<>();
//Sample plate filename
graphAttributes.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
ga.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
// Number of wells
graphAttributes.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
ga.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
//Well populations
Integer[] wellPopulations = data.getWellPopulations();
StringBuilder populationsStringBuilder = new StringBuilder();
@@ -53,7 +55,8 @@ public class GraphMLFileWriter {
populationsStringBuilder.append(wellPopulations[i].toString());
}
String wellPopulationsString = populationsStringBuilder.toString();
graphAttributes.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
ga.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
return ga;
}
public void writeGraphToFile() {
@@ -74,6 +77,9 @@ public class GraphMLFileWriter {
return attributes;
});
//register the attributes
for(String s : graphAttributes.keySet()) {
exporter.registerAttribute(s, AttributeCategory.GRAPH, AttributeType.STRING);
}
exporter.registerAttribute("type", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("sequence", AttributeCategory.NODE, AttributeType.STRING);
exporter.registerAttribute("occupancy", AttributeCategory.NODE, AttributeType.STRING);

View File

@@ -315,7 +315,7 @@ public class InteractiveInterface {
System.out.println("Serialized binary graph/data file written to: " + filename);
}
if(BiGpairSEQ.outputGraphML()) {
GraphMLFileWriter graphMLWriter = new GraphMLFileWriter(filename, data.getGraph());
GraphMLFileWriter graphMLWriter = new GraphMLFileWriter(filename, data);
graphMLWriter.writeGraphToFile();
System.out.println("GraphML file written to: " + filename);
}