예제 #1
0
    def test_file_invalid(self, invalid_csv_alignment):
        """Tests that the invalid alignment files fail properly.

        Args:
            invalid_csv_alignment (pytest.fixture): A parameterized pytest
                fixture providing invalid csv alignment filenames.
        """
        with open(invalid_csv_alignment) as in_csv:
            with pytest.raises(dr.AlignmentIOError):
                dr.read_csv_alignment_flo(in_csv)
예제 #2
0
    def test_stringio_valid(self, valid_csv_alignment):
        """Tests that alignments are read properly with valid input data.

        Tests that the valid alignment files do not fail when loaded into
        StringIO objects.

        Args:
            valid_csv_alignment (pytest.fixture): A parameterized pytest
                fixture providing valid csv alignment filenames.

        Raises:
            AssertionError: Raised if an exception is thrown when reading.
        """
        with open(valid_csv_alignment) as in_csv:
            csv_stringio = StringIO()
            csv_stringio.write(in_csv.read())
            csv_stringio.seek(0)
            try:
                (sequence_list,
                 headers) = dr.read_csv_alignment_flo(csv_stringio)
                assert len(headers) > 0
                assert len(sequence_list) > 0
                for i in sequence_list:
                    assert isinstance(i, Sequence)
                    assert isinstance(i.name, str)
                    assert len(i.cont_values) > 0
            except Exception as e:
                print('Raised exception: {}'.format(str(e)))
                raise AssertionError(e)
예제 #3
0
    def test_stringio_invalid(self, invalid_csv_alignment):
        """Tests that invalid alignment files cause the proper failure.

        Tests that the invalid alignment files fail properly when loaded into
        StringIO objects.

        Args:
            invalid_csv_alignment (pytest.fixture): A parameterized pytest
                fixture providing invalid csv alignment filenames.
        """
        with open(invalid_csv_alignment) as in_csv:
            csv_stringio = StringIO()
            csv_stringio.write(in_csv.read())
            csv_stringio.seek(0)
            with pytest.raises(dr.AlignmentIOError):
                dr.read_csv_alignment_flo(csv_stringio)
예제 #4
0
    def test_file_valid(self, valid_csv_alignment):
        """Tests that the valid alignment files do not fail.

        Args:
            valid_csv_alignment (pytest.fixture): A parameterized pytest
                fixture providing valid csv alignment filenames.
        """
        with open(valid_csv_alignment) as in_csv:
            try:
                sequence_list, headers = dr.read_csv_alignment_flo(in_csv)
                assert len(headers) > 0
                assert len(sequence_list) > 0
                for i in sequence_list:
                    assert isinstance(i, Sequence)
                    assert isinstance(i.name, string_formats)
                    assert len(i.cont_values) > 0
            except Exception as e:
                print('Raised exception: {}'.format(str(e)))
                assert False
예제 #5
0
    else:
        nrand = int(args.number_permutations)
    print(nrand)

    # Check that input files exist
    if not os.path.exists(args.in_tree_filename):
        raise IOError('Input tree {} does not exist'.format(
            args.in_tree_filename))
    if not os.path.exists(args.pam_filename):
        raise IOError('Input data file {} does not exist'.format(
            args.pam_filename))

    # Read data
    if args.data_format == 'csv':
        with open(args.pam_filename) as in_file:
            sequences, headers = data_readers.read_csv_alignment_flo(in_file)
    elif args.data_format == 'json':
        with open(args.pam_filename) as in_file:
            sequences, headers = data_readers.read_json_alignment_flo(in_file)
    elif args.data_format == 'phylip':
        with open(args.pam_filename) as in_file:
            sequences = data_readers.read_phylip_alignment_flo(in_file)
        headers = None
    elif args.data_format == 'table':
        with open(args.pam_filename) as in_file:
            sequences = data_readers.read_table_alignment_flo(in_file)
        headers = None
    else:
        raise Exception('Unknown data format: {}'.format(args.data_format))

    # Get the label annotation column, or None