o
    Rŀgn                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd deZG d	d
 d
eZG dd deZ	G dd deZ
G dd deZG dd deZedkr_ddlmZ e  dS dS )zCommand line wrapper for bwa.    )	_Argument)_Option)_StaticArgument)_Switch)AbstractCommandlinec                   @      e Zd ZdZdddZdS )BwaIndexCommandlinea  Command line wrapper for Burrows Wheeler Aligner (BWA) index.

    Index database sequences in the FASTA format, equivalent to::

        $ bwa index [-p prefix] [-a algoType] [-c] <in.db.fasta>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaIndexCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> index_cmd = BwaIndexCommandline(infile=reference_genome, algorithm="bwtsw")
    >>> print(index_cmd)
    bwa index -a bwtsw /path/to/reference_genome.fasta

    You would typically run the command using index_cmd() or via the
    Python subprocess module, as described in the Biopython tutorial.

    bwac              	   K   sp   || _ tdtg dddd dddtg d	d
dddtdgddddtddgdg| _tj| |fi | dS )Initialize the class.index)-aa	algorithma  Algorithm for constructing BWT index.

                    Available options are:
                        - is:    IS linear-time algorithm for constructing suffix array.
                          It requires 5.37N memory where N is the size of the database.
                          IS is moderately fast, but does not work with database larger
                          than 2GB. IS is the default algorithm due to its simplicity.
                        - bwtsw: Algorithm implemented in BWT-SW. This method works with the
                          whole human genome, but it does not work with database
                          smaller than 10MB and it is usually slower than IS.c                 S   s   | dv S )N)isbwtsw xr   r   T/var/www/html/myenv/lib/python3.10/site-packages/Bio/Sequencing/Applications/_bwa.py<lambda>7   s    z.BwaIndexCommandline.__init__.<locals>.<lambda>FT)checker_functionequateis_required)-ppprefixz3Prefix of the output database [same as db filename])r   r   infilezInput file namefilenamer   -cczGBuild color-space index. The input fasta should be in nucleotide space.N)program_namer   r   r   r   
parametersr   __init__selfcmdkwargsr   r   r   r#   &   s,   
zBwaIndexCommandline.__init__Nr	   __name__
__module____qualname____doc__r#   r   r   r   r   r      s    r   c                   @   r   )BwaAlignCommandlinea8  Command line wrapper for Burrows Wheeler Aligner (BWA) aln.

    Run a BWA alignment, equivalent to::

        $ bwa aln [...] <in.db.fasta> <in.query.fq> > <out.sai>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaAlignCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> read_file = "/path/to/read_1.fq"
    >>> output_sai_file = "/path/to/read_1.sai"
    >>> align_cmd = BwaAlignCommandline(reference=reference_genome, read_file=read_file)
    >>> print(align_cmd)
    bwa aln /path/to/reference_genome.fasta /path/to/read_1.fq

    You would typically run the command line using align_cmd(stdout=output_sai_file)
    or via the Python subprocess module, as described in the Biopython tutorial.

    r	   c                 K   s  || _ tdtdgddddtdgddddtdd	gd
dd ddtddgd
dd ddtddgddd ddtddgddd ddtddgddd ddtddgd d!d ddtd"d#gd$d%d ddtd&d'gd(d)d ddtd*d+gd,d-d ddtd.d/gd0d1d ddtd2d3gd4d5d ddtd6d7gd8d9d ddtd:d;gd<d=d ddtd>d?gd@dAd ddtdBdCgdDtdEdFgdGtdHdIgdJtdKdLgdMtdNdOgdPtdQdRgdSg| _tj| |fi | dTS )Ur
   aln	referenceReference file nameTr   	read_filezRead file name-nnzMaximum edit distance if the value is INT, or the fraction of missing alignments given 2% uniform base error rate if FLOAT. In the latter case, the maximum edit distance is automatically chosen for different read lengths. [0.04]c                 S      t | ttfS N
