Commit c67330fc authored by Ivan Vanat's avatar Ivan Vanat
Browse files

modules: added mite filtering; delete tmp files at the end

parent 9328f294
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
import os
import click
import glob
import shutil
from concurrent import futures
from datetime import datetime
from subprocess import CalledProcessError
@@ -66,6 +67,8 @@ def main(input_fasta: str, sketch: bool, format: str, output_fasta_offset: int,
        process_sequence(sequence, sketcher, sketch, format, output_fasta_offset, output_folder,
                         initial_threshold, threshold_multiplier, number_of_errors,
                         dependency_resolver)

    shutil.rmtree("/tmp/nested/")
    end_time = datetime.now()
    print('Total time: {}'.format(end_time - start_time))
    print('Number of errors: {}'.format(number_of_errors[0]))
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ from nested.output.output_objects.base_output_object import BaseOutputObject

class ToolInterface:
    def __init__(self, sequence: SeqRecord):
        self.output_object: Type[BaseOutputObject]
        self.output_object: BaseOutputObject = None
        self.sequence: Seq = sequence.seq
        self.seqId: str = sequence.id

+21 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ from nested.core.tool_interface import ToolInterface
from nested.entities.mite import Mite
from nested.output.output_objects.mite_output_object import MiteOutputObject
from nested.config.config import config, args_dict_to_list
from nested.utils import intervals


class MiteFinder(ToolInterface):
@@ -37,8 +38,10 @@ class MiteFinder(ToolInterface):

        stdout, stderr = process.communicate()

        mites = self._get_mites()
        candidates = self._get_mites()
        mites = self._filter_candidates(candidates)

        mites.sort(key=lambda e: e.location[0], reverse=True)
        self.output_object = MiteOutputObject(self.seqId, sequence, mites)

        return mites
@@ -55,6 +58,21 @@ class MiteFinder(ToolInterface):
            element = Mite(location, score, tir_left, tir_right)
            result.append(element)

        result.sort(key=lambda e: e.location[0], reverse=True)

        return result

    def _filter_candidates(self, candidates: List[Mite]) -> List[Mite]:
        mites = []
        candidates.sort(key=lambda e: e.score, reverse=True)

        for candidate in candidates:
            add = True
            for mite in mites:
                if candidate.location == mite.location:
                    continue
                if intervals.intersect(mite.location, candidate.location):
                    add = False
                    break
            if add:
                mites.append(candidate)

        return mites