Add read counts for individual wells to graphml output
This commit is contained in:
@@ -5,7 +5,6 @@ import org.jgrapht.nio.AttributeType;
|
|||||||
import org.jgrapht.nio.DefaultAttribute;
|
import org.jgrapht.nio.DefaultAttribute;
|
||||||
import org.jgrapht.nio.graphml.GraphMLExporter;
|
import org.jgrapht.nio.graphml.GraphMLExporter;
|
||||||
import org.jgrapht.nio.graphml.GraphMLExporter.AttributeCategory;
|
import org.jgrapht.nio.graphml.GraphMLExporter.AttributeCategory;
|
||||||
import org.w3c.dom.Attr;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,6 +12,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GraphMLFileWriter {
|
public class GraphMLFileWriter {
|
||||||
@@ -41,11 +41,11 @@ public class GraphMLFileWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Attribute> createGraphAttributes(){
|
private Map<String, Attribute> createGraphAttributes(){
|
||||||
Map<String, Attribute> ga = new HashMap<>();
|
Map<String, Attribute> attributes = new HashMap<>();
|
||||||
//Sample plate filename
|
//Sample plate filename
|
||||||
ga.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
|
attributes.put("sample plate filename", DefaultAttribute.createAttribute(data.getSourceFilename()));
|
||||||
// Number of wells
|
// Number of wells
|
||||||
ga.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
|
attributes.put("well count", DefaultAttribute.createAttribute(data.getNumWells().toString()));
|
||||||
//Well populations
|
//Well populations
|
||||||
Integer[] wellPopulations = data.getWellPopulations();
|
Integer[] wellPopulations = data.getWellPopulations();
|
||||||
StringBuilder populationsStringBuilder = new StringBuilder();
|
StringBuilder populationsStringBuilder = new StringBuilder();
|
||||||
@@ -55,11 +55,36 @@ public class GraphMLFileWriter {
|
|||||||
populationsStringBuilder.append(wellPopulations[i].toString());
|
populationsStringBuilder.append(wellPopulations[i].toString());
|
||||||
}
|
}
|
||||||
String wellPopulationsString = populationsStringBuilder.toString();
|
String wellPopulationsString = populationsStringBuilder.toString();
|
||||||
ga.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
|
attributes.put("well populations", DefaultAttribute.createAttribute(wellPopulationsString));
|
||||||
ga.put("read depth", DefaultAttribute.createAttribute(data.getReadDepth().toString()));
|
attributes.put("read depth", DefaultAttribute.createAttribute(data.getReadDepth().toString()));
|
||||||
ga.put("read error rate", DefaultAttribute.createAttribute(data.getReadErrorRate().toString()));
|
attributes.put("read error rate", DefaultAttribute.createAttribute(data.getReadErrorRate().toString()));
|
||||||
ga.put("error collision rate", DefaultAttribute.createAttribute(data.getErrorCollisionRate().toString()));
|
attributes.put("error collision rate", DefaultAttribute.createAttribute(data.getErrorCollisionRate().toString()));
|
||||||
return ga;
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Attribute> createVertexAttributes(Vertex v){
|
||||||
|
Map<String, Attribute> attributes = new HashMap<>();
|
||||||
|
//sequence type
|
||||||
|
attributes.put("type", DefaultAttribute.createAttribute(v.getType().name()));
|
||||||
|
//sequence
|
||||||
|
attributes.put("sequence", DefaultAttribute.createAttribute(v.getSequence()));
|
||||||
|
//number of wells the sequence appears in
|
||||||
|
attributes.put("occupancy", DefaultAttribute.createAttribute(v.getOccupancy()));
|
||||||
|
//total number of times the sequence was read
|
||||||
|
attributes.put("total read count", DefaultAttribute.createAttribute(v.getReadCount()));
|
||||||
|
StringBuilder wellsAndReadCountsBuilder = new StringBuilder();
|
||||||
|
Iterator<Map.Entry<Integer, Integer>> wellOccupancies = v.getWellOccupancies().entrySet().iterator();
|
||||||
|
while (wellOccupancies.hasNext()) {
|
||||||
|
Map.Entry<Integer, Integer> entry = wellOccupancies.next();
|
||||||
|
wellsAndReadCountsBuilder.append(entry.getKey() + ":" + entry.getValue());
|
||||||
|
if (wellOccupancies.hasNext()) {
|
||||||
|
wellsAndReadCountsBuilder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String wellsAndReadCounts = wellsAndReadCountsBuilder.toString();
|
||||||
|
//the wells the sequence appears in and the read counts in those wells
|
||||||
|
attributes.put("wells:read counts", DefaultAttribute.createAttribute(wellsAndReadCounts));
|
||||||
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeGraphToFile() {
|
public void writeGraphToFile() {
|
||||||
@@ -72,15 +97,7 @@ public class GraphMLFileWriter {
|
|||||||
//Set graph attributes
|
//Set graph attributes
|
||||||
exporter.setGraphAttributeProvider( () -> graphAttributes);
|
exporter.setGraphAttributeProvider( () -> graphAttributes);
|
||||||
//set type, sequence, and occupancy attributes for each vertex
|
//set type, sequence, and occupancy attributes for each vertex
|
||||||
//NEED TO ADD NEW FIELD FOR READ COUNT
|
exporter.setVertexAttributeProvider(this::createVertexAttributes);
|
||||||
exporter.setVertexAttributeProvider( v -> {
|
|
||||||
Map<String, Attribute> attributes = new HashMap<>();
|
|
||||||
attributes.put("type", DefaultAttribute.createAttribute(v.getType().name()));
|
|
||||||
attributes.put("sequence", DefaultAttribute.createAttribute(v.getSequence()));
|
|
||||||
attributes.put("occupancy", DefaultAttribute.createAttribute(v.getOccupancy()));
|
|
||||||
attributes.put("read count", DefaultAttribute.createAttribute(v.getReadCount()));
|
|
||||||
return attributes;
|
|
||||||
});
|
|
||||||
//register the attributes
|
//register the attributes
|
||||||
for(String s : graphAttributes.keySet()) {
|
for(String s : graphAttributes.keySet()) {
|
||||||
exporter.registerAttribute(s, AttributeCategory.GRAPH, AttributeType.STRING);
|
exporter.registerAttribute(s, AttributeCategory.GRAPH, AttributeType.STRING);
|
||||||
@@ -88,7 +105,8 @@ public class GraphMLFileWriter {
|
|||||||
exporter.registerAttribute("type", AttributeCategory.NODE, AttributeType.STRING);
|
exporter.registerAttribute("type", AttributeCategory.NODE, AttributeType.STRING);
|
||||||
exporter.registerAttribute("sequence", AttributeCategory.NODE, AttributeType.STRING);
|
exporter.registerAttribute("sequence", AttributeCategory.NODE, AttributeType.STRING);
|
||||||
exporter.registerAttribute("occupancy", AttributeCategory.NODE, AttributeType.STRING);
|
exporter.registerAttribute("occupancy", AttributeCategory.NODE, AttributeType.STRING);
|
||||||
exporter.registerAttribute("read count", AttributeCategory.NODE, AttributeType.STRING);
|
exporter.registerAttribute("total read count", AttributeCategory.NODE, AttributeType.STRING);
|
||||||
|
exporter.registerAttribute("wells:read counts", AttributeCategory.NODE, AttributeType.STRING);
|
||||||
//export the graph
|
//export the graph
|
||||||
exporter.exportGraph(graph, writer);
|
exporter.exportGraph(graph, writer);
|
||||||
} catch(IOException ex){
|
} catch(IOException ex){
|
||||||
|
|||||||
Reference in New Issue
Block a user