Package: mappy
Mappy provides a convenient interface tominimap2, a fast and accurate C program to align
genomic and transcribe nucleotide sequences.InstallationMappy depends onzlib. It can be installed withpip:pipinstall--usermappyor from the minimap2 github repo (Cythonrequired):gitclonehttps://github.com/lh3/minimap2cdminimap2pythonsetup.pyinstallUsageThe following Python script demonstrates the key functionality of mappy:importmappyasmpa=mp.Aligner("test/MT-human.fa")# load or build indexifnota:raiseException("ERROR: failed to load/build index")s=a.seq("MT_human",100,200)# retrieve a subsequence from the indexprint(mp.revcomp(s))# reverse complementforname,seq,qualinmp.fastx_read("test/MT-orang.fa"):# read a fasta/q sequenceforhitina.map(seq):# traverse alignmentsprint("{}\t{}\t{}\t{}".format(hit.ctg,hit.r_st,hit.r_en,hit.cigar_str))APIsMappy implements two classes and two global function.Class mappy.Alignermappy.Aligner(fn_idx_in=None,preset=None,...)This constructor accepts the following arguments:fn_idx_in: index or sequence file name. Minimap2 automatically tests the
file type. If a sequence file is provided, minimap2 builds an index. The
sequence file can be optionally gzip’d. This option has no effect ifseqis set.seq: a single sequence to index. The sequence name will be set toN/A.preset: minimap2 preset. Currently, minimap2 supports the following
presets:srfor single-end short reads;map-pbfor PacBio
read-to-reference mapping;map-ontfor Oxford Nanopore read mapping;splicefor long-read spliced alignment;asm5for assembly-to-assembly
alignment;asm10for full genome alignment of closely related species. Note
that the Python module does not support all-vs-all read overlapping.k: k-mer length, no larger than 28w: minimizer window size, no larger than 255min_cnt: mininum number of minimizers on a chainmin_chain_score: minimum chaing scorebw: chaining and alignment band widthbest_n: max number of alignments to returnn_threads: number of indexing threads; 3 by defaultextra_flags: additional flags defined in minimap.hfn_idx_out: name of file to which the index is written. This parameter
has no effect ifseqis set.scoring: scoring system. It is a tuple/list consisting of 4, 6 or 7
positive integers. The first 4 elements specify match scoring, mismatch
penalty, gap open and gap extension penalty. The 5th and 6th elements, if
present, set long-gap open and long-gap extension penalty. The 7th sets a
mismatch penalty involving ambiguous bases.mappy.Aligner.map(seq,seq2=None,cs=False,MD=False)This method alignsseqagainst the index. It is a generator,yieldinga series ofmappy.Alignmentobjects. Ifseq2is present, mappy
performs paired-end alignment, assuming the two ends are in the FR orientation.
Alignments of the two ends can be distinguished by theread_numfield
(see Class mappy.Alignment below). Argumentcsasks mappy to generate
thecstag;MDis similar. These two arguments might slightly
degrade performance and are not enabled by default.mappy.Aligner.seq(name,start=0,end=0x7fffffff)This method retrieves a (sub)sequence from the index and returns it as a Python
string.Noneis returned ifnameis not present in the index or
the start/end coordinates are invalid.mappy.Aligner.seq_namesThis property gives the array of sequence names in the index.Class mappy.AlignmentThis class describes an alignment. An object of this class has the following
properties:ctg: name of the reference sequence the query is mapped toctg_len: total length of the reference sequencer_standr_en: start and end positions on the referenceq_standq_en: start and end positions on the querystrand: +1 if on the forward strand; -1 if on the reverse strandmapq: mapping qualityblen: length of the alignment, including both alignment matches and gaps
but excluding ambiguous bases.mlen: length of the matching bases in the alignment, excluding ambiguous
base matches.NM: number of mismatches, gaps and ambiguous positions in the alignmenttrans_strand: transcript strand. +1 if on the forward strand; -1 if on the
reverse strand; 0 if unknownis_primary: if the alignment is primary (typically the best and the first
to generate)read_num: read number that the alignment corresponds to; 1 for the first
read and 2 for the second readcigar_str: CIGAR stringcigar: CIGAR returned as an array of shape(n_cigar,2). The two
numbers give the length and the operator of each CIGAR operation.MD: theMDtag as in the SAM format. It is an empty string unless
theMDargument is applied when callingmappy.Aligner.map().cs: thecstag.AnAlignmentobject can be converted to a string withstr()in
the following format:q_st  q_en  strand  ctg  ctg_len  r_st  r_en  mlen  blen  mapq  cg:Z:cigar_strIt is effectively the PAF format without the QueryName and QueryLength columns
(the first two columns in PAF).Miscellaneous Functionsmappy.fastx_read(fn,read_comment=False)This generator function opens a FASTA/FASTQ file andyieldsa(name,seq,qual)tuple for each sequence entry. The input file may be
optionally gzip’d. Ifread_commentis True, this generator yields
a(name,seq,qual,comment)tuple instead.mappy.revcomp(seq)Return the reverse complement of DNA stringseq. This function
recognizes IUB code and preserves the letter cases. UracilUis
complemented toA.