MetaPont 0.0.7__tar.gz → 0.0.8__tar.gz

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 (21) hide show
  1. {metapont-0.0.7/src/MetaPont.egg-info → metapont-0.0.8}/PKG-INFO +23 -1
  2. {metapont-0.0.7 → metapont-0.0.8}/README.md +22 -0
  3. {metapont-0.0.7 → metapont-0.0.8}/setup.cfg +3 -1
  4. metapont-0.0.8/src/MetaPont/Extract_Function_By_Taxa.py +130 -0
  5. metapont-0.0.8/src/MetaPont/constants.py +2 -0
  6. {metapont-0.0.7 → metapont-0.0.8/src/MetaPont.egg-info}/PKG-INFO +23 -1
  7. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont.egg-info/SOURCES.txt +1 -0
  8. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont.egg-info/entry_points.txt +2 -0
  9. metapont-0.0.7/src/MetaPont/constants.py +0 -2
  10. {metapont-0.0.7 → metapont-0.0.8}/LICENSE +0 -0
  11. {metapont-0.0.7 → metapont-0.0.8}/pyproject.toml +0 -0
  12. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/Extract_By_Function.py +0 -0
  13. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/Extract_By_Taxa.py +0 -0
  14. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/Extract_Reads_By_Function.py +0 -0
  15. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/Function_By_Taxa.py +0 -0
  16. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/__init__.py +0 -0
  17. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/kraken_emapper_readmap_combiner.py +0 -0
  18. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/lineage_matrix_collapse_v1.py +0 -0
  19. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont/lineage_matrix_collapse_v2.py +0 -0
  20. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont.egg-info/dependency_links.txt +0 -0
  21. {metapont-0.0.7 → metapont-0.0.8}/src/MetaPont.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: MetaPont
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: MetaPont - A tool to bridge the gap between the output of metagenomic tools and the analysis of the data
5
5
  Home-page: https://github.com/TheHuwsLab/MetaPont
6
6
  Author: Nicholas Dimonaco
@@ -116,6 +116,28 @@ PN0536_0004_S3_Final_Contig.tsv Lactobacillus 40076 0.404 0.002
116
116
 
117
117
  ---
118
118
 
119
+ # Extract-Function-By-Taxa:
120
+ ```bash
121
+ usage: Extract_Function_By_Taxa.py [-h] -d DIRECTORY -t TAXON -f FUNCTION -o
122
+ OUTPUT
123
+
124
+ MetaPont: Extract Reads Proportions for a Specific Taxon and Function
125
+
126
+ options:
127
+ -h, --help show this help message and exit
128
+ -d DIRECTORY, --directory DIRECTORY
129
+ Directory containing TSV files to analyse.
130
+ -t TAXON, --taxon TAXON
131
+ Target taxon to search for (e.g., 'g__Escherichia').
132
+ -f FUNCTION, --function FUNCTION
133
+ Target function to extract (e.g., 'EC:2.7.11.1').
134
+ -o OUTPUT, --output OUTPUT
135
+ Output file to save results.
136
+
137
+ ```
138
+
139
+
140
+
119
141
 
120
142
 
121
143
  ### Workflow - unfinished
@@ -101,6 +101,28 @@ PN0536_0004_S3_Final_Contig.tsv Lactobacillus 40076 0.404 0.002
101
101
 
102
102
  ---
103
103
 
104
+ # Extract-Function-By-Taxa:
105
+ ```bash
106
+ usage: Extract_Function_By_Taxa.py [-h] -d DIRECTORY -t TAXON -f FUNCTION -o
107
+ OUTPUT
108
+
109
+ MetaPont: Extract Reads Proportions for a Specific Taxon and Function
110
+
111
+ options:
112
+ -h, --help show this help message and exit
113
+ -d DIRECTORY, --directory DIRECTORY
114
+ Directory containing TSV files to analyse.
115
+ -t TAXON, --taxon TAXON
116
+ Target taxon to search for (e.g., 'g__Escherichia').
117
+ -f FUNCTION, --function FUNCTION
118
+ Target function to extract (e.g., 'EC:2.7.11.1').
119
+ -o OUTPUT, --output OUTPUT
120
+ Output file to save results.
121
+
122
+ ```
123
+
124
+
125
+
104
126
 
105
127
 
106
128
  ### Workflow - unfinished
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = MetaPont
3
- version = v0.0.7
3
+ version = v0.0.8
4
4
  author = Nicholas Dimonaco
5
5
  author_email = nicholas@dimonaco.co.uk
6
6
  description = MetaPont - A tool to bridge the gap between the output of metagenomic tools and the analysis of the data
