eukcc 2.3.0__tar.gz → 2.3.1__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 (28) hide show
  1. {eukcc-2.3.0/eukcc.egg-info → eukcc-2.3.1}/PKG-INFO +1 -1
  2. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/__main__.py +3 -2
  3. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/constants.py +1 -0
  4. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/eukcc.py +16 -1
  5. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/refine.py +2 -2
  6. {eukcc-2.3.0 → eukcc-2.3.1/eukcc.egg-info}/PKG-INFO +1 -1
  7. {eukcc-2.3.0 → eukcc-2.3.1}/pyproject.toml +1 -1
  8. {eukcc-2.3.0 → eukcc-2.3.1}/scripts/binlinks.py +30 -25
  9. {eukcc-2.3.0 → eukcc-2.3.1}/scripts/filter_euk_bins.py +4 -40
  10. {eukcc-2.3.0 → eukcc-2.3.1}/LICENSE +0 -0
  11. {eukcc-2.3.0 → eukcc-2.3.1}/MANIFEST.in +0 -0
  12. {eukcc-2.3.0 → eukcc-2.3.1}/README.md +0 -0
  13. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/__init__.py +0 -0
  14. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/base.py +0 -0
  15. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/bin.py +0 -0
  16. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/exec.py +0 -0
  17. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/fasta.py +0 -0
  18. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/file.py +0 -0
  19. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/find_markerset.py +0 -0
  20. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/helper.py +0 -0
  21. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/set_define.py +0 -0
  22. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc/treehandler.py +0 -0
  23. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc.egg-info/SOURCES.txt +0 -0
  24. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc.egg-info/dependency_links.txt +0 -0
  25. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc.egg-info/entry_points.txt +0 -0
  26. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc.egg-info/requires.txt +0 -0
  27. {eukcc-2.3.0 → eukcc-2.3.1}/eukcc.egg-info/top_level.txt +0 -0
  28. {eukcc-2.3.0 → eukcc-2.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eukcc
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Check eukaryotic genomes or MAGs for completeness and contamination
5
5
  Author-email: Paul Saary <eukcc@paulsaary.de>, MGnify team <metagenomics-help@ebi.ac.uk>
6
6
  License: GPLv3
@@ -220,9 +220,10 @@ def run_eukcc(args):
220
220
  )
221
221
  @click.option(
222
222
  "--use_placement",
223
- type=str,
223
+ type=click.Path(exists=True, dir_okay=False),
224
224
  default=None,
225
- help="Path to previous result file, to use exact same marker gene set",
225
+ help="Marker gene set of a previous run, to use the exact same set: savestate.json.gz in the output "
226
+ "folder of eukcc single, or <name>.json.gz of eukcc define_set",
226
227
  )
