PKN}iPwwhypothesis_bio/__init__.py"""Hypothesis strategies for biological data""" __version__ = "0.1" from . import strategies __all__ = [strategies] PKuOOl$hypothesis_bio/strategies.pyfrom enum import Enum from hypothesis import strategies as st DEFAULT_KSIZE = 21 class Alphabet(Enum): DNA = 1 DNA_N = 2 DNA_IUPAC = 3 RNA = 4 RNA_N = 5 RNA_IUPAC = 6 PROTEIN = 7 SYMBOLS = { Alphabet.DNA: "ACGT", Alphabet.DNA_N: "ACGTN", Alphabet.DNA_IUPAC: "AGCTYRWSKMDVHBNZ", Alphabet.RNA: "ACGU", Alphabet.RNA_N: "ACGUN", Alphabet.RNA_IUPAC: "AGCUYRWSKMDVHBNZ", Alphabet.PROTEIN: "ARNDCEQGHILKMFPSTWYV", } def symbols(alphabet: Alphabet) -> str: return SYMBOLS[alphabet] REVERSE_COMPLEMENTS = { Alphabet.DNA: dict(zip(symbols(Alphabet.DNA), "TGCA")), Alphabet.DNA_N: dict(zip(symbols(Alphabet.DNA_N), "TGCAN")), Alphabet.DNA_IUPAC: dict(zip(symbols(Alphabet.DNA_IUPAC), "TCGARYWSMKHBDVNZ")), Alphabet.RNA: dict(zip(symbols(Alphabet.RNA), "ACGU")), Alphabet.RNA_N: dict(zip(symbols(Alphabet.RNA_N), "ACGUN")), Alphabet.RNA_IUPAC: dict(zip(symbols(Alphabet.RNA_IUPAC), "UCGARYWSMKHBDVNZ")), } def reverse_complement(seq: str, alphabet: Alphabet = Alphabet.DNA) -> str: if alphabet == Alphabet.PROTEIN: raise ValueError("Proteins don't have reverse complements") RC = REVERSE_COMPLEMENTS[alphabet] return "".join(RC[c] for c in reversed(seq)) @st.composite def kmer(draw, *, alphabet: Alphabet = Alphabet.DNA, k: int = DEFAULT_KSIZE): """ A :mod:`hypothesis` strategy for creating k-mers, short sliding window substrings from a sequence. Parameters ---------- draw For internal hypothesis use. alphabet: Alphabet Symbols used to generate each position. Defaults to DNA symbols (ACGT) ksize: int Substring size. Must be positive. Returns ------- string a string with length k """ return draw(st.text(symbols(alphabet), min_size=k, max_size=k)) @st.composite def kmers( draw, seq: str, *, alphabet: Alphabet = Alphabet.DNA, k: int = DEFAULT_KSIZE, rc: bool = False ): """ A :mod:`hypothesis` strategy for creating k-mers (short sliding window substrings) from a given sequence. Parameters ---------- draw For internal hypothesis use. sequence: str Base sequence to sample k-mers from. Must be at least ksize long. alphabet: Alphabet Symbols used to generate each position. Defaults to DNA symbols (ACGT) ksize: int Substring size. Must be positive. Defaults to 21. rc: bool Allow reverse complements to be returned. Defaults to False. Returns ------- string a string with length k """ assert len(seq) >= k i = draw(st.integers(min_value=0, max_value=len(seq) - k)) kmer = seq[i : i + k] return_rc = False if rc: return_rc = draw(st.booleans()) if return_rc: return reverse_complement(kmer, alphabet) return kmer @st.composite def sequence(draw, *, alphabet: Alphabet = Alphabet.DNA, max_size: int = 1000): """ A :mod:`hypothesis` strategy for building nucleotide sequences Parameters ---------- draw For internal hypothesis use. alphabet: Alphabet Symbols used to generate each position. Defaults to DNA symbols (ACGT) max_size: int Length of the generated sequence. Must be positive. Returns ------- string a string representing a nucleotide sequence """ return draw(st.text(symbols(alphabet), max_size=max_size)) # strategy for creating valid FASTA records record = st.fixed_dictionaries( {"name": st.characters(min_codepoint=32, max_codepoint=126), "sequence": sequence} ) invalid_record = st.fixed_dictionaries( {"name": st.characters(), "sequence": st.characters()} ) PKN=6,55$hypothesis_bio-0.1.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2019 Luiz Irber Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HPO"hypothesis_bio-0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPK!H*t %hypothesis_bio-0.1.dist-info/METADATAVmsD~biL$IKf&Ҵ i-ɱgɖd\_Ooh*{%Ɛ7v9ZiDjGbZ%7M {XgL6@BgRvK *yU6LNB˨Gi4с)PY"Mrmbx L<; 䲈Ahp?Udm!0eݡFV" n"{7. Rm+dX$,Lw8[JT>k}F.Bx?MUԿv#;N%*%wnQFFgE)U\e5<xJ񩌯Of\3]I/z垹Q|֑%u~ހyx~U.__3.j^Zɼey%"|֨j#NWmNZq3/«pksF ()w1x8ЌͿevӲw'YH0S$: q-Bִ,Eu}buɭ1~>wgv'Q^DUʣz8S3rgړYN-].FaCyțP!;Ά$4j%&W4цu]1KhT~=@גò2f咑PK!HXY1#hypothesis_bio-0.1.dist-info/RECORD};r@޳`6; UȂ OLb^ʱm24KIMz2^‡{`$H: qY$#ѝGp{1Y /Ҿ c{7pTHbnJjBD{A,RB9fi*w:N-m>t/^IZ(!iXQ|B^Gg!{ɅpAmdn9]g!F|x7W4W6i]xpi!@aCb9U!aʼn; Vc/PKN}iPwwhypothesis_bio/__init__.pyPKuOOl$hypothesis_bio/strategies.pyPKN=6,55$hypothesis_bio-0.1.dist-info/LICENSEPK!HPO" hypothesis_bio-0.1.dist-info/WHEELPK!H*t %hypothesis_bio-0.1.dist-info/METADATAPK!HXY1#hypothesis_bio-0.1.dist-info/RECORDPK