From 0593fac6f8cd75fec9a58f6b94419d3de2dab29b Mon Sep 17 00:00:00 2001 From: thanhleviet Date: Tue, 2 Jul 2024 13:21:31 +0000 Subject: [PATCH] rfix: format --- q2_usearch/_chimera.py | 134 ---------------------- q2_usearch/tests/test_fastq_mergepairs.py | 1 + q2_usearch/tests/test_fastx_truncate.py | 8 +- 3 files changed, 6 insertions(+), 137 deletions(-) delete mode 100644 q2_usearch/_chimera.py diff --git a/q2_usearch/_chimera.py b/q2_usearch/_chimera.py deleted file mode 100644 index 98b46af..0000000 --- a/q2_usearch/_chimera.py +++ /dev/null @@ -1,134 +0,0 @@ -# ---------------------------------------------------------------------------- -# Copyright (c) 2016-2023, QIIME 2 development team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -# ---------------------------------------------------------------------------- - -import tempfile - -import biom -from q2_types.feature_data import DNAFASTAFormat - -from ._utils import run_command, _fasta_with_sizes - -# from ._cluster_features import _fasta_with_sizes, run_command -# from ._format import UchimeStatsFmt - - -_uchime_defaults = {"dn": 1.4, "mindiffs": 3, "mindiv": 0.8, "minh": 0.28, "xn": 8.0} - - -def uchime_ref( - sequences: DNAFASTAFormat, - table: biom.Table, - reference_sequences: DNAFASTAFormat, - dn: float = _uchime_defaults["dn"], - mindiffs: int = _uchime_defaults["mindiffs"], - mindiv: float = _uchime_defaults["mindiv"], - minh: float = _uchime_defaults["minh"], - xn: float = _uchime_defaults["xn"], - threads: int = 1, -) -> (DNAFASTAFormat, DNAFASTAFormat, UchimeStatsFmt): - cmd, chimeras, nonchimeras, uchime_stats = _uchime_ref( - sequences, table, reference_sequences, dn, mindiffs, mindiv, minh, xn, threads - ) - return chimeras, nonchimeras, uchime_stats - - -def _uchime_ref( - sequences, table, reference_sequences, dn, mindiffs, mindiv, minh, xn, threads -): - # this function only exists to simplify testing - chimeras = DNAFASTAFormat() - nonchimeras = DNAFASTAFormat() - uchime_stats = UchimeStatsFmt() - with tempfile.NamedTemporaryFile() as fasta_with_sizes: - _fasta_with_sizes(str(sequences), fasta_with_sizes.name, table) - cmd = [ - "vsearch", - "--uchime_ref", - fasta_with_sizes.name, - "--uchimeout", - str(uchime_stats), - "--nonchimeras", - str(nonchimeras), - "--chimeras", - str(chimeras), - "--dn", - str(dn), - "--mindiffs", - str(mindiffs), - "--mindiv", - str(mindiv), - "--minh", - str(minh), - "--xn", - str(xn), - "--db", - str(reference_sequences), - "--qmask", - "none", # ensures no lowercase DNA chars - "--xsize", - "--threads", - str(threads), - "--fasta_width", - "0", - ] - run_command(cmd) - - return cmd, chimeras, nonchimeras, uchime_stats - - -def uchime3_denovo( - sequences: DNAFASTAFormat, - table: biom.Table, - dn: float = _uchime_defaults["dn"], - mindiffs: int = _uchime_defaults["mindiffs"], - mindiv: float = _uchime_defaults["mindiv"], - minh: float = _uchime_defaults["minh"], - xn: float = _uchime_defaults["xn"], -) -> (DNAFASTAFormat, DNAFASTAFormat, UchimeStatsFmt): - cmd, chimeras, nonchimeras, uchime_stats = _uchime_denovo( - sequences, table, dn, mindiffs, mindiv, minh, xn - ) - return chimeras, nonchimeras, uchime_stats - - -def _uchime3_denovo(sequences, table, dn, mindiffs, mindiv, minh, xn): - # this function only exists to simplify testing - chimeras = DNAFASTAFormat() - nonchimeras = DNAFASTAFormat() - uchime_stats = UchimeStatsFmt() - with tempfile.NamedTemporaryFile() as fasta_with_sizes: - _fasta_with_sizes(str(sequences), fasta_with_sizes.name, table) - cmd = [ - "usearch", - "-uchime3_denovo", - fasta_with_sizes.name, - "-uchimeout", - str(uchime_stats), - "--nonchimeras", - str(nonchimeras), - "--chimeras", - str(chimeras), - "--dn", - str(dn), - "--mindiffs", - str(mindiffs), - "--mindiv", - str(mindiv), - "--minh", - str(minh), - "--xn", - str(xn), - "--qmask", - "none", # ensures no lowercase DNA chars - "--xsize", - "--fasta_width", - "0", - ] - run_command(cmd) - - return cmd, chimeras, nonchimeras, uchime_stats diff --git a/q2_usearch/tests/test_fastq_mergepairs.py b/q2_usearch/tests/test_fastq_mergepairs.py index eae2377..57f3205 100644 --- a/q2_usearch/tests/test_fastq_mergepairs.py +++ b/q2_usearch/tests/test_fastq_mergepairs.py @@ -1,5 +1,6 @@ import os import pandas as pd +import unittest from unittest.mock import patch from qiime2.plugin.testing import TestPluginBase from qiime2 import Artifact diff --git a/q2_usearch/tests/test_fastx_truncate.py b/q2_usearch/tests/test_fastx_truncate.py index 772e008..22ce7dd 100644 --- a/q2_usearch/tests/test_fastx_truncate.py +++ b/q2_usearch/tests/test_fastx_truncate.py @@ -10,8 +10,10 @@ import logging as logger import gzip + logger.basicConfig(level=logger.DEBUG) + class TestFastxTruncate(TestPluginBase): package = "q2_usearch.tests" @@ -35,7 +37,7 @@ def test_fastx_truncate_default_params(self): truncated_seqs = fastx_truncate(self.sequences) # Check if the returned object is of the correct type self.assertIsInstance(truncated_seqs, SingleLanePerSampleSingleEndFastqDirFmt) - + def test_fastx_truncate_custom_params(self): # Test with custom parameters truncated_seqs = fastx_truncate( @@ -140,7 +142,7 @@ def test_fastx_truncate_output_content(self): 100, "Sequence is longer than specified truncation length", ) - + if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main()