def test_overlapping_deletion(self): graph = graphContainer.GraphContainer() n = graph.add_altNode("chr", 10, 17, "ATCGATCG") varDel = {"start": 2, "end": 4, "alt": ""} varSNV = {"start": 4, "end": 4, "alt": "C"} variants.add_variants(graph, {n['name']: [varDel, varSNV]}) graphUtils.remove_empty_nodes(graph) nodeNames = [n['name'] for n in graph.nodes.values()] self.assertCountEqual(nodeNames, [ "chr:10-11:AT", "chr:12-13:CG", "chr:14-14:A", "chr:14-14:C", "chr:15-17:TCG" ]) left = graph.nodes["chr:10-11:AT"] right = graph.nodes["chr:15-17:TCG"] alt = graph.nodes["chr:14-14:C"] ref = graph.nodes["chr:14-14:A"] ins = graph.nodes["chr:12-13:CG"] self.assertTrue(graph.has_edge(left, right)) self.assertTrue(graph.has_edge(left, ins)) self.assertTrue(graph.has_edge(ins, ref)) self.assertTrue(graph.has_edge(ref, right)) self.assertTrue(graph.has_edge(ins, alt)) self.assertTrue(graph.has_edge(alt, right)) self.assertFalse(graph.has_edge(left, ref)) self.assertFalse(graph.has_edge(left, alt)) self.assertFalse(graph.has_edge(ref, ins))
def test_alt_snv(self): graph = graphContainer.GraphContainer() n = graph.add_altNode("chr", 10, 20, "ATCGATCG") var = {"start": 2, "end": 2, "alt": "T"} variants.add_variants(graph, {n['name']: [var]}) nodeNames = [n['name'] for n in graph.nodes.values()] self.assertCountEqual(nodeNames, ["chr:10-11:AT", "chr:12-12:C", "chr:13-20:GATCG", "chr:12-12:T"]) self.assertEqual(graph.nodes["chr:10-11:AT"]["sequence"], "AT") self.assertEqual(graph.nodes["chr:13-20:GATCG"]["sequence"], "GATCG") self.assertEqual(graph.nodes["chr:12-12:C"]["sequence"], "C") self.assertEqual(graph.nodes["chr:12-12:T"]["sequence"], "T")
def test_insertion(self): graph = graphContainer.GraphContainer() n = graph.add_altNode("chr", 10, 17, "ATCGATCG") var = {"start": 3, "end": 2, "alt": "TTT"} variants.add_variants(graph, {n['name']: [var]}) nodeNames = [n['name'] for n in graph.nodes.values()] self.assertCountEqual(nodeNames, ["chr:10-12:ATC", "chr:13-17:GATCG", "chr:13-12:TTT"]) left = graph.nodes["chr:10-12:ATC"] right = graph.nodes["chr:13-17:GATCG"] ins = graph.nodes["chr:13-12:TTT"] self.assertTrue(graph.has_edge(left, right)) self.assertTrue(graph.has_edge(left, ins)) self.assertTrue(graph.has_edge(ins, right)) self.assertFalse(graph.has_edge(ins, left)) self.assertFalse(graph.has_edge(right, ins))
def test_ref_snv(self): graph = graphContainer.GraphContainer() n = graph.add_refNode("chr", 10, 20) var = {"start": 2, "end": 2, "alt": "C"} variants.add_variants(graph, {n['name']: [var]}) nodeNames = [n['name'] for n in graph.nodes.values()] self.assertCountEqual(nodeNames, ["ref-chr:10-11", "ref-chr:12-12", "ref-chr:13-20", "chr:12-12:C"]) self.assertEqual(graph.nodes["chr:12-12:C"]["sequence"], "C") left = graph.nodes["ref-chr:10-11"] right = graph.nodes["ref-chr:13-20"] alt = graph.nodes["chr:12-12:C"] ref = graph.nodes["ref-chr:12-12"] self.assertTrue(graph.has_edge(left, ref)) self.assertTrue(graph.has_edge(left, alt)) self.assertTrue(graph.has_edge(ref, right)) self.assertTrue(graph.has_edge(alt, right)) self.assertFalse(graph.has_edge(left, right)) self.assertFalse(graph.has_edge(ref, alt))
def test_ins_end(self): graph = graphContainer.GraphContainer() r = graph.add_refNode("chr", 18, 20) n = graph.add_altNode("chr", 10, 17, "ATCGATCG") graph.add_edge(n, r, ["foo"]) var = {"start": 8, "end": 7, "alt": "CCC"} variants.add_variants(graph, {n['name']: [var]}) graphUtils.remove_empty_nodes(graph) left = graph.nodes["chr:10-17:ATCGATCG"] right = graph.nodes["ref-chr:18-20"] alt = graph.nodes["chr:18-17:CCC"] self.assertEqual(len(graph.nodes), 3) self.assertTrue(graph.has_edge(left, right)) self.assertTrue(graph.has_edge(left, alt)) self.assertTrue(graph.has_edge(alt, right)) self.assertFalse(graph.has_edge(alt, left)) self.assertFalse(graph.has_edge(right, alt)) self.assertCountEqual(graph.get_edge(left['name'], right['name'])['sequences'], ["foo"]) self.assertCountEqual(graph.get_edge(alt['name'], right['name'])['sequences'], ["foo"])
def run(args): levels = [logging.WARNING, logging.INFO, logging.DEBUG] logging.basicConfig(format='%(message)s', level=levels[min(args.verbose, len(levels) - 1)]) graphDict = load_json(args.graph) graph = graphUtils.load_json(graphDict) if args.variants: varJson = load_json(args.variants) if "variants" not in varJson: raise Exception("No variants in variant JSON") varDict = varJson["variants"] else: varDict = graphDict.get("variants", {}) if not varDict: logging.warning("No variants in graph") print(varDict.keys()) variants.add_variants(graph, varDict) graphUtils.remove_empty_nodes(graph) json.dump(graph.json_dict(), args.output, sort_keys=True)
def test_var_begin(self): graph = graphContainer.GraphContainer() r = graph.add_refNode("chr", 1, 9) n = graph.add_altNode("chr", 10, 17, "ATCGATCG") graph.add_edge(r, n, ["foo"]) var = {"start": 0, "end": 0, "alt": "G"} variants.add_variants(graph, {n['name']: [var]}) graphUtils.remove_empty_nodes(graph) left = graph.nodes["ref-chr:1-9"] right = graph.nodes["chr:11-17:TCGATCG"] ref = graph.nodes["chr:10-10:A"] alt = graph.nodes["chr:10-10:G"] self.assertEqual(len(graph.nodes), 4) self.assertTrue(graph.has_edge(left, ref)) self.assertTrue(graph.has_edge(left, alt)) self.assertTrue(graph.has_edge(ref, right)) self.assertTrue(graph.has_edge(alt, right)) self.assertFalse(graph.has_edge(left, right)) self.assertFalse(graph.has_edge(ref, alt)) self.assertCountEqual(graph.get_edge(left['name'], ref['name'])['sequences'], ["foo"]) self.assertCountEqual(graph.get_edge(left['name'], alt['name'])['sequences'], ["foo"])