tp assemblage cours amine ghozlane

test_construction_debruijn.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 debruijn import read_fastq
  8. from debruijn import cut_kmer
  9. from debruijn import build_kmer_dict
  10. from debruijn import build_graph
  11. def test_read_fastq():
  12. """Test fastq reading"""
  13. fastq_reader = read_fastq(os.path.abspath(os.path.join(os.path.dirname(__file__), "test_two_reads.fq")))
  14. assert next(fastq_reader) == "TCAGAGCTCTAGAGTTGGTTCTGAGAGAGATCGGTTACTCGGAGGAGGCTGTGTCACTCATAGAAGGGATCAATCACACCCACCACGTGTACCGAAACAA"
  15. assert next(fastq_reader) == "TTTGAATTACAACATCCATATGTTCTTGATGCTGGAATTCCAATATCTCAGTTGACAGTGTGCCCTCACCAGTGGATCAATTTACGAACCAACAATTGTG"
  16. def test_cut_kmer():
  17. """test Kmer cut"""
  18. kmer_reader = cut_kmer("TCAGA", 3)
  19. assert next(kmer_reader) == "TCA"
  20. assert next(kmer_reader) == "CAG"
  21. assert next(kmer_reader) == "AGA"
  22. def test_build_kmer_dict():
  23. kmer_dict = build_kmer_dict(os.path.abspath(os.path.join(os.path.dirname(__file__), "test_build.fq")), 3)
  24. assert(len(kmer_dict.keys()) == 4)
  25. assert "TCA" in kmer_dict
  26. assert "CAG" in kmer_dict
  27. assert "AGA" in kmer_dict
  28. assert "GAG" in kmer_dict
  29. assert kmer_dict["AGA"] == 2
  30. def test_build_graph():
  31. file = open(os.path.abspath(os.path.join(os.path.dirname(__file__), "kmer.pck")),'rb')
  32. kmer_dict = pickle.load(file)
  33. graph = build_graph(kmer_dict)
  34. #TCAGAGA
  35. #TCA TC CA
  36. #CAG CA AG
  37. #AGA AG GA
  38. #GAG GA AG
  39. #AGA AG GA
  40. assert graph.number_of_nodes() == 4
  41. assert graph.number_of_edges() == 4
  42. assert "AG" in graph
  43. assert "GA" in graph
  44. assert graph.edges["AG", "GA"]['weight'] == 2