tssv.py 22.9 KB
Newer Older
1
#!/usr/bin/env python
2 3

#
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
4
# Copyright (C) 2019 Jerry Hoogenboom
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#
# This file is part of FDSTools, data analysis tools for Next
# Generation Sequencing of forensic DNA markers.
#
# FDSTools is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# FDSTools is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FDSTools.  If not, see <http://www.gnu.org/licenses/>.
#

23 24 25 26
"""
Link raw reads in a FastA or FastQ file to markers and count the number
of reads for each unique sequence.

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
Scans a FastA or FastQ file, finding the sequences from the 'flanks'
section in the provided library file.  Each time a pair of flanks is
found, that sequence read is linked to the corresponding marker and the
portion of the sequence between the flanks is extracted.  The number of
times each such extracted sequence was encountered is counted, along
with the orientation (strand) in which it was found in the input file.
The output is a list of unique sequences found for each marker including
the corresponding counts.

By default, a small number of mismatches is allowed when aligning the
flanks to the reads.  This can be controlled with the -m/--mismatches
option.  Furthermore, when the portion of the sequence to which a flank
aligns is completely written in lowercase letters in the input file,
that match is discarded.  This way, FDSTools works well together with
the paired-end read merging tool FLASH, version 1.2.11/lo, which
(optionally) writes the non-overlapping portion of the reads in
lowercase [1].  Together, this ensures repetitive sequences (such as
STRs) are not truncated when the paired-end reads are merged.

The sequences thus obtained are subsequently filtered in three ways.
First, the 'expected_allele_length' section in the library file may be
used to specify hard limits on the acceptable sequence length for each
marker.  Any unexpectedly short or long sequence is removed.  Second,
any sequence with an ambiguous base (i.e., not A, C, G, or T) is
removed.  Finally, the -a/--minimum option can be used to filter out
sequences that have been seen only rarely.  When the
-A/--aggregate-filtered option is given, all filtered sequences of each
marker are aggregated and reported as 'Other sequences'.

This tool is an evolution of the original TSSV program [2].

References:
[1] https://github.com/Jerrythafast/FLASH-lowercase-overhang
[2] https://github.com/jfjlaros/tssv
61 62 63
"""
import sys
import math
64
import itertools as it
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
65
import os
66 67 68

from multiprocessing.queues import SimpleQueue
from multiprocessing import Process
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
69
from threading import Thread, Lock
70
from errno import EPIPE
71 72 73


from ..lib import pos_int_arg, add_input_output_args, get_input_output_files,\
74
                  add_sequence_format_args, reverse_complement, PAT_SEQ_RAW,\
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
75 76
                  ensure_sequence_format
from ..sg_align import align
77

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
78
__version__ = "2.0.0"
79 80 81 82 83 84 85


# Default values for parameters are specified below.

# Default maximum number of mismatches per nucleotide in the flanking
# sequences to allow.
# This value can be overridden by the -m command line option.
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
86
_DEF_MISMATCHES = 0.1
87

88 89 90
# Default penalty multiplier for insertions and deletions in the
# flanking sequences.
# This value can be overridden by the -n command line option.
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
91
_DEF_INDEL_SCORE = 2
92

