Skip to main content

Tools to analysis biology sequence

Project description

BioSequences

PyPI - Downloads version python version PyPI - License PyPI - Wheel GitHub last commit GitHub Repo stars


用于分析核酸与肽段序列

下载源码编译

python setup.py build_ext --inplace
rm ./build

pip安装

pip install biosequences

主要功能

bioseq.Sequence(seq="", info="")

  • RNA,DNA和Peptide都基于此抽象类,因此Sequence中的属性和方法为所有序列对象公有的属性和方法。

  • 相同的序列对象可以直接与同类对象或字符串进行拼接,比较。

  • 所有对象都不会对seq进行检查,所以构建对象时需要主要seq中不要出现不应该出现的字符,以免发生不必要的问题

    from bioseq import DNA, Peptide
    
    d1 = DNA("ATCC")
    d2 = DNA("AC")
    p1 = Peptide("MATN")
    
    d1  # 5'-ATCC-3'
    p1  # N-MATN-C
    d1 + d2  # 5'-ATCCAC-3'
    d2 + d1  # 5'-ACATCC-3'
    d1 + p2  # TypeError(Expected str or DNA add with DNA, not Peptide)
    d1 == d2  # False
    

属性

seq

序列信息,不可修改

info

序列的一些说明信息(可选)

length

序列的长度

weight

序列的分子量

composition

序列中各个单位的含量

方法

align(subject, mode=1)

subject(str | Sequence)比对对象
mode(int)
    1 - 使用Needleman-Wunsch进行全局比对
    2 - 使用Smith-Waterman进行局部比对

find(target)

在序列中查找目标序列并返回所有匹配的起始位置

target(str| Sequence)目标序列

mutation(position, target)

改变序列信息

position(str | int | List[int])需要修改的单个字符或者是需要修改的字符串起始位置
target(str| Sequence)目标序列

toDNA(), toRNA(), toPeptide()

Sequence序列转换为对应的生物序列

bioseq.RNA

用于存储RNA序列信息。

属性

revered

返回序列的反向RNA序列

complemented

返回序列的反向互补RNA序列

GC

返回序列的GC含量

orf

序列中的开放读码框,使用过getOrf()方法后才具有此属性

peptide

序列转录产物,使用过tanscript()后才有此属性

方法

revers()

将序列自身变为其反向序列。注意:会修改序列自身

complemented()

将序列自身变为其反向互补序列。注意:会修改序列自身

getOrf(topn=1, replace=False)

获取序列上的ORF

topn(int)查找序列中的所有orf并返回最长的topn个读码框
replace(bool) 当multi=False时生效是否将最长的orf替换为原序列

transcript(topn=1)

将序列翻译为肽链

topn(bool)根据读码框返回长度最长的topn个翻译产物翻译产物均为Peptide对象

bioseq.DNA

用于存储DNA序列信息。

方法

translate()

将DNA翻译为RNA对象并返回

transcript(topn=1)

将序列翻译为肽链

topn(bool)根据读码框返回长度最长的topn个翻译产物翻译产物均为Peptide对象

bioseq.Peptide

用于存储肽链序列信息。

属性

pI

基于EMBOSS数据库中氨基酸的pK值, 计算该肽链序列的等电点并返回

方法

chargeInpH(pH: float)

基于EMBOSS数据库中氨基酸的pK值,计算肽链在某一pH下所带的电荷量

pH(float): 溶液的pH值

getHphob(window_size=9, show_img=True)

基于Doolittle(1982)的氨基酸疏水性数据,计算肽链的疏水性,疏水性

window_size(int)某一氨基酸的疏水性为window_size内该氨基酸位于window中心时的所有氨基酸疏水性的平均值
show_img绘制疏水性结果需要matplotlib

bioseq.config

可在此文件中直接修改配置数据,或通过以下函数在运行时修改部分数据

setAlignPara(match = 2, mismatch = -3, gap_open = -3, gap_extend = -3)

修改序列比对时的评分规则,需要在比对前进行设置

match(int) 匹配得分(>0)
mismath(int)错配得分(<0)
gap_open(int)开口得分(<0)
gap_extend(int)开口延长得分(<0) 

d1 = DNA("ATCTCGC")
d2 = DNA("ATCCC")

print(d1.align(d2)) #('ATCTCGC', 'ATC-C-C', 4.0)
setAlignPara(5)
print(d1.align(d2)) #('ATCTCGC', 'A--TCCC', -0.5)

setStartCoden(coden = None)

修改核酸序列转录时需要的起始密码子,为传入coden则将密码子初始化为*"AUG"*

coden(str | List(str))密码子会在coden中寻找如有匹配则开始进行转录

d1 = DNA("ATCATCTCAGCATGAC")

print(d1.transcript(filtered=False)) # []
setStartCoden(["AUC"])
print(d1.transcript(filtered=False)) # [N-IISA-C, N-ISA-C]

bioseq.utils

工具

printAlign(sequence1, sequence2, spacing=10, line_width=30, show_seq=True)