isinstanceintfloatr   r   r   r   r   n       z.BwaAlignCommandline.__init__.<locals>.<lambda>Fr   r   -ooc                 S   r5   r6   r7   r   r   r   r   r   t   r;   z-eezWMaximum number of gap extensions, -1 for k-difference mode (disallowing long gaps) [-1]c                 S   
   t | tS r6   r8   r9   r   r   r   r   r   z      
 -ddz=Disallow a long deletion within INT bp towards the 3-end [16]c                 S   r@   r6   rA   r   r   r   r   r      rB   z-iiz4Disallow an indel within INT bp towards the ends [5]c                 S   r@   r6   rA   r   r   r   r   r      rB   z-llzTake the first INT subsequence as seed.

                    If INT is larger than the query sequence, seeding will be disabled.
                    For long reads, this option is typically ranged from 25 to 35 for
                    -k 2. [inf]c                 S   r@   r6   rA   r   r   r   r   r      rB   -kkz%Maximum edit distance in the seed [2]c                 S   r@   r6   rA   r   r   r   r   r      rB   -ttz,Number of threads (multi-threading mode) [1]c                 S   r@   r6   rA   r   r   r   r   r      rB   -MMziMismatch penalty. BWA will not search for suboptimal hits with a score lower than (bestScore-misMsc). [3]c                 S   r@   r6   rA   r   r   r   r   r      rB   -OOzGap open penalty [11]c                 S   r@   r6   rA   r   r   r   r   r      rB   -EEzGap extension penalty [4]c                 S   r@   r6   rA   r   r   r   r   r      rB   -RRa7  Proceed with suboptimal alignments if there are no more than INT equally best hits.

                    This option only affects paired-end mapping. Increasing this threshold helps
                    to improve the pairing accuracy at the cost of speed, especially for short
                    reads (~32bp).c                 S   r@   r6   rA   r   r   r   r   r      rB   -qqzParameter for read trimming [0].

                    BWA trims a read down to argmax_x{\sum_{i=x+1}^l(INT-q_i)} if q_l<INT
                    where l is the original read length.c                 S   r@   r6   rA   r   r   r   r   r      rB   -BBzLength of barcode starting from the 5-end. When INT is positive, the barcode of each read will be trimmed before mapping and will be written at the BC SAM tag. For paired-end reads, the barcode from both ends are concatenated. [0]c                 S   r@   r6   rA   r   r   r   r   r      rB   r   r    zXReverse query but not complement it, which is required for alignment in the color space.-NNzDisable iterative search. All hits with no more than maxDiff differences will be found. This mode is much slower than the default.z-IIzHThe input is in the Illumina 1.3+ read format (quality equals ASCII-64).-bbz6Specify the input read sequence file is the BAM formatz-b1b1zuWhen -b is specified, only use the first read in a read pair in mapping (skip single-end reads and the second reads).z-b2b2zIWhen -b is specified, only use the second read in a read pair in mapping.Nr!   r   r   r   r   r"   r   r#   r$   r   r   r   r#   b   s   


	}zBwaAlignCommandline.__init__Nr(   r)   r   r   r   r   r.   J       r.   c                   @   r   )BwaSamseCommandlinea  Command line wrapper for Burrows Wheeler Aligner (BWA) samse.

    Generate alignments in the SAM format given single-end reads.
    Equvialent to::

        $ bwa samse [-n maxOcc] <in.db.fasta> <in.sai> <in.fq> > <out.sam>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaSamseCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> read_file = "/path/to/read_1.fq"
    >>> sai_file = "/path/to/read_1.sai"
    >>> output_sam_file = "/path/to/read_1.sam"
    >>> samse_cmd = BwaSamseCommandline(reference=reference_genome,
    ...                                 read_file=read_file, sai_file=sai_file)
    >>> print(samse_cmd)
    bwa samse /path/to/reference_genome.fasta /path/to/read_1.sai /path/to/read_1.fq

    You would typically run the command line using samse_cmd(stdout=output_sam_file)
    or via the Python subprocess module, as described in the Biopython tutorial.

    r	   c                 K   s   || _ tdtdgddddtdgddddtdgd	dddtd
dgddd ddtddgddd ddg| _tj| |fi | dS )r
   samser0   r1   Tr   sai_filezSai file namer2   zRead  file namer3   r4   zMaximum number of alignments to output in the XA tag for reads paired properly.

                    If a read has more than INT hits, the XA tag will not be written. [3]c                 S   r@   r6   rA   r   r   r   r   r     rB   z.BwaSamseCommandline.__init__.<locals>.<lambda>Fr<   -rrCSpecify the read group in a format like '@RG	ID:foo	SM:bar'. [null]c                 S   r@   r6   rA   r   r   r   r   r     rB   Nr!   r   r   r   r"   r   r#   r$   r   r   r   r#      s.   

