Skip to content

Commit

Permalink
happy pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
bkille committed Jan 19, 2024
1 parent feb7a20 commit 2f81014
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 81 deletions.
11 changes: 1 addition & 10 deletions extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@
from Bio.Seq import Seq
from Bio.SeqIO import SeqRecord
from Bio.Align import MultipleSeqAlignment
from glob import glob
import logging
import tempfile
from pathlib import Path
import re
import subprocess
from collections import namedtuple, defaultdict, Counter
import bisect
import os
from Bio.Align import substitution_matrices
from itertools import product, combinations
import numpy as np
from Bio.AlignIO.MafIO import MafWriter, MafIterator
from Bio.AlignIO.MauveIO import MauveWriter, MauveIterator
from logger import logger, TqdmToLogger, MIN_TQDM_INTERVAL
from tqdm import tqdm
import time
from logger import logger, TqdmToLogger, MIN_TQDM_INTERVAL
import spoa
#%%

Expand Down
7 changes: 2 additions & 5 deletions parsnp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
'''

import os, sys, string, getopt, random,subprocess, time,operator, math, datetime,numpy #pysam
import os, sys, string, random, subprocess, time, operator, math, datetime, numpy #pysam
from collections import defaultdict
import csv
import shutil
import shlex
from tempfile import TemporaryDirectory
import re
import logging
from logger import logger, TqdmToLogger, MIN_TQDM_INTERVAL
import multiprocessing
import argparse
import signal
import inspect
from multiprocessing import Pool
from Bio import SeqIO
from glob import glob
Expand Down Expand Up @@ -149,7 +146,7 @@ def run_phipack(query,seqlen,workingdir):
currdir = os.getcwd()
os.chdir(workingdir)
command = "Profile -o -v -n %d -w 100 -m 100 -f %s > %s.out"%(seqlen,query,query)
run_command(command,1, prepend_time=True)
run_command(command, 1)
os.chdir(currdir)

def run_fasttree(query,workingdir,recombination_sites):
Expand Down
66 changes: 0 additions & 66 deletions partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,69 +729,3 @@ def merge_xmfas(
xmfa_out_handle.write(tx.read())


if __name__ == "__main__":
args = parse_args()
os.makedirs(args.output_dir, exist_ok=True)

query_files = list()
for arg_path in args.sequences:
if arg_path.endswith(".txt"):
with open(arg_path) as input_list_handle:
for line in input_list_handle:
query_files.append(line.strip())
elif any(arg_path.endswith(suff) for suff in FASTA_SUFFIX_LIST):
query_files.append(arg_path)
elif os.path.isdir(arg_path):
for f in os.listdir(arg_path):
if any(f.endswith(suff) for suff in FASTA_SUFFIX_LIST):
query_files.append(f"{arg_path}/{f}")

full_query_list_path = f"{args.output_dir}/input-list.txt"
with open(full_query_list_path, 'w') as input_list_handle:
for qf in query_files:
input_list_handle.write(qf + "\n")

partition_output_dir = f"{args.output_dir}/partition"
partition_list_dir = f"{partition_output_dir}/input-lists"
os.makedirs(partition_list_dir, exist_ok=True)
run_command(f"split -l {args.partition_size} -a 5 --additional-suffix '.txt' {full_query_list_path} {partition_list_dir}/{CHUNK_PREFIX}-")

chunk_label_parser = re.compile(f'{CHUNK_PREFIX}-(.*).txt')
chunk_labels = []
for partition_list_file in os.listdir(partition_list_dir):
chunk_labels.append(chunk_label_parser.search(partition_list_file).groups()[0])

parsnp_commands = []
for cl in chunk_labels:
chunk_output_dir = f"{partition_output_dir}/{CHUNK_PREFIX}-{cl}-out"
os.makedirs(chunk_output_dir, exist_ok=True)
chunk_command = f"./parsnp -d {partition_list_dir}/{CHUNK_PREFIX}-{cl}.txt -r {args.reference} -o {chunk_output_dir} "
chunk_command += args.parsnp_flags
chunk_command += f" > {chunk_output_dir}/parsnp.stdout 2> {chunk_output_dir}/parsnp.stderr"
parsnp_commands.append(chunk_command)

good_chunks = set(chunk_labels)
run_command_nocheck = partial(run_command, check=False)
with Pool(args.threads) as pool:
return_codes = tqdm(pool.imap(run_command_nocheck, parsnp_commands, chunksize=1), total=len(parsnp_commands))
for cl, rc in zip(chunk_labels, return_codes):
if rc != 0:
logger.error("Partition {cl} failed...")
good_chunks.remove(cl)

chunk_labels = list(good_chunks)

logger.info("Computing intersection of all partition LCBs...")
chunk_to_intvervaldict = get_chunked_intervals(partition_output_dir, chunk_labels)
intersected_interval_dict = get_intersected_intervals(chunk_to_intvervaldict)

logger.info("Trimming partitioned XMFAs back to intersected intervals...")
num_clusters = trim_xmfas(partition_output_dir, chunk_labels, intersected_interval_dict, args.threads)

os.makedirs(f"{args.output_dir}/merged-out/", exist_ok=True)
xmfa_out_f = f"{args.output_dir}/merged-out/parsnp.xmfa"

logger.info(f"Merging trimmed XMFA files into a single XMFA at {xmfa_out_f}")
merge_xmfas(partition_output_dir, chunk_labels, xmfa_out_f, num_clusters, args.threads)


0 comments on commit 2f81014

Please sign in to comment.