切割字符串功能/ Python适用于生物信息学 [英] slicing functionality for strings / Python suitability for bioinformatics

查看:66
本文介绍了切割字符串功能/ Python适用于生物信息学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> rs =''AUGCUAGACGUGGAGUAG''

rs [12:15] =''GAG''



Traceback(最近一次调用最后一次):

文件"< pyshell#119>",第1行,在?

rs [12:15] =''GAG''

TypeError:对象不支持切片分配


你可以''分配给
Python 2.3中的切片字符串的一部分,并且似乎没有提到这个作为Python 2.4特性的
(不要有时间实际尝试

2.4)。


Q1。扩展切片是否使用了Sequence协议?

Q2。不是字符串也支持Sequence protcol?

Q3。那么为什么你不能在处理字符串时进行扩展切片赋值工作




这种操作(切片/拼接序列代表

作为字符串)在执行

rna / dna /蛋白质测序算法时似乎是一个非常基本的oepration,它会大大增强

Python'如果切片

和扩展切片操作符达到其逻辑限制,那么对生物信息学工作的人有吸引力。


粗略搜索看起来似乎没有揭示任何当前的PEP

处理扩展切片/扩展的功能

切片操作符。


语法和功能明智,有没有理由为什么Python不能踢?
Perl's butt作为生物信息学的主导语言和

最终成为这种快速增长的通用语言和
资金丰富的领域?

解决方案

jb********@yahoo.com 写道:

rs =''AUGCUAGACGUGGAGUAG''
rs [12:15] =''GAG''


Traceback(最近一次调用最后一次):
文件"< pyshell#119>",第1行,在?
rs [12:15] =''GAG' '
TypeError:对象不支持切片分配

你不能在Python 2.3中分配切片字符串的一部分而且似乎没有提到这个作为Python 2.4的功能(没有时间实际尝试
2.4)。




字符串是在Python中不可变,这就是为什么分配给
切片不起作用的原因。

但为什么不使用列表呢?


rs = list(''AUGC ...'')

rs [12:15] = list(''GAG'')


Reinhold

< br>



" Reinhold Birkenfeld" <再************************ @ wolke7.net>写在

消息新闻:3p ************ @ individual.net ...

jb ******** @ yahoo.com 写道:

> rs =''AUGCUAGACGUGGAGUAG''
> rs [12:15] =''GAG''


Traceback(最近一次调用最后一次):
文件"< pyshell#119>",第1行,in?
rs [12:15] =''GAG''
TypeError:对象不支持切片分配

你不能分配切片字符串的一部分在Python 2.3中,似乎没有提到这个作为Python 2.4的功能(没有时间实际尝试
2.4)。



字符串在Python中是不可变的,这就是为什么分配到片段不起作用的原因。
但为什么不使用列表?

rs = list(''AUGC ......'')
rs [12:15] = list(''GAG'')




或者字符数组:参见数组模块。


Terry J. Reedy


对,我忘记了那......


>>> rs=''AUGCUAGACGUGGAGUAG''

rs[12:15]=''GAG''


Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs[12:15]=''GAG''
TypeError: object doesn''t support slice assignment

You can''t assign to a section of a sliced string in
Python 2.3 and there doesn''t seem to be mention of this
as a Python 2.4 feature (don''t have time to actually try
2.4 yet).

Q1. Does extended slicing make use of the Sequence protocol?
Q2. Don''t strings also support the Sequence protcol?
Q3. Why then can''t you make extended slicing assignment work
when dealing with strings?

This sort of operation (slicing/splicing of sequences represented
as strings) would seem to be a very fundamental oepration when doing
rna/dna/protein sequencing algorithms, and it would greatly enhance
Python''s appeal to those doing bioinformatics work if the slicing
and extended slicing operators worked to their logical limit.

Doing a cursory search doesn''t seem to reveal any current PEPs
dealing with extending the functionality of slicing/extended
slicing operators.

Syntax and feature-wise, is there a reason why Python can''t kick
Perl''s butt as the dominant language for bioinformatics and
eventually become the lingua franca of this fast-growing and
funding-rich field?

解决方案

jb********@yahoo.com wrote:

rs=''AUGCUAGACGUGGAGUAG''
rs[12:15]=''GAG''


Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs[12:15]=''GAG''
TypeError: object doesn''t support slice assignment

You can''t assign to a section of a sliced string in
Python 2.3 and there doesn''t seem to be mention of this
as a Python 2.4 feature (don''t have time to actually try
2.4 yet).



Strings are immutable in Python, which is why assignment to
slices won''t work.

But why not use lists?

rs = list(''AUGC...'')
rs[12:15] = list(''GAG'')

Reinhold



"Reinhold Birkenfeld" <re************************@wolke7.net> wrote in
message news:3p************@individual.net...

jb********@yahoo.com wrote:

> rs=''AUGCUAGACGUGGAGUAG''
> rs[12:15]=''GAG''


Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs[12:15]=''GAG''
TypeError: object doesn''t support slice assignment

You can''t assign to a section of a sliced string in
Python 2.3 and there doesn''t seem to be mention of this
as a Python 2.4 feature (don''t have time to actually try
2.4 yet).



Strings are immutable in Python, which is why assignment to
slices won''t work.

But why not use lists?

rs = list(''AUGC...'')
rs[12:15] = list(''GAG'')



Or arrays of characters: see the array module.

Terry J. Reedy


right, i forgot about that...


这篇关于切割字符串功能/ Python适用于生物信息学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