Exemplo n.º 1
0
    def test_read_interaction_file(self):
        """This function applies several tests to check several features. """

        """Tests if the output is a dictionary"""
        dict_test = graphReading.read_interaction_file_dict(interaction_file)
        dict_type = type(dict_test)
        self.assertEqual(dict_type, dict)  # assertEqual() tests the equality between two parameters

        """Tests if the output is a list"""
        list_test = graphReading.read_interaction_file_list(interaction_file)
        list_type = type(list_test)
        self.assertEqual(list_type, list)

        """Tests if the output is a list of tuples"""
        tuple_test = graphReading.read_interaction_file(interaction_file)
        tuple_type = type(tuple_test)
        self.assertEqual(tuple_type, tuple)

        """Tests if a file is empty"""
        first_char = int(file_empty.read(1))  # Gets the first character (if there is one, then it equals to 1)
        #print(type(first_char))
        if not first_char:
            no_char = 0  # If there is not a character in the file, then it equals to 0
        self.assertEqual(first_char, no_char)

        """Tests if a file whose first line has a wrong number which counts the number of interactions"""
        first_line = int(first_line_wrong.readline(1))  # Gets the first line
        lines_num = len(first_line_wrong.readlines())  # Counts the number of lines
        interaction_int = lines_num - 1
        self.assertEqual(first_line, interaction_int)

        """Tests if a file has not a first line with the number of interactions"""
        # TO DO

        """Tests if the number of columns is correct"""
Exemplo n.º 2
0
    def time_read_interaction_file(self):
        """This function measures the time in seconds to execute the functions read_interaction_file_dict and
        read_interaction_file_list in order to compare their performances."""

        dict_start = time.time()
        graphReading.read_interaction_file_dict(interaction_file)
        dict_finished = time.time() - dict_start

        print("Time to execute the function read_interaction_file_dict is {} seconds".format(dict_finished))


        list_start = time.time()
        graphReading.read_interaction_file_list(interaction_file)
        list_finished = time.time() - list_start

        print("Time to execute the function read_interaction_file_list is {} seconds".format(list_finished))
Exemplo n.º 3
0
def count_vertices(Human_HighQuality):
    """This function counts the number of peaks of a graph.

    :param Human_HighQuality: interaction file
    :return: vertices_int: number of vertices
    :rtype: integer
    """
    with open(Human_HighQuality, "r") as interaction_file:
        vertices_int = len(read_interaction_file_dict(Human_HighQuality))  # Counts the number of keys in the dictionary
        return vertices_int
Exemplo n.º 4
0
def get_ave_degree(Human_HighQuality):
    """This function calculates the proteins' average degree of the interaction graph.

    :param Human_HighQuality: interaction file
    :return: ave_degree_float: proteins' average degree
    :rtype: float
    """
    with open(Human_HighQuality, "r") as interaction_file:
        prot_graph_dict = read_interaction_file_dict(Human_HighQuality)

        for vertice in prot_graph_dict:  # For each protein in the dictionary...
            ave_degree_float = len(prot_graph_dict[vertice])/len(prot_graph_dict)  # ... It calculates the number of interaction,
            # And the total number of interactions is divided by the total number of proteins

        return ave_degree_float
Exemplo n.º 5
0
def get_degree(Human_HighQuality, prot):
    """This function takes an interaction graph and a protein name inputed by the user to return the protein's degree in
     the graph.

    :param Human_HighQuality: interaction file
    :param prot: inputed protein name
    :type prot: string
    :return: interactions_int: number of the protein's interactions
    :rtype: integer
    """
    with open(Human_HighQuality, "r") as interaction_file:
        prot_graph_dict = read_interaction_file_dict(Human_HighQuality)
        interactions_int = len(prot_graph_dict[prot])  # Takes the number of proteins in the dictionary that interacts
        # with the inputed protein

        return interactions_int
Exemplo n.º 6
0
def count_degree(Human_HighQuality, deg):
    """This function calculates the number of proteins from the interaction graph whose degree equals the parameter deg.

    :param Human_HighQuality: interaction file
    :param deg: number of interactions inputed by the user
    :type deg: integer
    :return: prot_list: list of proteins that have a degree which equals to the inputed degree
    :rtype: list
    """
    with open(Human_HighQuality, "r") as interaction_file:
        prot_graph_dict = read_interaction_file_dict(Human_HighQuality)
        prot_list = []

        for vertice in prot_graph_dict:  # This loop will check each element of the dictionary the following condition
            if len(prot_graph_dict[vertice]) == deg:  # If the current protein's degree equals to the inputed one...
                prot_list.append(vertice)  # ... Then, the protein is added to the list

        return str(prot_list)
Exemplo n.º 7
0
def get_max_degree(Human_HighQuality):
    """This function gets the protein's name with the maximum of interactions and its degree.

    :param Human_HighQuality: interaction file
    :return: prot_str, max_degree_int: protein name
    :rtype: string, integer
    """
    with open(Human_HighQuality, "r") as interaction_file:
        prot_graph_dict = read_interaction_file_dict(Human_HighQuality)
        max_degree_int = 0  # Initialisation of the variable
        prot_str = ""

        for vertice in prot_graph_dict:  # This loop checks for each element of the dictionary the following condition

            if len(prot_graph_dict[vertice]) > max_degree_int:  # If the number of proteins that interact with the
                # current one is superior to the current maximum degree
                max_degree_int = len(prot_graph_dict[vertice])  # Then, the maximum degree takes the new protein degree's value
                prot_str = vertice  # And the argument takes this protein's name

        return (prot_str, max_degree_int)