zBwaSamseCommandline.__init__Nr(   r)   r   r   r   r   r`      s    r`   c                   @   r   )BwaSampeCommandlineao  Command line wrapper for Burrows Wheeler Aligner (BWA) sampe.

    Generate alignments in the SAM format given paired-end reads.
    Equivalent to::

        $ bwa sampe [...] <in.db.fasta> <in1.sai> <in2.sai> <in1.fq> <in2.fq> > <out.sam>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaSampeCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> read_file1 = "/path/to/read_1.fq"
    >>> read_file2 = "/path/to/read_2.fq"
    >>> sai_file1 = "/path/to/read_1.sai"
    >>> sai_file2 = "/path/to/read_2.sai"
    >>> output_sam_file = "/path/to/output.sam"
    >>> read_group = r"@RG\tID:foo\tSM:bar"  # BWA will turn backslash-t into tab
    >>> sampe_cmd = BwaSampeCommandline(reference=reference_genome,
    ...                                 sai_file1=sai_file1, sai_file2=sai_file2,
    ...                                 read_file1=read_file1, read_file2=read_file2,
    ...                                 r=read_group)
    >>> print(sampe_cmd)
    bwa sampe /path/to/reference_genome.fasta /path/to/read_1.sai /path/to/read_2.sai /path/to/read_1.fq /path/to/read_2.fq -r @RG\tID:foo\tSM:bar

    You would typically run the command line using sampe_cmd(stdout=output_sam_file)
    or via the Python subprocess module, as described in the Biopython tutorial.

    r	   c                 K   s   || _ tdtdgddddtdgddddtdgd	dddtd
gddddtdgddddtddgddd ddtddgddd ddtddgddd ddtddgdd d ddtd!d"gd#d$d ddg| _tj| |fi | d%S )&r
   samper0   r1   Tr   	sai_file1z
Sai file 1	sai_file2z
Sai file 2
read_file1zRead  file 1
read_file2zRead  file 2r   r   zMaximum insert size for a read pair to be considered being mapped properly [500].

                    Since 0.4.5, this option is only used when there are not enough
                    good alignments to infer the distribution of insert sizes.c                 S   r@   r6   rA   r   r   r   r   r   R  rB   z.BwaSampeCommandline.__init__.<locals>.<lambda>Fr<   r=   r>   zMaximum occurrences of a read for pairing [100000].

                        A read with more occurrences will be treated as a single-end read.
                        Reducing this parameter helps faster pairing.c                 S   r@   r6   rA   r   r   r   r   r   [  rB   r3   r4   zMaximum number of alignments to output in the XA tag for reads paired properly [3].

                    If a read has more than INT hits, the XA tag will not be written.c                 S   r@   r6   rA   r   r   r   r   r   c  rB   rW   rX   zMaximum number of alignments to output in the XA tag for disconcordant read pairs (excluding singletons) [10].

                    If a read has more than INT hits, the XA tag will not be written.c                 S   r@   r6   rA   r   r   r   r   r   k  rB   rc   rd   re   c                 S   r@   r6   r8   strr   r   r   r   r   q  rB   Nrf   r$   r   r   r   r#   @  sR   
		2zBwaSampeCommandline.__init__Nr(   r)   r   r   r   r   rg     s    !rg   c                   @   r   )BwaBwaswCommandlinea  Command line wrapper for Burrows Wheeler Aligner (BWA) bwasw.

    Align query sequences from FASTQ files. Equivalent to::

        $ bwa bwasw [...] <in.db.fasta> <in.fq>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaBwaswCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> read_file = "/path/to/read_1.fq"
    >>> bwasw_cmd = BwaBwaswCommandline(reference=reference_genome, read_file=read_file)
    >>> print(bwasw_cmd)
    bwa bwasw /path/to/reference_genome.fasta /path/to/read_1.fq

    You would typically run the command line using bwasw_cmd() or via the
    Python subprocess module, as described in the Biopython tutorial.

    r	   c                 K   sL  || _ tdtdgddddtdgddddtdgd	dd
