sensityper 1.0.1__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.
Files changed (29) hide show
  1. sensityper/__init__.py +0 -0
  2. sensityper/ariba_batch_v0.2.py +97 -0
  3. sensityper/html_generator.py +1649 -0
  4. sensityper/resources/ariba_db/00.info.txt +3 -0
  5. sensityper/resources/ariba_db/00.version_info.txt +27 -0
  6. sensityper/resources/ariba_db/01.filter.check_genes.log +922 -0
  7. sensityper/resources/ariba_db/01.filter.check_metadata.log +0 -0
  8. sensityper/resources/ariba_db/01.filter.check_metadata.tsv +35440 -0
  9. sensityper/resources/ariba_db/01.filter.check_noncoding.log +0 -0
  10. sensityper/resources/ariba_db/02.cdhit.all.fa +28743 -0
  11. sensityper/resources/ariba_db/02.cdhit.clusters.pickle +0 -0
  12. sensityper/resources/ariba_db/02.cdhit.clusters.tsv +14 -0
  13. sensityper/resources/ariba_db/02.cdhit.gene.fa +363 -0
  14. sensityper/resources/ariba_db/02.cdhit.gene.varonly.fa +28303 -0
  15. sensityper/resources/ariba_db/02.cdhit.noncoding.fa +0 -0
  16. sensityper/resources/ariba_db/02.cdhit.noncoding.varonly.fa +77 -0
  17. sensityper/resources/examples/example_data.tab +20 -0
  18. sensityper/resources/examples/out_metrics.tsv +122 -0
  19. sensityper/resources/sensitype.db +106 -0
  20. sensityper/resources/sensitype.penA.db +918 -0
  21. sensityper/sensiscript.py +532 -0
  22. sensityper/sensityper.py +919 -0
  23. sensityper/sensityping_metrics.py +944 -0
  24. sensityper-1.0.1.dist-info/METADATA +465 -0
  25. sensityper-1.0.1.dist-info/RECORD +29 -0
  26. sensityper-1.0.1.dist-info/WHEEL +5 -0
  27. sensityper-1.0.1.dist-info/entry_points.txt +3 -0
  28. sensityper-1.0.1.dist-info/licenses/LICENSE +674 -0
  29. sensityper-1.0.1.dist-info/top_level.txt +1 -0
sensityper/__init__.py ADDED
File without changes
@@ -0,0 +1,97 @@
1
+ import os
2
+ import re
3
+ import argparse
4
+ import subprocess
5
+
6
+ def run_ariba(input_dirs, output_dir, db_path, threads):
7
+ # Split the input directories by comma
8
+ dirs = input_dirs.split(',')
9
+
10
+ # Define possible forward and reverse suffix patterns
11
+ forward_suffixes = ['_1.fastq.gz', '_R1.fastq.gz', '_R1_001.fastq.gz']
12
+ reverse_suffixes = ['_2.fastq.gz', '_R2.fastq.gz', '_R2_001.fastq.gz']
13
+
14
+ # Loop through each directory
15
+ for d in dirs:
16
+ # Get all the forward read files in the directory based on possible suffixes
17
+ forward_files = [f for f in os.listdir(d) for suffix in forward_suffixes if f.endswith(suffix)]
18
+
19
+ for f in forward_files:
20
+ # Extract the sample name based on the detected suffix
21
+ for suffix in forward_suffixes:
22
+ if f.endswith(suffix):
23
+ sample_name = f.rsplit(suffix, 1)[0]
24
+ reverse_suffix = reverse_suffixes[forward_suffixes.index(suffix)]
25
+ break
26
+
27
+ # Construct the reverse read file name
28
+ reverse_file = os.path.join(d, sample_name + reverse_suffix)
29
+
30
+ # Construct each output folder inside the main output directory
31
+ output_folder = os.path.join(output_dir, sample_name + '_ARIBA')
32
+
33
+ # Check if the output folder already exists
34
+ if os.path.exists(output_folder):
35
+ print(f"Skipping {output_folder} as it already exists.")
36
+ #continue
37
+
38
+ # Run the ARIBA command with the specified number of threads
39
+ cmd = [
40
+ 'ariba', 'run', '--verbose', '--threads', str(threads), db_path,
41
+ os.path.join(d, f), reverse_file, output_folder
42
+ ]
43
+ subprocess.run(cmd)
44
+
45
+ # Modify the report.tsv file to include the penA.insD345 if detected
46
+ report_file = os.path.join(output_folder, 'report.tsv')
47
+ new_report_file = os.path.join(output_folder, 'report_complete.tsv')
48
+ with open(report_file, 'r') as infile, open(new_report_file, 'w') as outfile:
49
+ for line in infile:
50
+ if 'D147_T148insT' in line:
51
+ pattern = r"0\t\.\tp\t\.\t0\tD147_T148insT"
52
+ replacement = "1\tSNP\tp\tD147_T148insT\t1\tD147_T148insT"
53
+ modified_line = re.sub(pattern, replacement, line)
54
+ elif 'R146_D147insR' in line:
55
+ pattern = r"0\t\.\tp\t\.\t0\tR146_D147insR"
56
+ replacement = "1\tSNP\tp\tR146_D147insR\t1\tR146_D147insR"
57
+ modified_line = re.sub(pattern, replacement, line)
58
+ else:
59
+ modified_line = line
60
+ outfile.write(modified_line)
61
+
62
+ # Generate filenames.txt for the ARIBA summary including absolute paths
63
+ #with open('filenames.txt', 'w') as f:
64
+ # report_files = [os.path.join(output_dir, d, 'report_complete.tsv') for d in os.listdir(output_dir) if d.endswith('_ARIBA')]
65
+ # #report_names = [d.replace('_ARIBA', '') for d in os.listdir(output_dir) if d.endswith('_ARIBA')]
66
+ # for count, report_file in enumerate(report_files):
67
+ # #print(report_file)
68
+ # f.write(report_file+'\n')
69
+
70
+ # Execute ARIBA summary
71
+ #cmd = [
72
+ # 'ariba', 'summary', 'ariba_summary', '-f', 'filenames.txt', '--cluster_cols',
73
+ # 'assembled,ref_seq,pct_id', '--col_filter', 'n',
74
+ # '--row_filter', 'n', '--no_tree', '--v_groups', '--known_variants'
75
+ #]
76
+ #subprocess.run(cmd)
77
+
78
+
79
+ if __name__ == "__main__":
80
+ parser = argparse.ArgumentParser(description="Run ARIBA on multiple directories.")
81
+ parser.add_argument('-d', '--input_dirs', required=True, help="Comma-separated list of input directories containing FASTQ files.")
82
+ parser.add_argument('-o', '--output_dir', required=True, help="Output directory for ARIBA results.")
83
+ parser.add_argument('--db_path', required=True, help="Path to the ARIBA database.")
84
+ parser.add_argument('-t', '--threads', type=int, default=1, help="Number of threads for ARIBA run.")
85
+
86
+ args = parser.parse_args()
87
+
88
+ # Construct the output folder
89
+ output_dir = args.output_dir
90
+ if not os.path.exists(output_dir):
91
+ create_folder = ['mkdir', output_dir]
92
+ subprocess.run(create_folder)
93
+ output_dir = os.path.abspath(output_dir)
94
+ print(output_dir)
95
+
96
+ run_ariba(args.input_dirs, output_dir, args.db_path, args.threads)
97
+