# Path: riboSeed/shared_methods.py
# def md5(fname, string=False):
#     """straight from quantumsoup
#     http://stackoverflow.com/questions/3431825/
#         generating-an-md5-checksum-of-a-file
#     updated 20160916 for strings; if true, fname can be a string
#     """
#     if string:
#         return hashlib.md5(fname.encode('utf-8')).hexdigest()
#     else:
#         hash_md5 = hashlib.md5()
#         with open(fname, "rb") as f:
#             for chunk in iter(lambda: f.read(4096), b""):
#                 hash_md5.update(chunk)
#             return hash_md5.hexdigest()
# 
# Path: riboSeed/riboSpec.py
# DEBUG = False
#     PLOT = True
#     PLOT = False
#     M = [ [0]*size for i in range(size) ]
#     DG = nx.DiGraph()
#     N = G.number_of_nodes()
#     M = G.number_of_edges()
#     _G = nx.line_graph(G)
#     _N = _G.number_of_nodes()
#     _M = _G.number_of_edges()
#     RUN_16S, RUN_23S = True, True
#         RUN_16S = False
#         RUN_23S = False
#     L = [ list(x) for x in uniq ]
#         M = make_adjacency_matrix(G_dict)
#     RUN_16S, RUN_23S = check_rrnas_dict(rrnas, logger=logger)
#     ANY_TANDEM = "N"
#             REV = False
#                         REV = True
#                         ANY_TANDEM = "Y"
#                         ANY_TANDEM = "Y"
#     def do_profile(follow=[]):
#         def inner(func):
#             def profiled_func(*args, **kwargs):
#     def do_profile(follow=[]):
#         def inner(func):
#             def nothing(*args, **kwargs):
#     def __init__(self, name=None, length=None, cov=None,
#                  reverse_complimented=None, neighbor_list=None, raw=None):
#     def __str__(self):
# def get_args(test_args=None):  # pragma: no cover
# def extract_node_len_cov_rc(node_name):
# def make_Node(name):
# def make_adjacency_matrix(g):
# def plot_adjacency_matrix(G, node_order=None, partitions=[], colors=[], outpath=None): #pragma: no cover
# def parse_fastg(f):
# def plot_G(
#         G,
#         nodes5,
#         nodes16,
#         nodes23,
#         outpath, outpath2):  # pragma: nocover
# def neighborhood_by_length(G, source, cutoff=20000, ignored_nodes=[]):
# def make_gff_list(gffpath):
# def find_rRNA_from_gffs(gff_list, partial=False, logger=None):
# def get_depth_of_big_nodes(G, threshold=5000):
# def make_silly_boxplot(vals, outpath, names=None, title="", yline=None):  #pragma: nocover
# def percentile(N, percent, key=lambda x:x):
# def get_matching_node(name, rc, node_list):
# def node_name_and_strand_in_graph(node, G):
# def populate_subgraph_from_source(g, root, node_list, counter, length=0, cutoff=1000, debug=False):
# def reverse_populate_subgraph_from_source(g, root, node_list, counter, length=0, cutoff=1000, debug=False):
# def make_rRNAs_dict(gff_list, gff_list_partial):
# def check_rrnas_dict(rrnas, logger=None):
# def remove_duplicate_nested_lists(l):
# def remove_similar_lists(lst, lengths_lst, medium_threshold = 200):
# def add_temp_edges(node_list, G):
# def find_collapsable_partial_rRNA_nodes(
#         rrnas, G, nodes_data, threshold=200, logger=None):
# def make_path_without_simple_bubbles(path, g, nodes_data, threshold=20000, logger=None):
# def process_assembly_graph(args, fastg, output_root, PLOT, which_k, logger):
# def get_fastgs_from_spades_dir(d, logger=None):
# def main(args, logger=None):
# class FastgNode(object):


import sys
import logging
import shutil
import networkx as nx
import os
import unittest
import random
import networkx
from Bio import SeqIO
from argparse import Namespace
from riboSeed.shared_methods import md5
from riboSeed import riboSpec as rs
        # incl, border = rs.neighborhood_by_length(DG, source=4, cutoff=10)


    def test_spades_parse(self):
        t = rs.get_fastgs_from_spades_dir(self.spades_dir)
        self.assertEqual(4, len(t.keys()))

    def test_extract_node_len_cov_rc(self):
        node_name = "EDGE_313_length_1481_cov_1436.86"
        node_name_rc = "EDGE_313_length_1481_cov_1436.86'"
        self.assertEqual("313", rs.extract_node_len_cov_rc(node_name)[0])
        self.assertEqual(1481, rs.extract_node_len_cov_rc(node_name)[1])
        self.assertEqual(1436.86, rs.extract_node_len_cov_rc(node_name)[2])
        self.assertTrue(rs.extract_node_len_cov_rc(node_name_rc)[3])
        self.assertFalse(rs.extract_node_len_cov_rc(node_name)[3])

    def test_make_Node(self):
        node_name = "EDGE_313_length_1481_cov_1436.86"
        n = rs.make_Node(node_name)
        self.assertEqual(313, n.name)
        self.assertEqual(1481, n.length)
        self.assertEqual(1436.86, n.cov)
        self.assertEqual(node_name, n.raw)


    def test_make_adjacency_matrix(self):
        d = {1: [3, 4],
             2: [],
             3: [],
             4: [2, 3]}