93 94 95 96 97
# Default minimum number of reads to consider.
# This value can be overridden by the -a command line option.
_DEF_MINIMUM = 1


Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
98

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
class TSSV:
    def __init__(self, library, threshold, indel_score, dirname, workers, deduplicate, infile):
        # User inputs.
        self.library = library
        self.indel_score = indel_score
        self.workers = workers
        self.deduplicate = deduplicate
        self.lock = Lock()

        # Convert library.
        self.tssv_library = {marker: (
            (flanks[0], reverse_complement(flanks[1])), (
                int(math.ceil(len(flanks[0]) * threshold)),
                int(math.ceil(len(flanks[1]) * threshold))))
            for marker, flanks in library["flanks"].items()}

        # Open input file.
        file_format, self.input = init_sequence_file_read(infile)

        # Open output directory if we have one.
        if dirname:
            self.outfiles = prepare_output_dir(dirname, self.tssv_library, file_format)
        else:
            self.outfiles = None

        # Internal state.
        self.sequences = {marker: {} for marker in self.tssv_library}
        self.counters = {marker: {key: 0 for key in
                ("fPaired", "rPaired", "fLeft", "rLeft", "fRight", "rRight")}
            for marker in self.tssv_library}
        self.total_reads = 0
        self.unrecognised = 0
        self.cache = {}
    #__init__


    def dedup_reads(self):
        for record in self.input:
            self.lock.acquire()
            if record[1] in self.cache:
                completed, data = self.cache[record[1]]
                if completed:
                    self.process_results(record, data)
                else:
                    # Store header and (if applicable) quality scores.
                    data.append(record[0::2])
                self.lock.release()
            else:
                self.cache[record[1]] = (False, [record[0::2]])
                self.lock.release()
                yield record[1]
    #dedup_reads


    def cache_results(self, seq, results):
        self.lock.acquire()
        for record in self.cache[seq][1]:
            self.process_results(tuple([record[0], seq]) + record[1:], results)
        if self.deduplicate:
            self.cache[seq] = (True, results)
        else:
            del self.cache[seq]
        self.lock.release()
    #cache_results


    def process_results(self, record, results):
        self.total_reads += 1
        recognised = 0
        for marker, matches, seq1, seq2 in results:
            recognised |= matches
            self.counters[marker]["fLeft"] += matches & 1
            self.counters[marker]["fRight"] += matches >> 1 & 1
            self.counters[marker]["rLeft"] += matches >> 2 & 1
            self.counters[marker]["rRight"] += matches >> 3 & 1
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
174

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188
            # Search in the forward strand.
            if seq1 is not None:
                self.counters[marker]["fPaired"] += 1
                if seq1 not in self.sequences[marker]:
                    self.sequences[marker][seq1] = [1, 0]
                else:
                    self.sequences[marker][seq1][0] += 1
                if self.outfiles:
                    write_sequence_record(self.outfiles["markers"][marker]["paired"], record)
            elif self.outfiles:
                if matches & 1:
                    write_sequence_record(self.outfiles["markers"][marker]["noend"], record)
                if matches & 2:
                    write_sequence_record(self.outfiles["markers"][marker]["nostart"], record)
189

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203
            # Search in the reverse strand.
            if seq2 is not None:
                self.counters[marker]["rPaired"] += 1
                if seq2 not in self.sequences[marker]:
                    self.sequences[marker][seq2] = [0, 1]
                else:
                    self.sequences[marker][seq2][1] += 1
                if self.outfiles:
                    write_sequence_record(self.outfiles["markers"][marker]["paired"], record)
            elif self.outfiles:
                if matches & 4:
                    write_sequence_record(self.outfiles["markers"][marker]["noend"], record)
                if matches & 8:
                    write_sequence_record(self.outfiles["markers"][marker]["nostart"], record)