227
228
  @click.option(
228
229
  "--set_number_species",
@@ -1,5 +1,6 @@
1
1
  # extensions of the bins used by eukcc folder, plain or gzip compressed
2
2
  FASTA_EXTENSIONS = (".fa", ".fna", ".fasta")
3
+ FASTA_SUFFIXES = FASTA_EXTENSIONS + tuple(f"{ext}.gz" for ext in FASTA_EXTENSIONS)
3
4
 
4
5
  # extension of the merged bins written by eukcc folder
5
6
  DEFAULT_EXTENSION = ".fa"
@@ -237,6 +237,16 @@ class eukcc:
237
237
  # load the old info
238
238
  old_state.load_state(self.state["use_placement"])
239
239
  self.state["marker_set"] = old_state["marker_set"]
240
+ # the placement tree was in the workdir of the previous run, so its lineage is reused;
241
+ # a set from define_set has no lineage
242
+ for key in ("lng", "lng_names"):
243
+ if old_state.get(key) is not None:
244
+ self.state[key] = old_state[key]
245
+ # the profiles of the set are only in the database of the clade it was defined in
246
+ if old_state["clade"] is not None and old_state["clade"] != self.state["clade"]:
247
+ logging.info(f"Using the {old_state['clade']} database of the loaded set")
248
+ self.state["clade"] = old_state["clade"]
249
+ self.state["dbinfo"] = self.load_db(self.state["db"], clade=self.state["clade"])
240
250
  logging.info(
241
251
  f"Loaded precomputed set with {len(self.state['marker_set']['profiles'])} profiles"
242
252
  )
@@ -245,7 +255,8 @@ class eukcc:
245
255
  # figure placement
246
256
  if self.placement() is None:
247
257
  return None
248
- if self.state["ignore_tree"] and self.state["comparison_genomes"] is not None:
258
+ # the set is defined on the genomes, so there is no placement in the tree to use
259
+ if self.state["comparison_genomes"] is not None:
249
260
  logging.info(
250
261
  "Will create custom marker set based on input genomes/proteomes"
251
262
  )
@@ -379,6 +390,10 @@ class eukcc:
379
390
 
380
391
  def add_taxid(self):
381
392
  pl = self.state["placement"]
393
+ # with --use_placement the lineage of the loaded set is kept, with --genomes there is none
394
+ if pl is None or "placements" not in pl.keys():
395
+ logging.debug("No placements in the tree, the lineage is not inferred")
396
+ return
382
397
  tree = pl["tog"]
383
398
  if "marker_set" in self.state.keys():
384
399
  places = self.state["marker_set"]["covered_pl"]
@@ -7,7 +7,7 @@ from collections import defaultdict
7
7
  from eukcc.eukcc import eukcc, eukcc_state
8
8
  from eukcc.fasta import merge_fasta, valid_fastas
9
9
  from eukcc import __version__
10
- from eukcc.constants import FASTA_EXTENSIONS, DEFAULT_EXTENSION
10
+ from eukcc.constants import FASTA_SUFFIXES, DEFAULT_EXTENSION
11
11
  from eukcc.fasta import Fasta
12
12
  from eukcc.bin import bin, merge_bins
13
13
  from eukcc.file import file
@@ -62,7 +62,7 @@ def eukcc_folder(args):
62
62
  state["input_bins"] = valid_fastas(
63
63
  _path
64
64
  for _path in glob.glob(os.path.join(state["binfolder"], "*"))
65
- if _path.lower().endswith(FASTA_EXTENSIONS + tuple(f"{ext}.gz" for ext in FASTA_EXTENSIONS))
65
+ if _path.lower().endswith(FASTA_SUFFIXES)
66
66
  )
67
67
  logging.info(f"Found {len(state['input_bins'])} bins")
68
68
  if len(state["input_bins"]) == 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eukcc
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Check eukaryotic genomes or MAGs for completeness and contamination
5
5
  Author-email: Paul Saary <eukcc@paulsaary.de>, MGnify team <metagenomics-help@ebi.ac.uk>
6
6
  License: GPLv3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "eukcc"
3
- version = "2.3.0"
3
+ version = "2.3.1"
4
4
  readme = "README.md"
5
5
  license = {text = "GPLv3"}
6
6
  authors = [
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env python3
2
2
  import pysam
3
- from Bio import SeqIO
4
3
  from collections import defaultdict
5
4
  import os
6
5
  import argparse
7
6
  import logging
8
7
  import csv
8
+ from eukcc.constants import FASTA_SUFFIXES
9
+ from eukcc.fasta import Fasta
9
10
 
10
11
 
11
12
  def is_in(read, contig_map, within=1000):
@@ -35,30 +36,28 @@ def keep_read(read, contig_map, within=1000, min_ANI=98, min_cov=0):
35
36
  return False
36
37
 
37
38
 
38
- def contig_map(bindir, suffix=".fa"):
39
+ def bin_files(bindir):
40
+ """
41
+ the bins used by eukcc folder, so the bin names match its own
42
+ """
43
+ return [f for f in os.listdir(bindir) if f.lower().endswith(FASTA_SUFFIXES)]
44
+
45
+
46
+ def contig_map(bindir):
39
47
  m = {}
40
- for f in os.listdir(bindir):
41
- if f.endswith(suffix) is False:
42
- continue
43
- path = os.path.join(bindir, f)
44
- with open(path, "r") as handle:
45
- for record in SeqIO.parse(handle, "fasta"):
46
- m[record.name] = len(record.seq)
48
+ for f in bin_files(bindir):
49
+ for record in Fasta(os.path.join(bindir, f)):
50
+ m[record.name] = len(record.seq)
47
51
  return m
48
52
 
49
53
 
50
- def bin_map(bindir, suffix=".fa"):
54
+ def bin_map(bindir):
51
55
  contigs = defaultdict(str)
52
56
  contigs_per_bin = defaultdict(int)
53
- for f in os.listdir(bindir):
54
- if f.endswith(suffix) is False:
55
- continue
56
- path = os.path.join(bindir, f)
57
- binname = os.path.basename(f)
58
- with open(path, "r") as handle:
59
- for record in SeqIO.parse(handle, "fasta"):
60
- contigs[record.name] = binname
61
- contigs_per_bin[binname] += 1
57
+ for binname in bin_files(bindir):
58
+ for record in Fasta(os.path.join(bindir, binname)):
59
+ contigs[record.name] = binname
60
+ contigs_per_bin[binname] += 1
62
61
  return contigs, contigs_per_bin
63
62
 
64
63
 
@@ -107,14 +106,20 @@ def main():
107
106
  # set arguments
108
107
  # arguments are passed to classes
109
108
  parser = argparse.ArgumentParser(
110
- description="Evaluate completeness and contamination of a MAG."
109
+ description="Count the read pairs linking bins, for eukcc folder --links."
110
+ )
111
+ parser.add_argument(
112
+ "--binfolder",
113
+ type=str,
114
+ required=True,
115
+ help="Folder with the bins: .fa, .fna or .fasta files, optionally gzip compressed",
111
116
  )
112
- parser.add_argument("bindir", type=str, help="Run script on these bins")
113
117
  parser.add_argument(
114
- "bam",
118
+ "--alignment",
115
119
  type=str,
116
- help="Bam file(s) with reads aligned against all contigs making up the bins",
120
+ required=True,
117
121
  nargs="+",
122
+ help="Bam file(s) with paired reads aligned against all contigs making up the bins",
118
123
  )
119
124
  parser.add_argument(
120
125
  "--out",
@@ -170,7 +175,7 @@ def main():
170
175
  level=logLevel,
171
176
  )
172
177
 
173
- bindir = args.bindir
178
+ bindir = args.binfolder
174
179
 
175
180
  cm = contig_map(bindir)
176
181
  bm, contigs_per_bin = bin_map(bindir)
@@ -180,7 +185,7 @@ def main():
180
185
  bin_table = defaultdict(lambda: defaultdict(int))
181
186
 
182
187
  # iterate all bam files
183
- for bamf in args.bam:
188
+ for bamf in args.alignment:
184
189
  link_table = read_bam_file(bamf, link_table, cm, args.within, args.ANI)
185
190
 
186
191
  logging.debug(f"Created link table with {len(link_table)} entries")
@@ -24,43 +24,7 @@ import tempfile
24
24
  import gzip
25
25
  from multiprocessing import Pool
26
26
  from functools import partial
27
-
28
-
29
- # backup fasta handler, so we can use readonly directories
30
- class fa_class:
31
- def __init__(self, seq, name, long_name):
32
- self.seq = seq
33
- self.name = name
34
- self.long_name = long_name
35
-
36
- def __str__(self):
37
- return self.seq
38
-
39
- def __len__(self):
40
- return len(self.seq)
41
-
42
-
43
- def Fasta(path):
44
- """
45
- Iterator for fasta files
46
- """
47
- entry = False
48
-
49
- with open(path) as fin:
50
- for line in fin:
51
- if line.startswith(">"):
52
- if entry is not False:
53
- entry.seq = "".join(entry.seq)
54
- yield entry
55
- # define new entry
56
- long_name = line.strip()[1:]
57
- name = long_name.split()[0]
58
- entry = fa_class([], name, long_name)
59
- else:
60
- entry.seq.append(line.strip())
61
- # yield last one
62
- entry.seq = "".join(entry.seq)
63
- yield entry
27
+ from eukcc.fasta import Fasta
64
28
 
65
29
 
66
30
  def gunzip(path, tmp_dir):
@@ -190,10 +154,10 @@ def evaluate_bin(path, args):
190
154
  eukfile = os.path.join(tmp_dir, "euks.fna")
191
155
  bacfile = os.path.join(tmp_dir, "bacs.fna")
192
156
  # EukRep can not deal with Gzipped Fasta files, so we unzip it in case it is a Gzip file
193
- path = gunzip(path, tmp_dir)
157
+ eukrep_path = gunzip(path, tmp_dir)
194
158
  # Launching EukRep
195
- logging.debug(f"Starting EukRep on {path}")
196
- eukrep_result = EukRep(path, eukfile, bacfile, minl=args.minl)
159
+ logging.debug(f"Starting EukRep on {eukrep_path}")
160
+ eukrep_result = EukRep(eukrep_path, eukfile, bacfile, minl=args.minl)
197
161
  eukrep_result.run()
198
162
  b = bin(path, eukrep_result)
199
163
  b.stats()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes