def get_alpha(r4s): """ Get the alpha parameter of the conservation scores, as defined by rate4site Args: r4s (file): The absolute file path to the alignment file Returns: The alpha parameter of the conservation score. """ try: if os.path.isfile(r4s): with open(r4s, 'r') as f: contents = f.read() splitted = contents.split(os.linesep) for s in splitted: if re.search('alpha parameter', s): parameter = constool.get_num(s) return parameter[0] raise Rate4SiteError('File format is not supported') else: raise FileNotFoundError except IndexError: raise Rate4SiteError('File format is not supported') finally: warnings.warn("This method is especially susceptible to changes in the format of \ the output file", Warning)
def test_get_num_negative(self): """Tests that get_num can retrieve negative and positive numbers from within a string""" digit = constool.get_num( "Hello, how are all 1234.56 and -42 of you today") self.assertEqual(digit, [1234.56, -42])
def test_get_num_none(self): """Tests that a string containing no digits returns no digits""" digit = constool.get_num("Oh, there are none of you today") self.assertEqual(digit, [])
def test_get_num_multi(self): """Tests that get_num can retrieve multiple floats and integers from a string """ digit = constool.get_num( "Hello, how are all 1234.56 and 42 of you today") self.assertEqual(digit, [1234.56, 42])
def test_get_num_good(self): """Tests that get num can retrieve a single float from a string""" digit = constool.get_num("Hello, how are all 1234.56 of you today") self.assertEqual(digit[0], 1234.56)