204

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        if not recognised:
            self.unrecognised += 1
            if self.outfiles:
                write_sequence_record(self.outfiles["unknown"], record)
    #process_results


    def process_file(self):
        if self.workers == 1:
            for seq in self.dedup_reads():
                self.cache_results(seq, process_sequence(self.tssv_library, self.indel_score, seq))
        else:
            # Start worker processes.  The work is divided into tasks that
            # require about 1 million alignments each.
            done_queue = SimpleQueue()
            chunksize = int(1000000/(4*len(self.tssv_library))) or 1
            thread = Thread(target=feeder, args=(self.dedup_reads(), self.tssv_library,
                self.indel_score, self.workers, chunksize, done_queue))
            thread.daemon = True
            thread.start()
            for seq, results in it.chain.from_iterable(iter(done_queue.get, None)):
                self.cache_results(seq, results)
            thread.join()

        # Count number of unique sequences per marker.
        for marker in self.tssv_library:
            self.counters[marker]["unique_seqs"] = len(self.sequences[marker])
    #process_file


    def filter_sequences(self, aggregate_filtered, minimum, missing_marker_action):
        # Aggregate the sequences that we are about to filter out.
        if aggregate_filtered:
            aggregates = {}
            for marker in self.sequences:
                expected_length = self.library.get("expected_length", {}).get(marker)
                for sequence, (forward, reverse) in self.sequences[marker].items():
                    if not seq_pass_filt(sequence, forward + reverse, minimum, expected_length):
                        if marker not in aggregates:
                            aggregates[marker] = [0, 0]
                        aggregates[marker][0] += forward
                        aggregates[marker][1] += reverse

        # Filter out sequences with low read counts and invalid bases.
        for marker, sequences in self.sequences.items():
            expected_length = self.library.get("expected_length", {}).get(marker)
            self.sequences[marker] = {sequence: counts
                for sequence, counts in sequences.items()
                if seq_pass_filt(sequence, sum(counts), minimum, expected_length)}

        # Add aggregate rows if the user requested so.
        if aggregate_filtered:
            for marker in aggregates:
                self.sequences[marker]["Other sequences"] = aggregates[marker]

        # Check presence of all markers.
        if missing_marker_action != "exclude":
            for marker in self.tssv_library:
                if not self.sequences[marker]:
                    if missing_marker_action == "include":
                        self.sequences[marker]["No data"] = [0, 0]
                    else:
                        raise ValueError("Marker %s was not detected!" % marker)
    #filter_sequences


    def write_sequence_tables(self, outfile, seqformat="raw"):
        header = "\t".join(("marker", "sequence", "total", "forward", "reverse")) + "\n"
        outfile.write(header)
        if self.outfiles:
            self.outfiles["sequences"].write(header)
        for marker in sorted(self.sequences):
            if self.outfiles:
                self.outfiles["markers"][marker]["sequences"].write(header)
            sequences = self.sequences[marker]
            for total, seq in sorted(((sum(sequences[s]), s) for s in sequences), reverse=True):
                line = "\t".join(map(str, [
                    marker,
                    ensure_sequence_format(seq, seqformat, "raw", self.library, marker),
                    total] + sequences[seq])) + "\n"
                outfile.write(line)
                if self.outfiles:
                    self.outfiles["sequences"].write(line)
                    self.outfiles["markers"][marker]["sequences"].write(line)
    #write_sequence_tables


    def write_statistics_table(self, outfile):
        header = "\t".join(("marker", "unique_seqs", "tPaired", "fPaired", "rPaired",
                            "tLeft", "fLeft", "rLeft", "tRight", "fRight", "rRight")) + "\n"
        if self.outfiles:
            self.outfiles["statistics"].write(header)
        outfile.write(header)
        for marker in sorted(self.counters):
            line = "\t".join(map(str, (
                marker,
                self.counters[marker]["unique_seqs"],
                self.counters[marker]["fPaired"] + self.counters[marker]["rPaired"],
                self.counters[marker]["fPaired"],
                self.counters[marker]["rPaired"],
                self.counters[marker]["fLeft"] + self.counters[marker]["rLeft"],
                self.counters[marker]["fLeft"],
                self.counters[marker]["rLeft"],
                self.counters[marker]["fRight"] + self.counters[marker]["rRight"],
                self.counters[marker]["fRight"],
                self.counters[marker]["rRight"]))) + "\n"
            if self.outfiles:
                self.outfiles["statistics"].write(line)
            outfile.write(line)

        line = "\ntotal reads\t%i\nunrecognised reads\t%i\n" % (self.total_reads,self.unrecognised)
        if self.outfiles:
            self.outfiles["statistics"].write(line)
        outfile.write(line)
    #write_statistics_table
#TSSV


def prepare_output_dir(dir, markers, file_format):
    # Create output directories.
    os.makedirs(dir)
    for marker in markers:
        os.mkdir(os.path.join(dir, marker))

    # Open output files.
    return {
        "sequences": open(os.path.join(dir, "sequences.csv"), "w"),
        "statistics": open(os.path.join(dir, "statistics.csv"), "w"),
        "unknown": open(os.path.join(dir, "unknown.f" + file_format[-1]), "w"),
        "markers": {
            marker: {
                "sequences": open(os.path.join(dir, marker, "sequences.csv"), "w"),
                "paired": open(os.path.join(dir, marker, "paired.f" + file_format[-1]), "w"),
                "noend": open(os.path.join(dir, marker, "noend.f" + file_format[-1]), "w"),
                "nostart": open(os.path.join(dir, marker, "nostart.f" + file_format[-1]), "w"),
            } for marker in markers
        }
    }
#prepare_output_dir


def align_pair(reference, reference_rc, pair, indel_score=1):
    left_dist, left_pos = align(reference, pair[0], indel_score)
    right_dist, right_pos = align(reference_rc, pair[1], indel_score)
    return (left_dist, left_pos), (right_dist, len(reference) - right_pos)
#align_pair


