Skip to content

Commit

Permalink
fixed parsing problem of fastANI
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzbuck committed Jun 21, 2021
1 parent 044484c commit d3092d9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mOTUlizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if os.path.exists(".git"):
label = subprocess.check_output(["git", "describe", "--tags"]).strip().decode()
else:
label = "0.2.3"
label = "0.2.4"

os.chdir(cwd)

Expand Down
6 changes: 3 additions & 3 deletions mOTUlizer/bin/mOTUlize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import multiprocessing
from mOTUlizer.classes import *
from mOTUlizer.utils import *
from mOTUlizer.config import FASTA_EXTS
from mOTUlizer.classes.MetaBin import MetaBin
from mOTUlizer.classes.mOTU import mOTU
from mOTUlizer import __version__
Expand All @@ -28,7 +29,6 @@
"""

fasta_exts = [".fna", ".fa", ".fasta", ".fna", ".ffn"]

def motulize(args):
#parse and check your amino-acid files
Expand Down Expand Up @@ -73,8 +73,8 @@ def motulize(args):
for l in handle:
if "query" not in l:
ll = l.split("\t")
g1 = ".".join(os.path.basename(ll[0]).split(".")[:-1]) if any([ll[0].endswith(ext) for ext in fasta_exts]) else ll[0]
g2 = ".".join(os.path.basename(ll[1]).split(".")[:-1]) if any([ll[1].endswith(ext) for ext in fasta_exts]) else ll[1]
g1 = ".".join(os.path.basename(ll[0]).split(".")[:-1]) if any([ll[0].endswith(ext) for ext in FASTA_EXTS]) else ll[0]
g2 = ".".join(os.path.basename(ll[1]).split(".")[:-1]) if any([ll[1].endswith(ext) for ext in FASTA_EXTS]) else ll[1]
dist = float(ll[2])
dist_dict[(g1,g2)] = dist
else :
Expand Down
6 changes: 5 additions & 1 deletion mOTUlizer/classes/MetaBin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from subprocess import Popen, PIPE, call
import os
import shutil
from mOTUlizer.config import FASTA_EXTS

class MetaBin:
def __repr__(self) :
Expand Down Expand Up @@ -81,7 +82,10 @@ def get_anis(cls, bins, outfile = None, method = "fastANI", block_size = 500, th
os.remove(b1_tfile)
with open(fastani_file) as handle:
handle.readline()
out_dists = {(l.split()[0], l.strip().split()[1]) : float(l.split()[2]) for l in handle}
out_dists = {(os.path.basename(l.split()[0]), os.path.basename(l.strip().split()[1])) : float(l.split()[2]) for l in handle}
out_dists = {( ".".join(k[0].split(".")[:-1]) if any([k[0].endswith(ext) for ext in FASTA_EXTS]) else k[0],
".".join(k[1].split(".")[:-1]) if any([k[1].endswith(ext) for ext in FASTA_EXTS]) else k[1] ): v
for k,v in out_dists.items() }
# tfile = lambda k : ".".join(k.split(".")[:-1]) if (k.endswith(".fna") or k.endswith(".fa") or k.endswith(".fasta") or k.endswith(".fna") or k.endswith(".ffn")) else k
# out_dists = {(tfile(k[0]),tfile(k[1])) : v for k,v in out_dists.items()}
if outfile is None:
Expand Down
1 change: 1 addition & 0 deletions mOTUlizer/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MIN_PROB = -1000 # log10 of prob of impossible event
DB_FOLDER = "/home/moritz/dbs/"
FASTA_EXTS = [".fna", ".fa", ".fasta", ".fna", ".ffn"]

0 comments on commit d3092d9

Please sign in to comment.