<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2015 by <NAME>
# gaik (dot) tamazian (at) gmail (dot) com

import os
import logging
import unittest
from chromosomer.alignment.blast import Blast
from chromosomer.alignment.exception import BlastAlignmentError

path = os.path.dirname(__file__)
os.chdir(path)


class TestBlastAlignment(unittest.TestCase):
    def setUp(self):
        self.__correct_file = os.path.join(
            'data', 'blast', 'blast_tabular_alignments.txt'
        )
        self.__test_line = os.path.join(
            'data', 'blast', 'blast_tabular_line.txt'
        )
        self.__incorrect_lines = os.listdir(os.path.join(
            'data', 'blast', 'incorrect_input'
        ))
        # silence the logging messages
        logging.disable(logging.ERROR)

    def test_alignments(self):
        """
        Check if the parser reads a file in the BLAST tabular format
        in the correct way.
        """
        # test against the correct input file
        parser = Blast(self.__correct_file)
        for alignment in parser.alignments():
            self.assertEqual(len(alignment), 12)

        # test against the correct input line and check the entries
        parser = Blast(self.__correct_file)
        alignment = parser.alignments().next()
        self.assertIsInstance(alignment, Blast.Alignment)
        self.assertEqual(alignment.query, 'lcl|BA000007.2_gene_5374')
        self.assertEqual(alignment.subject,
                         'gi|556503834|ref|NC_000913.3|')
        self.assertEqual(alignment.identity, 98.14)
        self.assertEqual(alignment.length, 2856)
        self.assertEqual(alignment.mismatches, 53)
        self.assertEqual(alignment.gap_openings, 0)
        self.assertEqual(alignment.q_start, 1)
        self.assertEqual(alignment.q_end, 2856)
        self.assertEqual(alignment.s_start, 4483837)
        self.assertEqual(alignment.s_end, 4480982)
        self.assertEqual(alignment.e_value, 0.0)
        self.assertEqual(alignment.bit_score, 4981)

        # test again incorrect input lines, the exception must be
        # raised
        for incorrect_input in self.__incorrect_lines:
            parser = Blast(os.path.join(
                'data', 'blast', 'incorrect_input', incorrect_input))
            with self.assertRaises(BlastAlignmentError):
                alignment = parser.alignments().next()
                self.assertIsInstance(alignment, Blast.Alignment)

suite = unittest.TestLoader().loadTestsFromTestCase(TestBlastAlignment)
unittest.TextTestRunner(verbosity=2).run(suite)
<commit_msg>A minor fix in the test suite<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2015 by <NAME>
# gaik (dot) tamazian (at) gmail (dot) com

import os
import logging
import unittest
from chromosomer.alignment.blast import Blast
from chromosomer.alignment.exception import BlastAlignmentError

path = os.path.dirname(__file__)
os.chdir(path)


class TestBlastAlignment(unittest.TestCase):
    def setUp(self):
        self.__correct_file = os.path.join(
            'data', 'blast', 'blast_tabular_alignments.txt'
        )
        self.__test_line = os.path.join(
            'data', 'blast', 'blast_tabular_line.txt'
        )
        self.__incorrect_lines = os.listdir(os.path.join(
            'data', 'blast', 'incorrect_input'
        ))
        # silence the logging messages
        logging.disable(logging.ERROR)

    def test_alignments(self):
        """
        Check if the parser reads a file in the BLAST tabular format
        in the correct way.
        """
        # test against the correct input file
        parser = Blast(self.__correct_file)
        for alignment in parser.alignments():
            self.assertEqual(len(alignment), 12)

        # test against the correct input line and check the entries
        parser = Blast(self.__correct_file)
        alignment = parser.alignments().next()
        self.assertIsInstance(alignment, Blast.Alignment)
        self.assertEqual(alignment.query, 'lcl|BA000007.2_gene_5374')
        self.assertEqual(alignment.subject,
                         'gi|556503834|ref|NC_000913.3|')
        self.assertEqual(alignment.identity, 98.14)
        self.assertEqual(alignment.length, 2856)
        self.assertEqual(alignment.mismatches, 53)
        self.assertEqual(alignment.gap_openings, 0)
        self.assertEqual(alignment.q_start, 1)
        self.assertEqual(alignment.q_end, 2856)
        self.assertEqual(alignment.s_start, 4483837)
        self.assertEqual(alignment.s_end, 4480982)
        self.assertEqual(alignment.e_value, 0.0)
        self.assertEqual(alignment.bit_score, 4981)

        # test again incorrect input lines, the exception must be
        # raised
        for incorrect_input in self.__incorrect_lines:
            parser = Blast(os.path.join(
                'data', 'blast', 'incorrect_input', incorrect_input))
            with self.assertRaises(BlastAlignmentError):
                parser.alignments().next()

suite = unittest.TestLoader().loadTestsFromTestCase(TestBlastAlignment)
unittest.TextTestRunner(verbosity=2).run(suite)

{'fraction_non_alphanumeric': 0.10193798449612403, 'fraction_numerical': 0.02751937984496124, 'mean_word_length': 2.74800290486565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '791869', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1469, 'n_words': 319}