yamcot 1.0.0__cp310-cp310-win_amd64.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.
yamcot/execute.py ADDED
@@ -0,0 +1,97 @@
1
+ import logging
2
+ import os
3
+ import subprocess
4
+ from io import StringIO
5
+
6
+ import pandas as pd
7
+
8
+ # Import the C++ extension
9
+ from yamcot._core import run_motali_cpp
10
+
11
+
12
+ def run_prosampler(foreground_path, background_path, output_dir, motif_length, number_of_motifs):
13
+ if not os.path.exists(output_dir):
14
+ os.makedirs(output_dir)
15
+ args = [
16
+ "ProSampler",
17
+ "-i",
18
+ foreground_path,
19
+ "-b",
20
+ background_path,
21
+ "-k",
22
+ f"{motif_length}",
23
+ "-l",
24
+ "0",
25
+ "-m",
26
+ f"{number_of_motifs}",
27
+ "-z",
28
+ "0",
29
+ "-t",
30
+ "4",
31
+ "-w",
32
+ "2",
33
+ "-o",
34
+ f"{output_dir}/motifs",
35
+ ]
36
+ logger = logging.getLogger(__name__)
37
+ logger.debug(" ".join(args))
38
+ stdout = subprocess.run(args, shell=False, capture_output=True)
39
+ logger.debug(stdout)
40
+ return 0
41
+
42
+
43
+ def run_tomtom(motifs_1, motifs_2):
44
+ args = ["tomtom", motifs_1, motifs_2, "-thresh", "1", "-text"]
45
+
46
+ logger = logging.getLogger(__name__)
47
+ logger.debug(" ".join(args))
48
+
49
+ stdout = subprocess.run(args, shell=False, capture_output=True)
50
+
51
+ logger.debug(stdout)
52
+
53
+ table = pd.read_csv(StringIO(stdout.stdout.decode()), sep="\t", comment="#")
54
+ table = table[["Query_ID", "Target_ID", "p-value", "Overlap", "Orientation"]]
55
+ table.columns = ["query", "target", "p-value", "overlap", "orientation"]
56
+ table = table.reset_index(drop=True)
57
+
58
+ return table.iloc[0].to_dict()
59
+
60
+
61
+ def run_motali(
62
+ fasta_path, motif_1, motif_2, type_1, type_2, dist_1, dist_2, overlap_path, all_path, prc_path, hist_path, sta_path
63
+ ):
64
+ """
65
+ Run motali comparison using either the C++ extension or subprocess fallback.
66
+ """
67
+ logger = logging.getLogger(__name__)
68
+
69
+ # Use the C++ extension directly
70
+ result = run_motali_cpp(
71
+ file_fasta=fasta_path,
72
+ type_model_1=type_1,
73
+ type_model_2=type_2,
74
+ file_model_1=motif_1,
75
+ file_model_2=motif_2,
76
+ file_table_1=dist_1,
77
+ file_table_2=dist_2,
78
+ shift=50, # Default shift value
79
+ threshold=0.002, # Default threshold
80
+ file_hist=hist_path,
81
+ yes_out_hist=1,
82
+ file_prc=prc_path,
83
+ yes_out_prc=1,
84
+ file_short_over=overlap_path,
85
+ file_short_all=all_path,
86
+ file_sta_long=sta_path,
87
+ )
88
+
89
+ if result != 0:
90
+ logger.error(f"C++ function returned error code: {result}")
91
+ raise RuntimeError(f"C++ function failed with error code: {result}")
92
+
93
+ # Read the result from the output file
94
+ with open(all_path) as file:
95
+ score = float(file.readline().strip())
96
+
97
+ return score