# Path: riboSeed/shared_methods.py
# def md5(fname, string=False):
#     """straight from quantumsoup
#     http://stackoverflow.com/questions/3431825/
#         generating-an-md5-checksum-of-a-file
#     updated 20160916 for strings; if true, fname can be a string
#     """
#     if string:
#         return hashlib.md5(fname.encode('utf-8')).hexdigest()
#     else:
#         hash_md5 = hashlib.md5()
#         with open(fname, "rb") as f:
#             for chunk in iter(lambda: f.read(4096), b""):
#                 hash_md5.update(chunk)
#             return hash_md5.hexdigest()
# 
# Path: riboSeed/riboSpec.py
# DEBUG = False
#     PLOT = True
#     PLOT = False
#     M = [ [0]*size for i in range(size) ]
#     DG = nx.DiGraph()
#     N = G.number_of_nodes()
#     M = G.number_of_edges()
#     _G = nx.line_graph(G)
#     _N = _G.number_of_nodes()
#     _M = _G.number_of_edges()
#     RUN_16S, RUN_23S = True, True
#         RUN_16S = False
#         RUN_23S = False
#     L = [ list(x) for x in uniq ]
#         M = make_adjacency_matrix(G_dict)
#     RUN_16S, RUN_23S = check_rrnas_dict(rrnas, logger=logger)
#     ANY_TANDEM = "N"
#             REV = False
#                         REV = True
#                         ANY_TANDEM = "Y"
#                         ANY_TANDEM = "Y"
#     def do_profile(follow=[]):
#         def inner(func):
#             def profiled_func(*args, **kwargs):
#     def do_profile(follow=[]):
#         def inner(func):
#             def nothing(*args, **kwargs):
#     def __init__(self, name=None, length=None, cov=None,
#                  reverse_complimented=None, neighbor_list=None, raw=None):
#     def __str__(self):
# def get_args(test_args=None):  # pragma: no cover
# def extract_node_len_cov_rc(node_name):
# def make_Node(name):
# def make_adjacency_matrix(g):
# def plot_adjacency_matrix(G, node_order=None, partitions=[], colors=[], outpath=None): #pragma: no cover
# def parse_fastg(f):
# def plot_G(
#         G,
#         nodes5,
#         nodes16,
#         nodes23,
#         outpath, outpath2):  # pragma: nocover
# def neighborhood_by_length(G, source, cutoff=20000, ignored_nodes=[]):
# def make_gff_list(gffpath):
# def find_rRNA_from_gffs(gff_list, partial=False, logger=None):
# def get_depth_of_big_nodes(G, threshold=5000):
# def make_silly_boxplot(vals, outpath, names=None, title="", yline=None):  #pragma: nocover
# def percentile(N, percent, key=lambda x:x):
# def get_matching_node(name, rc, node_list):
# def node_name_and_strand_in_graph(node, G):
# def populate_subgraph_from_source(g, root, node_list, counter, length=0, cutoff=1000, debug=False):
# def reverse_populate_subgraph_from_source(g, root, node_list, counter, length=0, cutoff=1000, debug=False):
# def make_rRNAs_dict(gff_list, gff_list_partial):
# def check_rrnas_dict(rrnas, logger=None):
# def remove_duplicate_nested_lists(l):
# def remove_similar_lists(lst, lengths_lst, medium_threshold = 200):
# def add_temp_edges(node_list, G):
# def find_collapsable_partial_rRNA_nodes(
#         rrnas, G, nodes_data, threshold=200, logger=None):
# def make_path_without_simple_bubbles(path, g, nodes_data, threshold=20000, logger=None):
# def process_assembly_graph(args, fastg, output_root, PLOT, which_k, logger):
# def get_fastgs_from_spades_dir(d, logger=None):
# def main(args, logger=None):
# class FastgNode(object):


# Path: tests/test_riboSpec.py
import sys
import logging
import shutil
import networkx as nx
import os
import unittest
import random
import networkx
from Bio import SeqIO
from argparse import Namespace
from riboSeed.shared_methods import md5
from riboSeed import riboSpec as rs

        # incl, border = rs.neighborhood_by_length(DG, source=4, cutoff=10)


    def test_spades_parse(self):
        t = rs.get_fastgs_from_spades_dir(self.spades_dir)
        self.assertEqual(4, len(t.keys()))

    def test_extract_node_len_cov_rc(self):
        node_name = "EDGE_313_length_1481_cov_1436.86"
        node_name_rc = "EDGE_313_length_1481_cov_1436.86'"
        self.assertEqual("313", rs.extract_node_len_cov_rc(node_name)[0])
        self.assertEqual(1481, rs.extract_node_len_cov_rc(node_name)[1])
        self.assertEqual(1436.86, rs.extract_node_len_cov_rc(node_name)[2])
        self.assertTrue(rs.extract_node_len_cov_rc(node_name_rc)[3])
        self.assertFalse(rs.extract_node_len_cov_rc(node_name)[3])

    def test_make_Node(self):
        node_name = "EDGE_313_length_1481_cov_1436.86"
        n = rs.make_Node(node_name)
        self.assertEqual(313, n.name)
        self.assertEqual(1481, n.length)
        self.assertEqual(1436.86, n.cov)
        self.assertEqual(node_name, n.raw)


    def test_make_adjacency_matrix(self):
        d = {1: [3, 4],
             2: [],
             3: [],
             4: [2, 3]}

        M = rs.make_adjacency_matrix(d)