dtddgddd d
dtddgddd d
dtddgddd d
dtddgddd d
dtddgdd d d
dtd!d"gd#d$d d
dtd%d&gd'd(d d
dtd)d*gd+d,d d
dtd-d.gd/d0d d
dtd1d2gd3d4d d
dtd5d6gd7d8d d
dg| _tj| |fi | d9S ):r
   bwaswr0   r1   Tr   r2   z	Read file	mate_filez	Mate fileFr   r   zScore of a match [1]c                 S   r@   r6   rA   r   r   r   r   r     rB   z.BwaBwaswCommandline.__init__.<locals>.<lambda>r<   rZ   r[   zMismatch penalty [3]c                 S   r@   r6   rA   r   r   r   r   r     rB   rS   rT   zGap open penalty [5]c                 S   r@   r6   rA   r   r   r   r   r     rB   rc   rd   zOGap extension penalty. The penalty for a contiguous gap of size k is q+k*r. [2]c                 S   r@   r6   rA   r   r   r   r   r     rB   rI   rJ   z1Number of threads in the multi-threading mode [1]c                 S   r@   r6   rA   r   r   r   r   r     rB   -wwz'Band width in the banded alignment [33]c                 S   r@   r6   rA   r   r   r   r   r     rB   -TTz)Minimum score threshold divided by a [37]c                 S   r@   r6   rA   r   r   r   r   r     rB   r   r    zCoefficient for threshold adjustment according to query length [5.5].

                    Given an l-long query, the threshold for a hit to be retained is
                    a*max{T,c*log(l)}.c                 S   r@   r6   )r8   r:   r   r   r   r   r     rB   z-zzzIZ-best heuristics. Higher -z increases accuracy at the cost of speed. [1]c                 S   r@   r6   rA   r   r   r   r   r     rB   z-ssz{Maximum SA interval size for initiating a seed [3].

                    Higher -s increases accuracy at the cost of speed.c                 S   r@   r6   rA   r   r   r   r   r     rB   rW   rX   zYMinimum number of seeds supporting the resultant alignment to skip reverse alignment. [5]c                 S   r@   r6   rA   r   r   r   r   r     rB   Nrf   r$   r   r   r   r#     s   
	OzBwaBwaswCommandline.__init__Nr(   r)   r   r   r   r   ro   x  s    ro   c                   @   r   )BwaMemCommandlinea_  Command line wrapper for Burrows Wheeler Aligner (BWA) mem.

    Run a BWA-MEM alignment, with single- or paired-end reads, equivalent to::

        $ bwa mem [...] <in.db.fasta> <in1.fq> <in2.fq> > <out.sam>

    See http://bio-bwa.sourceforge.net/bwa.shtml for details.

    Examples
    --------
    >>> from Bio.Sequencing.Applications import BwaMemCommandline
    >>> reference_genome = "/path/to/reference_genome.fasta"
    >>> read_file = "/path/to/read_1.fq"
    >>> output_sam_file = "/path/to/output.sam"
    >>> align_cmd = BwaMemCommandline(reference=reference_genome, read_file1=read_file)
    >>> print(align_cmd)
    bwa mem /path/to/reference_genome.fasta /path/to/read_1.fq

    You would typically run the command line using align_cmd(stdout=output_sam_file)
    or via the Python subprocess module, as described in the Biopython tutorial.

    r	   c                 K   s  || _ tdtdgddddtdgddddtdgd	dd