def process_sequence(tssv_library, indel_score, seq):
354 355 356 357
    """Find markers in sequence."""
    seqs = (seq, reverse_complement(seq))
    seqs_up = map(str.upper, seqs)
    results = []
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
358
    for marker, (pair, thresholds) in tssv_library.items():
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
        algn = (
            align_pair(seqs_up[0], seqs_up[1], pair, indel_score),
            align_pair(seqs_up[1], seqs_up[0], pair, indel_score))
        matches = 0
        if algn[0][0][0] <= thresholds[0]:
            # Left marker was found in forward sequence
            cutout = seqs[0][max(0, algn[0][0][1]-len(pair[0])):algn[0][0][1]]
            if cutout.lower() != cutout:
                matches += 1
        if algn[0][1][0] <= thresholds[1]:
            # Right marker was found in forward sequence.
            cutout = seqs[0][algn[0][1][1] : algn[0][1][1]+len(pair[1])]
            if cutout.lower() != cutout:
                matches += 2
        if algn[1][0][0] <= thresholds[0]:
            # Left marker was found in reverse sequence
            cutout = seqs[1][max(0, algn[1][0][1]-len(pair[0])):algn[1][0][1]]
            if cutout.lower() != cutout:
                matches += 4
        if algn[1][1][0] <= thresholds[1]:
            # Right marker was found in reverse sequence.
            cutout = seqs[1][algn[1][1][1] : algn[1][1][1]+len(pair[1])]
            if cutout.lower() != cutout:
                matches += 8
        results.append((marker, matches,
            # Matched pair in forward sequence.
            seqs[0][algn[0][0][1] : algn[0][1][1]] if
                (matches & 3) == 3 and algn[0][0][1] < algn[0][1][1]
                else None,
            # Matched pair in reverse sequence.
            seqs[1][algn[1][0][1] : algn[1][1][1]] if
                (matches & 12) == 12 and algn[1][0][1] < algn[1][1][1]
                else None))
    return results
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
393 394 395 396 397 398 399 400
#process_sequence


def seq_pass_filt(sequence, reads, threshold, explen=None):
    """Return False if the sequence does not meet the criteria."""
    return (reads >= threshold and PAT_SEQ_RAW.match(sequence) is not None and
        (explen is None or explen[0] <= len(sequence) <= explen[1]))
#seq_pass_filt
401 402 403 404 405 406 407


def worker(tssv_library, indel_score, task_queue, done_queue):
    """
    Read sequences from task_queue, write findings to done_queue.
    """
    for task in iter(task_queue.get, None):
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
408
        done_queue.put(tuple((seq, process_sequence(tssv_library, indel_score, seq)) for seq in task))
409 410 411
#worker


412
def feeder(input, tssv_library, indel_score, workers, chunksize, done_queue):
413 414
    """
    Start worker processes, feed them sequences from input and have them
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
415
    write their results to done_queue.
416 417 418 419 420 421 422 423 424 425
    """
    task_queue = SimpleQueue()
    processes = []
    for i in range(workers):
        process = Process(target=worker,
            args=(tssv_library, indel_score, task_queue, done_queue))
        process.daemon = True
        process.start()
        processes.append(process)
    while 1:
426
        # Sending chunks of reads to the workers.
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
427
        task = tuple(it.islice(input, chunksize))
428 429 430 431 432 433 434 435 436 437 438
        if not task:
            break
        task_queue.put(task)
    for i in range(workers):
        task_queue.put(None)
    for process in processes:
        process.join()
    done_queue.put(None)
#feeder


Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
439 440 441 442 443 444 445 446 447 448
def write_sequence_record(outfile, record):
    """
    Write a tuple of (header, sequence) to a FastA stream or
    a tuple of (header, sequence, quality) to a FastQ stream.
    """
    outfile.write((">%s\n%s\n" if len(record) == 2 else "@%s\n%s\n+\n%s\n") % record)
#write_sequence_record


def init_sequence_file_read(infile):
449
    """
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
450 451 452
    Return a 2-tuple with "fasta" or "fastq" and a generator that
    generates tuples of (header, sequence) from a FastA stream or
    tuples of (header, sequence, quality) from a FastQ stream.
453 454 455 456 457 458 459
    """
    firstchar = infile.read(1)
    if not firstchar:
        return
    if firstchar not in ">@":
        raise ValueError("Input file is not a FastQ or FastA file")

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
460 461 462 463 464 465 466 467 468 469 470
    def genreads():
        state = 0
        for line in infile:
            if state == 1:  # Put most common state on top.
                if firstchar == ">" and line.startswith(">"):
                    yield (header, seq)
                    header = line[1:].strip()
                    seq = ""
                elif firstchar == "@" and line.startswith("+"):
                    qual = ""
                    state = 2
