<commit_before>package graph;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import ontology.GeneOntology;
import statistics.TestResult;
import main.GOEnrichment;

public class Graph
{
	private GeneOntology go;
	private TestResult t;
	private HashSet<Integer> nodeIds;
	private Vector<Node> nodes;
	private Vector<Edge> edges;
	private double cutOff;
	
	private final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
								  "<!-- This file was written by GOEnrichment.-->\n" +
								  "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " +
								  	 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
								  	 "xmlns:y=\"http://www.yworks.com/xml/graphml\" " +
								  	 "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " +
								  	 "http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd\">";
	private final String KEY = "\t<key id=\"d0\" for=\"node\" yfiles.type=\"nodegraphics\"/>\n" +
							   "\t<key id=\"d1\" for=\"edge\" yfiles.type=\"edgegraphics\"/>";
	private final String START = "\t<graph edgedefault=\"directed\" id=\"G\">";
	private final String END = "\t</graph>\n</graphml>";

	public Graph(int type)
	{
		//Start with the nodes
		nodes = new Vector<Node>();
		nodeIds = new HashSet<Integer>();
		//Create and add the root node
		go = GOEnrichment.getInstance().getOntology();
		cutOff = GOEnrichment.getInstance().getCuttoff();
		int root = go.getRoot(type);
		nodes.add(new Node(root,1.0,"#FFFFFF"));
		nodeIds.add(root);
		//Create and add each test result node below the cut-off
		t = GOEnrichment.getInstance().getResults()[type];
		for(int term : t.getTerms())
		{
			double pValue = t.getCorrectedPValue(term);
			if(pValue <= cutOff)
			{
				nodes.add(new Node(term,t.getStudyCount(term)*1.0/t.getStudyTotal(),getColor(pValue)));
				nodeIds.add(term);
			}
		}
		//Create and add each test result node that is an ancestor of a 
		//node below the cut-off
		t = GOEnrichment.getInstance().getResults()[type];
		for(int term : t.getTerms())
		{
			if(nodeIds.contains(term))
				continue;
			Set<Integer> descendants = go.getDescendants(term);
			for(int d : descendants)
			{
				if(nodeIds.contains(d))
				{
					nodes.add(new Node(term,t.getStudyCount(term)*1.0/t.getStudyTotal(),"#FFFFFF"));
					nodeIds.add(term);
					break;
				}
			}
		}
		//Proceed with the edges
		edges = new Vector<Edge>();
		for(int term : nodeIds)
		{
			//We create an edge between each term and each of its ancestors that...
			Set<Integer> ancestors = go.getAncestors(term);
			for(int ancestor : ancestors)
			{
				//...is present as a node in the graph and...
				boolean toAdd = nodeIds.contains(ancestor);<commit_msg>Updated graph to use filtered results<commit_after>package graph;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import ontology.GeneOntology;
import statistics.TestResult;
import main.GOEnrichment;

public class Graph
{
	private GeneOntology go;
	private TestResult t;
	private HashSet<Integer> nodeIds;
	private Vector<Node> nodes;
	private Vector<Edge> edges;
	private double cutOff;
	
	private final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
								  "<!-- This file was written by GOEnrichment.-->\n" +
								  "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " +
								  	 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
								  	 "xmlns:y=\"http://www.yworks.com/xml/graphml\" " +
								  	 "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " +
								  	 "http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd\">";
	private final String KEY = "\t<key id=\"d0\" for=\"node\" yfiles.type=\"nodegraphics\"/>\n" +
							   "\t<key id=\"d1\" for=\"edge\" yfiles.type=\"edgegraphics\"/>";
	private final String START = "\t<graph edgedefault=\"directed\" id=\"G\">";
	private final String END = "\t</graph>\n</graphml>";

	public Graph(int type)
	{
		//Start with the nodes
		nodes = new Vector<Node>();
		nodeIds = new HashSet<Integer>();
		//Create and add the root node
		go = GOEnrichment.getInstance().getOntology();
		cutOff = GOEnrichment.getInstance().getCuttoff();
		int root = go.getRoot(type);
		nodes.add(new Node(root,1.0,"#FFFFFF"));
		nodeIds.add(root);
		//Create and add each test result node below the cut-off
		t = GOEnrichment.getInstance().getFilteredResults()[type];
		for(int term : t.getTerms())
		{
			double pValue = t.getCorrectedPValue(term);
			if(pValue <= cutOff)
			{
				nodes.add(new Node(term,t.getStudyCount(term)*1.0/t.getStudyTotal(),getColor(pValue)));
				nodeIds.add(term);
			}
		}
		//Create and add each test result node that is an ancestor of a 
		//node below the cut-off
		t = GOEnrichment.getInstance().getFilteredResults()[type];
		for(int term : t.getTerms())
		{
			if(nodeIds.contains(term))
				continue;
			Set<Integer> descendants = go.getDescendants(term);
			for(int d : descendants)
			{
				if(nodeIds.contains(d))
				{
					nodes.add(new Node(term,t.getStudyCount(term)*1.0/t.getStudyTotal(),"#FFFFFF"));
					nodeIds.add(term);
					break;
				}
			}
		}
		//Proceed with the edges
		edges = new Vector<Edge>();
		for(int term : nodeIds)
		{
			//We create an edge between each term and each of its ancestors that...
			Set<Integer> ancestors = go.getAncestors(term);
			for(int ancestor : ancestors)
			{
				//...is present as a node in the graph and...
				boolean toAdd = nodeIds.contains(ancestor);
{'fraction_non_alphanumeric': 0.1616871704745167, 'fraction_numerical': 0.00632688927943761, 'mean_word_length': 3.3575803981623276, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 2, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7180547', 'n_tokens_mistral': 2242, 'n_tokens_neox': 1915, 'n_words': 430}