Пример #1
0
    def test_validate_negative_missing_keys(self):
        filepath = self.get_data_path('placements-missing.json')
        fmt = PlacementsFormat(filepath, mode='r')

        with self.assertRaisesRegex(ValidationError,
                                    'found.*placements.*tree'):
            fmt.validate()
Пример #2
0
    def test_placements_format_to_dict(self):
        transformer = self.get_transformer(PlacementsFormat, dict)

        fp = pathlib.Path(self.temp_dir.name) / pathlib.Path('placements.json')
        fp.write_text('{"foo": 1}')

        input_ = PlacementsFormat(str(fp), mode='r')
        with self.assertRaisesRegex(ValidationError, r'found \[\'foo\'\]'):
            # A bit of a cop-out, but this means we were able to parse the
            # JSON document.
            input_.validate(level='max')

        obs = transformer(input_)
        self.assertEqual(obs, {'foo': 1})
Пример #3
0
def sepp(representative_sequences: DNASequencesDirectoryFormat,
         reference_database: SeppReferenceDirFmt,
         alignment_subset_size: int = 1000,
         placement_subset_size: int = 5000,
         threads: int = 1,
         debug: bool = False,
         ) -> (NewickFormat, PlacementsFormat):

    placements = 'q2-fragment-insertion_placement.json'
    tree = 'q2-fragment-insertion_placement.tog.relabelled.tre'

    placements_result = PlacementsFormat()
    tree_result = NewickFormat()

    with tempfile.TemporaryDirectory() as tmp:
        _run(str(representative_sequences.file.view(DNAFASTAFormat)),
             str(threads), tmp,
             str(alignment_subset_size), str(placement_subset_size),
             str(reference_database.alignment.path_maker()),
             str(reference_database.phylogeny.path_maker()),
             str(reference_database.raxml_info.path_maker()),
             debug)
        outtree = os.path.join(tmp, tree)
        outplacements = os.path.join(tmp, placements)

        _add_missing_branch_length(outtree)

        shutil.copyfile(outtree, str(tree_result))
        shutil.copyfile(outplacements, str(placements_result))

    return tree_result, placements_result
Пример #4
0
def sepp(
    representative_sequences: DNASequencesDirectoryFormat,
    threads: int = 1,
    alignment_subset_size: int = 1000,
    placement_subset_size: int = 5000,
    reference_alignment: AlignedDNASequencesDirectoryFormat = None,
    reference_phylogeny: NewickFormat = None,
    debug: bool = False,
) -> (NewickFormat, PlacementsFormat):

    _sanity()
    # check if sequences and tips in reference match
    if not _reference_matches(reference_alignment, reference_phylogeny):
        raise ValueError(
            ('Reference alignment and phylogeny do not match up. Please ensure'
             ' that all sequences in the alignment correspond to exactly one '
             'tip name in the phylogeny.'))

    placements = 'q2-fragment-insertion_placement.json'
    tree = 'q2-fragment-insertion_placement.tog.relabelled.tre'

    placements_result = PlacementsFormat()
    tree_result = NewickFormat()

    with tempfile.TemporaryDirectory() as tmp:
        _run(str(representative_sequences.file.view(DNAFASTAFormat)),
             str(threads), tmp, str(alignment_subset_size),
             str(placement_subset_size), reference_alignment,
             reference_phylogeny, debug)
        outtree = os.path.join(tmp, tree)
        outplacements = os.path.join(tmp, placements)

        _add_missing_branch_length(outtree)

        shutil.copyfile(outtree, str(tree_result))
        shutil.copyfile(outplacements, str(placements_result))

    return tree_result, placements_result
Пример #5
0
    def test_validate_negative_array(self):
        filepath = self.get_data_path('root-array.json')
        fmt = PlacementsFormat(filepath, mode='r')

        with self.assertRaisesRegex(ValidationError, 'JSON object'):
            fmt.validate()
Пример #6
0
    def test_validate_positive(self):
        filepath = self.get_data_path('placements.json')
        fmt = PlacementsFormat(filepath, mode='r')

        fmt.validate()
        self.assertTrue(True)