转到字符串中的某个位置 [英] Going to a certain position in a string
问题描述
我想在与我所得到的相反(从负数方面)的字符串上到达某个点。
AAAAAAAAAACCCCCCCCCCCCTTTTTTTTTTGGGGGGGGGG
TTTTTTTTTTGGGGGGGGGGAAAAAAAAAACCCCCCCCCC
因此您需要转换坐标。在底部链上,基数0(最右边的C)与顶部链上的基数39相对。以1为底的是38,以2为底的。(重要点:注意,每次将这两个数相加时会发生什么。)因此,以10为底的是29,以19为底的20。 / p>
因此:如果我想在底部链上找到10-20的底数,我可以在顶部链上找到20-29的底数(然后反向补充)。
我写了以下内容:
fp = open(infile ,'r')
for fp中的行:
tokens = line.split()
exonstarts = tokens [8] [:-1] .split(',')
exonends =令牌[9] [:-1] .split(',')
压缩= list(zip(exonstarts,exonends))
chrom_len = len(chr_string)
s =' '.join(bc [base.upper()]用于chr_string [-starts-1:-ends-1]中的基数,用于开始,以压缩结尾)+'\n'
但是,每次这样做,我都会得到:
错误:全局名称开始'未定义
我该如何解决?
尝试在最后一项周围加上括号:
s =''.join(bc [base.upper()]为底数(chr_string [-starts-1:-ends-1] \
^
开头,以压缩结尾))+'\n'
^
您在此处定义了两个不同的生成器。这等效于:
strands =(chr_string [-starts-1:-ends-1]开头,结尾为压缩)
Supplementary_strands =(bc [base.upper()]为stage_1中的base)
join_exons =''.join(stage_2)+'\n'
I want to get to a certain point on a string that is opposite (from the negative side) to that of what I am given.
AAAAAAAAAACCCCCCCCCCTTTTTTTTTTGGGGGGGGGG TTTTTTTTTTGGGGGGGGGGAAAAAAAAAACCCCCCCCCC
So you need to convert coordinates. On the bottom strand, base 0 (the right-most C) is opposed to base 39 on the top strand. Base 1 is against base 38. Base 2 is against case 37. (Important point: notice what happens when you add these two numbers up — every time.) So base 10 is against base 29, and base 19 is against base 20.
So: if I want to find base 10-20 on the bottom strand, I can look at base 20-29 on the top (and then reverse-complement it).
I have written the following:
fp = open(infile, 'r')
for line in fp:
tokens = line.split()
exonstarts = tokens[8][:-1].split(',')
exonends = tokens[9][:-1].split(',')
zipped = list(zip(exonstarts, exonends))
chrom_len = len(chr_string)
s = ''.join(bc[base.upper()] for base in chr_string[-starts-1:-ends-1] for starts, ends in zipped)+'\n'
Yet, every time I do this I get:
Error: global name 'starts' is not defined
How do I fix this??
Try adding parentheses around the last term:
s = ''.join(bc[base.upper()] for base in (chr_string[-starts-1:-ends-1]\
^
for starts, ends in zipped)) +'\n'
^
Your defining two different generators here. This is equivalent to:
strands = (chr_string[-starts-1:-ends-1] for starts, ends in zipped)
complementary_strands = (bc[base.upper()] for base in stage_1)
joined_exons = ''.join(stage_2) + '\n'
这篇关于转到字符串中的某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!