def bamtofastq(bam, picardjar, threads=1, paired=True, twofastq=False):
    assert os.path.exists(picardjar)
    assert bam.endswith('.bam')

    outfq = None
    outfq_pair = None

    cmd = ['java', '-XX:ParallelGCThreads=' + str(threads), '-Xmx4g', '-jar', picardjar, 'SamToFastq', 'VALIDATION_STRINGENCY=SILENT', 'INPUT=' + bam]
    cmd.append('INCLUDE_NON_PRIMARY_ALIGNMENTS=false') # in case the default ever changes
    
    if paired:
        if twofastq: # two-fastq paired end
            outfq_pair = [sub('bam$', '1.fastq', bam), sub('bam$', '2.fastq', bam)]
            cmd.append('F=' + outfq_pair[0])
            cmd.append('F2=' + outfq_pair[1])
        else: # interleaved paired-end
            outfq = sub('bam$', 'fastq', bam)
            cmd.append('FASTQ=' + outfq)
            cmd.append('INTERLEAVE=true')
    else:
        outfq = sub('bam$', 'fastq', bam)
        cmd.append('FASTQ=' + outfq)

    sys.stdout.write("INFO\t" + now() + "\tconverting BAM " + bam + " to FASTQ\n")
    subprocess.call(cmd)

    if outfq is not None:
        assert os.path.exists(outfq) # conversion failed
        return [outfq]

    if outfq_pair is not None:
        assert os.path.exists(outfq_pair[0]) and os.path.exists(outfq_pair[1])
        return outfq_pair

    return None
Runs this query on the index represented by 'searcher'.
dataset/ETHPy150Open adamewing/bamsurgeon/bamsurgeon/common.py/bamtofastq--crossover with--dataset/ETHPy150Open tallstreet/Whoosh-AppEngine/src/whoosh/query.py/Query.docs