@@ -31,6 +31,8 @@ console_scripts =
31
31
  extract-by-function = MetaPont.Extract_By_Function:main
32
32
  Extract-By-Taxa = MetaPont.Extract_By_Taxa:main
33
33
  extract-by-taxa = MetaPont.Extract_By_Taxa:main
34
+ Extract-Function-By-Taxa = MetaPont.Extract_Function_By_Taxa:main
35
+ extract-function-by-taxa = MetaPont.Extract_Function_By_Taxa:main
34
36
  Extract-Reads-By-Function = MetaPont.Extract_Reads_By_Function:main
35
37
  extract-reads-by-function = MetaPont.Extract_Reads_By_Function:main
36
38
  kraken-emapper-readmap-combine = kraken_emapper_readmap_combiner:main
@@ -0,0 +1,130 @@
1
+ import argparse
2
+ import os
3
+ import csv
4
+ import sys
5
+ from collections import defaultdict
6
+
7
+ # Needed to account for large CSV/TSV files
8
+ csv.field_size_limit(sys.maxsize)
9
+
10
+ def process_tsv_by_taxon_and_function(file_path, target_taxon, target_function):
11
+ """
12
+ Processes a TSV file to calculate the proportion of reads assigned to a taxon and function
13
+ relative to all reads assigned to that function across all taxa.
14
+
15
+ Parameters:
16
+ file_path (str): Path to the TSV file.
17
+ target_taxon (str): Taxon to search for in the lineage column.
18
+ target_function (str): Function to search for in the function columns.
19
+
20
+ Returns:
21
+ function_proportion (float): Proportion of reads assigned to the function within the taxon
22
+ relative to all reads assigned to the function.
23
+ reads_taxon_function (int): Total reads assigned to the taxon and function.
24
+ total_reads_function (int): Total reads assigned to the function across all taxa.
25
+ """
26
+ reads_taxon_function = 0 # Reads assigned to the specified taxon and function
27
+ total_reads_function = 0 # Total reads assigned to the function across all taxa
28
+
29
+ with open(file_path, "r") as tsv_file:
30
+ reader = csv.reader(tsv_file, delimiter="\t")
31
+ next(reader) # Skip the first row (sample name)
32
+ headers = next(reader) # Read headers from the second row
33
+
34
+ # Ensure required columns exist
35
+ try:
36
+ taxa_idx = headers.index("Lineage")
37
+ reads_idx = headers.index("Mapped_Reads")
38
+ except ValueError:
39
+ print(f"Error: Required columns not found in {file_path}. Skipping...")
40
+ return 0, 0, 0
41
+
42
+ # Process each row
43
+ for row in reader:
44
+ if len(row) < len(headers):
45
+ continue # Skip malformed rows
46
+
47
+ lineage = row[taxa_idx]
48
+ reads = int(row[reads_idx]) # Get the number of reads for this row
49
+
50
+ # Check if this row matches the specified function ID
51
+ for cell in row[6:]:
52
+ if cell and any(target_function in part for part in cell.replace(',', '|').split('|')):
53
+ if target_taxon in lineage:
54
+ # lineage = lineage.split("s__")[0] # .split("|")[0]
55
+ reads_taxon_function += reads
56
+ total_reads_function += reads
57
+ else:
58
+ total_reads_function += reads
59
+ break # Stop checking further functional columns for this row
60
+
61
+
62
+ # # Check if the function is present in this row
63
+ # function_present = any(target_function in cell for cell in row[6:] if cell)
64
+ #
65
+ # if function_present:
66
+ # total_reads_function += reads # Add to total function reads across all taxa
67
+ #
68
+ # # If the taxon is also present, add to taxon-specific function reads
69
+ # if target_taxon in lineage:
70
+ # reads_taxon_function += reads
71
+
72
+ # Compute the proportion
73
+ function_proportion = reads_taxon_function / total_reads_function if total_reads_function > 0 else 0
74
+
75
+ return function_proportion, reads_taxon_function, total_reads_function
76
+
77
+
78
+ def main():
79
+ parser = argparse.ArgumentParser(description='MetaPont: Extract Reads Proportions for a Specific Taxon and Function')
80
+ parser.add_argument(
81
+ "-d", "--directory", required=True,
82
+ help="Directory containing TSV files to analyse."
83
+ )
84
+ parser.add_argument(
85
+ "-t", "--taxon", required=True,
86
+ help="Target taxon to search for (e.g., 'g__Escherichia')."
87
+ )
88
+ parser.add_argument(
89
+ "-f", "--function", required=True,
90
+ help="Target function to extract (e.g., 'EC:2.7.11.1')."
91
+ )
92
+ parser.add_argument(
93
+ "-o", "--output", required=True,
94
+ help="Output file to save results."
95
+ )
96
+
97
+ options = parser.parse_args()
98
+ print(f"Running extraction for Taxon: {options.taxon} and Function: {options.function}")
99
+
100
+ input_path = os.path.abspath(options.directory)
101
+ output_path = os.path.abspath(options.output)
102
+
103
+ # Store results
104
+ results = []
105
+
106
+ # Process each TSV file in the directory
107
+ for file_name in os.listdir(input_path):
108
+ if file_name.endswith("_Final_Contig.tsv"):
109
+ file_path = os.path.join(options.directory, file_name)
110
+ print(f"Processing file: {file_name}")
111
+
112
+ function_proportion, reads_taxon_function, total_reads_function = process_tsv_by_taxon_and_function(
113
+ file_path, options.taxon, options.function
114
+ )
115
+
116
+ # Store the result
117
+ results.append((file_name.replace("_Final_Contig.tsv", ""), function_proportion, reads_taxon_function, total_reads_function))
118
+
119
+ # Write results to output file
120
+ with open(output_path, "w") as out:
121
+ out.write(f"Taxon: {options.taxon}, Function: {options.function}\n")
122
+ out.write("Sample\tFunction Proportion\tReads in Taxon & Function\tTotal Reads in Function\n")
123
+ for sample, function_proportion, reads_taxon_function, total_reads_function in results:
124
+ out.write(f"{sample}\t{function_proportion:.6f}\t{reads_taxon_function}\t{total_reads_function}\n")
125
+
126
+ print(f"Results saved to {options.output}")
127
+
128
+
129
+ if __name__ == "__main__":
130
+ main()
@@ -0,0 +1,2 @@
1
+ MetaPont_Version = 'v0.0.8'
2
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: MetaPont
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: MetaPont - A tool to bridge the gap between the output of metagenomic tools and the analysis of the data
5
5
  Home-page: https://github.com/TheHuwsLab/MetaPont
