tp assemblage cours amine ghozlane

test_characteristics.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Tests for graph characteristic"""
  2. import pytest
  3. import os
  4. import networkx as nx
  5. import hashlib
  6. from .context import debruijn
  7. #from .context import debruijn_comp
  8. from debruijn import get_starting_nodes
  9. from debruijn import get_sink_nodes
  10. from debruijn import get_contigs
  11. from debruijn import save_contigs
  12. def test_get_starting_nodes():
  13. graph = nx.DiGraph()
  14. graph.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
  15. nodes = get_starting_nodes(graph)
  16. assert len(nodes) == 2
  17. assert 1 in nodes
  18. assert 3 in nodes
  19. def test_get_sink_nodes():
  20. graph = nx.DiGraph()
  21. graph.add_edges_from([(1, 2), (3, 2), (2, 4), (4, 5), (5, 6), (5, 7)])
  22. nodes = get_sink_nodes(graph)
  23. assert len(nodes) == 2
  24. assert 6 in nodes
  25. assert 7 in nodes
  26. def test_get_contigs():
  27. graph = nx.DiGraph()
  28. graph.add_edges_from([("TC", "CA"), ("AC", "CA"), ("CA", "AG"), ("AG", "GC"), ("GC", "CG"), ("CG", "GA"), ("GA", "AT"), ("GA", "AA")])
  29. contig_list = get_contigs(graph, ["TC", "AC"], ["AT" , "AA"])
  30. results = ["TCAGCGAT", "TCAGCGAA", "ACAGCGAT", "ACAGCGAA"]
  31. assert len(contig_list) == 4
  32. for contig in contig_list:
  33. assert contig[0] in results
  34. assert contig[1] == 8
  35. # def test_get_contigs_comp():
  36. # graph = nx.DiGraph()
  37. # graph.add_edges_from([(("AG", "TC"), ("CA", "GT")), (("AC", "TG"), ("CA", "GT")), (("CA", "GT"), ("AG", "TC")),
  38. # (("AG", "TC"), ("CG", "GC")), (("CG", "GC"), ("CG", "GC")), (("CG", "GC"), ("CT", "GA")), (("CT", "GA"), ("AT", "TC")),
  39. # (("CT", "GA"), ("AA", "TT"))])
  40. # contig_list = get_contigs(graph, ["TC", "AC"], ["AT" , "AA"])
  41. # results = ["TCAGCGAT", "TCAGCGAA", "ACAGCGAT", "ACAGCGAA"]
  42. # assert len(contig_list) == 4
  43. # for contig in contig_list:
  44. # assert contig[0] in results
  45. # assert contig[1] == 8
  46. def test_save_contigs():
  47. test_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "test.fna"))
  48. contig = [("TCAGCGAT", 8), ("TCAGCGAA",8), ("ACAGCGAT", 8), ("ACAGCGAA", 8)]
  49. save_contigs(contig, test_file)
  50. with open(test_file, 'rb') as contig_test:
  51. assert hashlib.md5(contig_test.read()).hexdigest() == "ca84dfeb5d58eca107e34de09b3cc997"