在命令行中按格式输出两个比对后的序列, 可在config.SYMBOL中修改显示的符号

spacing(int)序列显示间隔
line_width(int)每行显示的字符数
show_sequence(bool)是否显示序列

d1 = DNA("ATCATCTCAGCATGAC")
d2 = DNA("ATCATCGCATGAC")

seq1, seq2 = d1.align(d2)
printAlign(d1, d2)
#    1 ATCATCTCAG CAT
#      ┃┃┃┃┃┃•┃┃• •┃•
#    1 ATCATCGCAT GAC
printAlign(d1, d2, spacing=3, line_width=10, show_seq=False)
#    1 ┃┃┃ ┃┃┃ •┃┃ •
# 
#   11 •┃• 

parseFasta(fasta_text: str)

pasre a string in fasta format

loadFasta(filename, iterator=False)

读取fasta文件,并返回所有读取到的(序列列表,序列名列表)

filename(str): 文件名
itertor(bool): 用于读取大文件设置为True返回迭代器

fetchNCBI(uid)

uid(str|List[str]): NCBI中序列的唯一编号 NC_XXXXNM_XXXX等仅限于DNA(mRNA)RNA和多肽序列返回对应的序列对象支持批量获取返回Sequence列表顺序与传入的参数顺序不一致且不包含NCBI中未获取到的数据可以根据Sequence.info自行排序

NCBI RefSeq's document: https://www.ncbi.nlm.nih.gov/books/NBK21091/table/ch18.T.refseq_accession_numbers_and_mole some NCBI E-utilities's api: https://www.ncbi.nlm.nih.gov/books/NBK25499/table/chapter4.T._valid_values_of__retmode_and/

fetchENS(uid)

uid(str|List[str]): ENS编号支持批量获取返回Sequence列表顺序与传入的参数顺序一致

Ensemble REST Api: https://rest.ensembl.org/documentation/info/sequence_id

Change Log

Version: 1.1.4

  • add: bioseq.utils.fetchENS()
  • add: bioseq.utils.parseFasta()
  • add: Add iterator option to bioseq.utils.loadFasta()
  • add: multi-uids fetch support for bioseq.utils.fetchNCBI()

Version: 1.1.3

  • fix: Wrong results from bioseq.utils.loadFasta()

Version: 1.1.2

  • change: RNA.getOrf(), RNA.transcript()
  • add: algoritm.pyi

Version: 1.1.1

  • add: unittest
  • fix: some bug found in unintest

Version: 1.1.0

  • add: infoattribute for Sequence
  • add: toDNA(), toRNA(), toPeptide() method for Sequence
  • add: utils.fetchNCBI() change: utils.read_fasta() to utils.loadFasta and be a generator of Sequence

Version: 1.0.9

  • add: add type annotations, remove *.pyi file
  • add: Sequence.reset_cache() to reset some cached property, to update the value after mutation, include weight, composition, GC(DNA, RNA), orf(DNA, RNA), peptide(DNA, RNA), translate(DNA, RNA), pI(Peptide), Hphob_list(Peptide).
  • add: warning when mutation overlaped previous mutaion
  • fix: some wrong typing check in Sequence.find(), Sequence.mutation()
  • remove: return_score: bool for Sequence.align()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BioSequences-1.1.4.tar.gz (20.5 kB view details)

Uploaded Source

Built Distributions

BioSequences-1.1.4-cp38-cp38-win_amd64.whl (25.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

BioSequences-1.1.4-cp38-cp38-manylinux2014_x86_64.whl (39.3 kB view details)

Uploaded CPython 3.8

File details

Details for the file BioSequences-1.1.4.tar.gz.

File metadata

  • Download URL: BioSequences-1.1.4.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for BioSequences-1.1.4.tar.gz
Algorithm Hash digest
SHA256 504c3d27e6fcec7934722c9297869d864c2ba0fb962ee1477924eb9ebdb38e33
MD5 b3e3141301ce5e41f6cbca1e9abe7b63
BLAKE2b-256 af4fc947315e8ba27b6d3af1cfaca88da60a6c3d5bdb94d83abcba96b731e93c

See more details on using hashes here.

File details

Details for the file BioSequences-1.1.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: BioSequences-1.1.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for BioSequences-1.1.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e839b387a62d9fc05450d161488df0e62efb683789df98521c1cbc55b76f534b
MD5 457d47bf02c134627462c2a6a2031f81
BLAKE2b-256 45cafac40f5a1c9268ed2a5c89328cc3d026014076829772553d45983ef15f02

See more details on using hashes here.

File details

Details for the file BioSequences-1.1.4-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: BioSequences-1.1.4-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for BioSequences-1.1.4-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 321b6a57e7b20cf29b93cb56edd425cd58751a3ed9af63791dfb4df28ebe458e
MD5 ad3640d9ffabc00b7e487875a101b7bc
BLAKE2b-256 c720d3bc7388d089017bf6f4921a5a69966307aa5d3964791296072ba90f04f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page