6
6
  Author: Nicholas Dimonaco
@@ -116,6 +116,28 @@ PN0536_0004_S3_Final_Contig.tsv Lactobacillus 40076 0.404 0.002
116
116
 
117
117
  ---
118
118
 
119
+ # Extract-Function-By-Taxa:
120
+ ```bash
121
+ usage: Extract_Function_By_Taxa.py [-h] -d DIRECTORY -t TAXON -f FUNCTION -o
122
+ OUTPUT
123
+
124
+ MetaPont: Extract Reads Proportions for a Specific Taxon and Function
125
+
126
+ options:
127
+ -h, --help show this help message and exit
128
+ -d DIRECTORY, --directory DIRECTORY
129
+ Directory containing TSV files to analyse.
130
+ -t TAXON, --taxon TAXON
131
+ Target taxon to search for (e.g., 'g__Escherichia').
132
+ -f FUNCTION, --function FUNCTION
133
+ Target function to extract (e.g., 'EC:2.7.11.1').
134
+ -o OUTPUT, --output OUTPUT
135
+ Output file to save results.
136
+
137
+ ```
138
+
139
+
140
+
119
141
 
120
142
 
121
143
  ### Workflow - unfinished
@@ -4,6 +4,7 @@ pyproject.toml
4
4
  setup.cfg
5
5
  src/MetaPont/Extract_By_Function.py
6
6
  src/MetaPont/Extract_By_Taxa.py
7
+ src/MetaPont/Extract_Function_By_Taxa.py
7
8
  src/MetaPont/Extract_Reads_By_Function.py
8
9
  src/MetaPont/Function_By_Taxa.py
9
10
  src/MetaPont/__init__.py
@@ -1,8 +1,10 @@
1
1
  [console_scripts]
2
2
  Extract-By-Function = MetaPont.Extract_By_Function:main
3
3
  Extract-By-Taxa = MetaPont.Extract_By_Taxa:main
4
+ Extract-Function-By-Taxa = MetaPont.Extract_Function_By_Taxa:main
4
5
  Extract-Reads-By-Function = MetaPont.Extract_Reads_By_Function:main
5
6
  extract-by-function = MetaPont.Extract_By_Function:main
6
7
  extract-by-taxa = MetaPont.Extract_By_Taxa:main
8
+ extract-function-by-taxa = MetaPont.Extract_Function_By_Taxa:main
7
9
  extract-reads-by-function = MetaPont.Extract_Reads_By_Function:main
8
10
  kraken-emapper-readmap-combine = kraken_emapper_readmap_combiner:main
@@ -1,2 +0,0 @@
1
- MetaPont_Version = 'v0.0.7'
2
-
File without changes
File without changes