Exemplo n.º 1
0
    def test_single_sample(self, tmpdir, path_proj_conf_file,
                           which_sample_index):
        """ Single Sample is perfectly valid for Project and sheet. """

        # Pull out the values for the current sample.
        values = DATA[which_sample_index]

        # Write the annotations.
        anns_path = os.path.join(tmpdir.strpath, NAME_ANNOTATIONS_FILE)
        with open(anns_path, 'w') as anns_file:
            anns_file.write("{}\n".format(",".join(COLUMNS)))
            anns_file.write("{}\n".format(",".join([str(v) for v in values])))

        # Build the sheet.
        p = Project(path_proj_conf_file)
        sheet = p.build_sheet()

        # It should be a single-row DataFrame.
        assert isinstance(sheet, pd.DataFrame)
        assert 1 == len(sheet)
        assert 1 == p.num_samples

        # There will be additional values added from the Project,
        # but the core data values will have remained the same.
        sample = list(p.samples)[0]
        for attr, exp_val in zip(COLUMNS, values):
            obs_val = getattr(sample, attr)
            try:
                assert exp_val == obs_val
            except AssertionError as e:
                try:
                    assert exp_val == int(obs_val)
                except AssertionError:
                    raise e
Exemplo n.º 2
0
    def test_multiple_samples(self, protocols, path_anns_file,
                              path_proj_conf_file):
        """ Project also processes multiple Sample fine. """

        p = Project(path_proj_conf_file)

        # Total sample count is constant.
        assert len(SAMPLE_NAMES) == sum(1 for _ in p.samples)

        # But the sheet permits filtering to specific protocol(s).
        exp_num_samples = len(SAMPLE_NAMES) if not protocols else \
            sum(sum(1 for l in LIBRARIES if l == p) for p in protocols)
        sheet = p.build_sheet(*protocols)
        assert exp_num_samples == len(sheet)
        if protocols:
            fuzzy_protos = {alpha_cased(p) for p in protocols}
            for _, sample_data in sheet.iterrows():
                assert alpha_cased(sample_data.library) in fuzzy_protos
Exemplo n.º 3
0
 def test_no_samples(self, protocols, delimiter, path_empty_project):
     """ Lack of Samples is unproblematic for the sheet build. """
     # Regardless of protocol(s), the sheet should be empty.
     p = Project(path_empty_project)
     sheet = p.build_sheet(*protocols)
     assert sheet.empty