471
                else:
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
472 473 474 475 476 477 478
                    seq += line.strip()
            elif state == 2:
                if line.startswith("@") and len(qual) >= len(seq):
                    yield (header, seq, qual)
                    header = line[1:].strip()
                    seq = ""
                    state = 1
479
                else:
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
480 481 482 483 484 485
                    qual += line.strip()
            elif state == 0:
                header = line.strip()
                seq = ""
                state = 1
        yield (header, seq) if state == 1 else (header, seq, qual)
486

Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
487 488
    return "fasta" if firstchar == ">" else "fastq", genreads()
#init_sequence_file_read
489 490


Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
491
def run_tssv_lite(infile, outfile, reportfile, library, seqformat,
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
492
                  threshold, minimum, aggregate_filtered,
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
493 494 495 496
                  missing_marker_action, dirname, indel_score, workers, no_deduplicate):
    tssv = TSSV(library, threshold, indel_score, dirname, workers, not no_deduplicate, infile)
    tssv.process_file()
    tssv.filter_sequences(aggregate_filtered, minimum, missing_marker_action)
497

498
    try:
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
499 500
        tssv.write_sequence_tables(outfile, seqformat)
        tssv.write_statistics_table(reportfile)
501 502 503
    except IOError as e:
        if e.errno != EPIPE:
            raise
504 505 506 507 508 509
#run_tssv_lite


def add_arguments(parser):
    add_sequence_format_args(parser, "raw", False, True)
    add_input_output_args(parser, True, False, True)
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
510 511 512 513 514 515
    parser.add_argument("-D", "--dir",
        help="output directory for verbose output; when given, a subdirectory "
             "will be created for each marker, each with a separate "
             "sequences.csv file and a number of FASTA/FASTQ files containing "
             "unrecognised reads (unknown.fa), recognised reads "
             "(Marker/paired.fa), and reads that lack one of the flanks of a "
516
             "marker (Marker/noend.fa and Marker/nostart.fa)")
517
    parser.add_argument("-T", "--num-threads", metavar="THREADS",
518 519
        type=pos_int_arg, default=1,
        help="number of worker threads to use (default: %(default)s)")
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
520 521 522
    parser.add_argument("-X", "--no-deduplicate", action="store_true",
        help="disable deduplication of reads; by setting this option, memory usage will be "
             "reduced in expense of longer running time")
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
523 524
    filtergroup = parser.add_argument_group("filtering options")
    filtergroup.add_argument("-m", "--mismatches", type=float,
525 526 527
        default=_DEF_MISMATCHES,
        help="number of mismatches per nucleotide to allow in flanking "
             "sequences (default: %(default)s)")
528 529 530 531 532
    filtergroup.add_argument("-n", "--indel-score", metavar="N",
        type=pos_int_arg, default=_DEF_INDEL_SCORE,
        help="insertions and deletions in the flanking sequences are "
             "penalised this number of times more heavily than mismatches "
             "(default: %(default)s)")
533
    filtergroup.add_argument("-a", "--minimum", metavar="N", type=pos_int_arg,
534 535 536
        default=_DEF_MINIMUM,
        help="report only sequences with this minimum number of reads "
             "(default: %(default)s)")
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
537 538
    filtergroup.add_argument("-A", "--aggregate-filtered", action="store_true",
        help="if specified, sequences that have been filtered (as per the "
539 540 541
             "-a/--minimum option, the expected_allele_length section in the "
             "library file, as well as all sequences with ambiguous bases) "
             "will be aggregated per marker and reported as 'Other sequences'")
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
542
    filtergroup.add_argument("-M", "--missing-marker-action", metavar="ACTION",
543 544 545 546 547 548 549 550 551 552 553 554 555
        choices=("include", "exclude", "halt"),
        default="include",
        help="action to take when no sequences are linked to a marker: one of "
             "%(choices)s (default: %(default)s)")
#add_arguments


def run(args):
    files = get_input_output_files(args, True, False)
    if not files:
        raise ValueError("please specify an input file, or pipe in the output "
                         "of another program")
    infile = sys.stdin if files[0] == "-" else open(files[0], "r")
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
556
    run_tssv_lite(infile, files[1], args.report, args.library,
557
                  args.sequence_format, args.mismatches, args.minimum,
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
558
                  args.aggregate_filtered, args.missing_marker_action,
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
559
                  args.dir, args.indel_score, args.num_threads, args.no_deduplicate)
560 561
    if infile != sys.stdin:
        infile.close()
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
562
#run