tp assemblage cours amine ghozlane

test_construction_debruijn.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """Tests for graph build"""
  2. import pytest
  3. import os
  4. import networkx as nx
  5. import pickle
  6. from .context import debruijn
  7. #from .context import debruijn_comp
  8. from debruijn import read_fastq
  9. from debruijn import cut_kmer
  10. from debruijn import build_kmer_dict
  11. from debruijn import build_graph
  12. def test_read_fastq():
  13. """Test fastq reading"""
  14. fastq_reader = read_fastq(os.path.abspath(os.path.join(os.path.dirname(__file__), "test_two_reads.fq")))
  15. assert next(fastq_reader) == "TCAGAGCTCTAGAGTTGGTTCTGAGAGAGATCGGTTACTCGGAGGAGGCTGTGTCACTCATAGAAGGGATCAATCACACCCACCACGTGTACCGAAACAA"
  16. assert next(fastq_reader) == "TTTGAATTACAACATCCATATGTTCTTGATGCTGGAATTCCAATATCTCAGTTGACAGTGTGCCCTCACCAGTGGATCAATTTACGAACCAACAATTGTG"
  17. def test_cut_kmer():
  18. """test Kmer cut"""
  19. kmer_reader = cut_kmer("TCAGA", 3)
  20. assert next(kmer_reader) == "TCA"
  21. assert next(kmer_reader) == "CAG"
  22. assert next(kmer_reader) == "AGA"
  23. def test_build_kmer_dict():
  24. kmer_dict = build_kmer_dict(os.path.abspath(os.path.join(os.path.dirname(__file__), "test_build.fq")), 3)
  25. assert(len(kmer_dict.keys()) == 4)
  26. assert "TCA" in kmer_dict
  27. assert "CAG" in kmer_dict
  28. assert "AGA" in kmer_dict
  29. assert "GAG" in kmer_dict
  30. assert kmer_dict["AGA"] == 2
  31. def test_build_graph():
  32. file = open(os.path.abspath(os.path.join(os.path.dirname(__file__), "kmer.pck")),'rb')
  33. kmer_dict = pickle.load(file)
  34. graph = build_graph(kmer_dict)
  35. #TCAGAGA
  36. #TCA TC CA
  37. #CAG CA AG
  38. #AGA AG GA
  39. #GAG GA AG
  40. #AGA AG GA
  41. assert graph.number_of_nodes() == 4
  42. assert graph.number_of_edges() == 4
  43. assert "AG" in graph
  44. assert "GA" in graph
  45. assert graph.edges["AG", "GA"]['weight'] == 2
  46. # def test_build_graph_comp():
  47. # file = open(os.path.abspath(os.path.join(os.path.dirname(__file__), "kmer_comp.pck")),'rb')
  48. # kmer_dict = pickle.load(file)
  49. # graph = build_graph(kmer_dict)
  50. # #TCAGAGA
  51. # #TCA TC CA
  52. # #CAG CA AG
  53. # #AGA AG GA
  54. # #GAG GA AG
  55. # #AGA AG GA
  56. # # ((TC, AG), (CA, GT)), (CA, AG), (AG
  57. # assert graph.number_of_nodes() == 4
  58. # assert graph.number_of_edges() == 3
  59. # assert "AG" in graph
  60. # assert "GA" in graph
  61. # assert graph.edges["AG", "GA"]['weight'] == 2