dtddgddd d
dtddgddd d
dtddgddd d
dtddgddd d
dtddgdd d d
dtd!d"gd#d$d d
dtd%d&gd'd(d d
dtd)d*gd+d,d d
dtd-d.gd/d0d d
dtd1d2gd3d4d d
dtd5d6gd7d8d d
dtd9d:gd;d<d d
dtd=d>gd?d@d d
dtdAdBgdCdDd d
dtdEdFgdGdHd d
dtdIdJgdKtdLdMgdNtdOdPgdQtdRdSgdTtdUdVgdWtdXdYgdZg| _tj| |fi | d[S )\r
   memr0   r1   Tr   rk   zRead 1 file namerl   zRead 2 file nameFrI   rJ   zNumber of threads [1]c                 S   r@   r6   rA   r   r   r   r   r     rB   z,BwaMemCommandline.__init__.<locals>.<lambda>r<   rG   rH   zMinimum seed length. Matches shorter than INT will be missed. The alignment speed is usually insensitive to this value unless it significantly deviates 20. [19]c                 S   r@   r6   rA   r   r   r   r   r     rB   rr   rs   zBand width. Essentially, gaps longer than INT will not be found. Note that the maximum gap length is also affected by the scoring matrix and the hit length, not solely determined by this option. [100]c                 S   r@   r6   rA   r   r   r   r   r     rB   rC   rD   a  Off-diagonal X-dropoff (Z-dropoff). Stop extension when the difference between the best and the current extension score is above \|i-j\|*A+INT, where i and j are the current positions of the query and reference, respectively, and A is the matching score. Z-dropoff is similar to BLAST's X-dropoff except that it doesn't penalize gaps in one of the sequences in the alignment. Z-dropoff not only avoids unnecessary extension, but also reduces poor alignments inside a long good alignment. [100]c                 S   r@   r6   rA   r   r   r   r   r     rB   rc   rd   zTrigger re-seeding for a MEM longer than minSeedLen*FLOAT. This is a key heuristic parameter for tuning the performance. Larger value yields fewer seeds, which leads to faster alignment speed but lower accuracy. [1.5]c                 S   r5   r6   r7   r   r   r   r   r   %  r;   r   r    ziDiscard a MEM if it has more than INT occurrence in the genome. This is an insensitive parameter. [10000]c                 S   r@   r6   rA   r   r   r   r   r   +  rB   z-AAzMatching score. [1]c                 S   r@   r6   rA   r   r   r   r   r   1  rB   rU   rV   z[Mismatch penalty. The sequence error rate is approximately: {.75 * exp[-log(4) * B/A]}. [4]c                 S   r@   r6   rA   r   r   r   r   r   7  rB   rM   rN   zGap open penalty. [6]c                 S   r@   r6   rA   r   r   r   r   r   =  rB   rO   rP   zfGap extension penalty. A gap of length k costs O + k*E (i.e. -O is for opening a zero-length gap). [1]c                 S   r@   r6   rA   r   r   r   r   r   C  rB   z-LLaA  Clipping penalty. When performing SW extension, BWA-MEM keeps track of the best score reaching the end of query. If this score is larger than the best SW score minus the clipping penalty, clipping will not be applied. Note that in this case, the SAM AS tag reports the best SW score; clipping penalty is not deducted. [5]c                 S   r@   r6   rA   r   r   r   r   r   I  rB   z-UUzPenalty for an unpaired read pair. BWA-MEM scores an unpaired read pair as scoreRead1+scoreRead2-INT and scores a paired as scoreRead1+scoreRead2-insertPenalty. It compares these two scores to determine whether we should force pairing. [9] c                 S   r@   r6   rA   r   r   r   r   r   O  rB   rQ   rR   zComplete read group header line. 't' can be used in STR and will be converted to a TAB in the output SAM. The read group ID will be attached to every read in the output. An example is '@RG	ID:foo	SM:bar'. [null]c                 S   r@   r6   rm   r   r   r   r   r   U  rB   rt   ru   zWDon't output alignment with score lower than INT. This option only affects output. [30]c                 S   r@   r6   rA   r   r   r   r   r   [  rB   z-vvaF  Control the verbose level of the output. This option has not been fully supported throughout BWA. Ideally, a value 0 for disabling all the output to stderr; 1 for outputting errors only; 2 for warnings and errors; 3 for all normal messages; 4 or higher for debugging. When this option takes value 4, the output is not SAM. [3]c                 S   r@   r6   rA   r   r   r   r   r   a  rB   z-PPzrIn the paired-end mode, perform SW to rescue missing hits only but do not try to find hits that fit a proper pair.r   r   zmAssume the first input query file is interleaved paired-end FASTA/Q. See the command description for details.r   r   zOutput all found alignments for single-end or unpaired paired-end reads. These alignments will be flagged as secondary alignments.z-CCa-  Append FASTA/Q comment to SAM output. This option can be used to transfer read meta information (e.g. barcode) to the SAM output. Note that the FASTA/Q comment (the string after a space in the header line) must conform the SAM spec (e.g. BC:Z:CGTAC). Malformated comments lead to incorrect SAM output.z-HHzUse hard clipping 'H' in the SAM output. This option may dramatically reduce the redundancy of output when mapping long contig or BAC sequences.rK   rL   z@Mark shorter split hits as secondary (for Picard compatibility).Nr^   r$   r   r   r   r#     s   


~zBwaMemCommandline.__init__Nr(   r)   r   r   r   r   rx     r_   rx   __main__)run_doctestN)r-   Bio.Applicationr   r   r   r   r   r   r.   r`   rg   ro   rx   r*   
Bio._utilsr   r   r   r   r   <module>   s$   : 9Zl 
