

from pymsascoring.score.score import Score

__author__ = "Juan ignacio Álvarez"
__license__ = "GPL"
__version__ = "1.0-SNAPSHOT"
__status__ = "Development"
__email__ = "juaalvare@uma.es"

class PercentageOfTotallyConservedColumns(Score):
    list = []

    def __init__(self, a):
        self.list = a

    def percentage_of_totally_conserved_columns(self):
        """
                        This function redefines count the number of conserved columns of a list of MSA

                        Args:
                            count - the number of totals conserved columns
                            count2 - number of equals letters  per column
                            curr_char - colum of each MSA
                            model - First sequence used as reference to starting the comparation
                        Returns:
                            score - Total score of MSA after calculating percentage of non gaps

                        """
        count = 0
        curr_char = 0
        model=self.list[0]
    #Iterate each letter of the secuencies
        while curr_char < len(model[1]):
            count2 = 0
        #Iterate each secuence
            for current_sequence in self.list:
                temp = model[1]
                temp2 = current_sequence[1]
                #Comparing and count
                if temp[curr_char] == temp2[curr_char] and temp2[curr_char] != "-":
                    count2 += 1
                    if count2 == len(self.list):
                        count += 1
            curr_char += 1
        return count / len(model[1]) * 100;
from pymsascoring.score.score import Score
import logging

__author__ = "Juan ignacio Álvarez"
__license__ = "GPL"
__version__ = "1.0-SNAPSHOT"
__status__ = "Development"
__email__ = "juaalvare@uma.es"

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class PercentageOfTotallyConservedColumns(Score):
    def __init__(self, msa):
        self.msa = msa

    def get_seqs_from_list_of_pairs(self, msa):
        """ Get the second value of a list with multiple elements.

        :param msa: List of pairs -id and sequence- (i.e. "[('ID1', 'AB'), ('ID2', 'CD'), ('ID3', 'EF')]" ).
        :return: List of sequences (i.e. "('AB', 'CD', 'EF' )").
        """

        sequences = []

        logger.debug('List of pairs: {0}'.format(msa))
        for i in range(len(msa)):
            sequences.append(msa[i][1])
        logger.debug('List of sequences: {0}'.format(sequences))
        return sequences

    def percentage_of_totally_conserved_columns(self):
        sequences = self.get_seqs_from_list_of_pairs(self.msa)  # List of sequences
        length_sequence = len(sequences[0])

        column = []
        percentage = 0

        for k in range(length_sequence):
            for value in sequences:
                column.append(value[k])
            if len(set(column)) <= 1:
                percentage += 1
            column.clear()

        logger.info('Total number of conserved colums: {0} out of {1}'.format(percentage, length_sequence))
        return percentage / length_sequence * 100
Refactor and logger added