qiime2-its 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
qiime2_its/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from qiime2_its._version import __version__
2
+
3
+ __all__ = ["__version__"]
qiime2_its/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.3.2"
Binary file
@@ -0,0 +1,37 @@
1
+ """Helpers for merging QIIME2 taxonomy assignments into a biom feature table."""
2
+ import subprocess
3
+ from pathlib import Path
4
+
5
+ TAXONOMY_HEADER = '#OTUID\ttaxonomy\tconfidence\n'
6
+
7
+
8
+ def rewrite_taxonomy_header(taxonomy_tsv):
9
+ """Replace the first line of a QIIME2-exported taxonomy.tsv with the header
10
+ biom's `add-metadata` expects (#OTUID / taxonomy / confidence).
11
+ """
12
+ taxonomy_tsv = Path(taxonomy_tsv)
13
+ tmp_path = taxonomy_tsv.with_name(taxonomy_tsv.name + '.tmp')
14
+ with open(taxonomy_tsv) as in_f, open(tmp_path, 'w') as out_f:
15
+ out_f.write(TAXONOMY_HEADER)
16
+ next(in_f, None) # skip original header
17
+ out_f.writelines(in_f)
18
+ tmp_path.replace(taxonomy_tsv)
19
+
20
+
21
+ def add_metadata(input_biom, taxonomy_tsv, output_biom):
22
+ cmd = ['biom', 'add-metadata',
23
+ '--sc-separated', 'taxonomy',
24
+ '-i', str(input_biom),
25
+ '--observation-metadata-fp', str(taxonomy_tsv),
26
+ '-o', str(output_biom)]
27
+ subprocess.run(cmd, check=True)
28
+
29
+
30
+ def convert_to_tsv(input_biom, taxonomy_tsv, output_tsv):
31
+ cmd = ['biom', 'convert',
32
+ '--to-tsv',
33
+ '--header-key', 'taxonomy',
34
+ '-i', str(input_biom),
35
+ '--observation-metadata-fp', str(taxonomy_tsv),
36
+ '-o', str(output_tsv)]
37
+ subprocess.run(cmd, check=True)
File without changes
@@ -0,0 +1,50 @@
1
+ """Standalone utility: reverse-complement every fastq file in a folder."""
2
+ import argparse
3
+ from multiprocessing import cpu_count
4
+ from pathlib import Path
5
+
6
+ from qiime2_its import env_checks, fastq_utils
7
+ from qiime2_its._version import __version__
8
+
9
+
10
+ def run(input_folder, output_folder, threads):
11
+ input_folder = Path(input_folder)
12
+ output_folder = Path(output_folder)
13
+
14
+ if not input_folder.exists() or not input_folder.is_dir():
15
+ raise ValueError('Input folder does not exist or is not a directory.')
16
+ # Not inside it either: the fastq search below is recursive, so a second
17
+ # run would find (and try to re-process) the first run's own output.
18
+ if output_folder.resolve() == input_folder.resolve() or input_folder.resolve() in output_folder.resolve().parents:
19
+ raise ValueError('Please choose an output folder different from (and not inside) the input folder.')
20
+ output_folder.mkdir(parents=True, exist_ok=True)
21
+
22
+ fastq_list = fastq_utils.list_fastq(input_folder)
23
+ if not fastq_list:
24
+ raise ValueError('No fastq files found in the input folder.')
25
+
26
+ print('Processing:')
27
+ fastq_utils.rc_fastq_parallel(fastq_list, output_folder, env_checks.clamp_cpu(threads))
28
+
29
+
30
+ def build_parser():
31
+ cpu = cpu_count()
32
+ parser = argparse.ArgumentParser(description='Reverse complement all entries in fastq file(s).')
33
+ parser.add_argument('-i', '--input', metavar='/input_folder/', required=True, type=str,
34
+ help='Input folder with fastq file(s), gzipped or not. Accepted extensions are '
35
+ '".fastq", ".fastq.gz", ".fq" and ".fq.gz". Searched recursively. Mandatory.')
36
+ parser.add_argument('-o', '--output', metavar='/modified_fastq/', required=True, type=str,
37
+ help='Output folder. Must be different from (and not inside) the input folder. Mandatory.')
38
+ parser.add_argument('-t', '--threads', metavar=str(cpu), default=cpu, type=int,
39
+ help=f'Number of CPUs. Default is {cpu}.')
40
+ parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
41
+ return parser
42
+
43
+
44
+ def main():
45
+ args = build_parser().parse_args()
46
+ run(args.input, args.output, args.threads)
47
+
48
+
49
+ if __name__ == '__main__':
50
+ main()