2016-10-17 36 views
0
sample = ['AAAA','CGCG','TTTT','AT$T','ACAC','ATGC','AATA'] 
Position = [0, 1,  2,  3,  4,  5,  6] 

我有上面的示例与每个元素相关联的位置。我做滤波的几个步骤,这些步骤的代码被赋予here.如何在列表中的元素被分类为对(Python)之后保留原始列表的位置值?

在消除步骤是:

#If each base is identical to itself eliminate those elements eg. AAAA, TTTT 
#If there are more than 2 types of bases (i.e.' conversions'== 1) then eliminate those elements eg. ATGC 
#Make pairs of all remaining combinations 
#If a $ in the pair, then the corresponding base from the other pair is eliminated eg. (CGCG,AT$T) ==> (CGG, ATT) and (ATT, AAA) 
#Remove all pairs where one of the elements has all identical bases eg. (ATT,AAA) 

最后,我有与上述的不同组合的输出如下所示。

我需要找到一种方式,使我得到这些对相对于原始样本的位置如下。

Position = [[1,3],[1,4],[1,6],[3,4]] 

回答

0

您可以在列表转换为第一元组的列表

xs = ['AAAA', 'CGCG', 'TTTT', 'AT$T', 'ACAC', 'ATGC', 'AATA'] 
ys = [(i, x) for i,x in enumerate(xs)] 

print(ys) 
=> [(0, 'AAAA'), (1, 'CGCG'), (2, 'TTTT'), (3, 'AT$T'), (4, 'ACAC'), (5, 'ATGC'), (6, 'AATA')] 

然后,作为您的输入列表,而不是

+0

工作,但现在我必须在这里改变我的整个程序(HTTPS ://eval.in/662091)合并这个。没有一种方法可以在不妨碍代码的情况下对其进行外部跟踪? – biogeek

+0

@biogeek你应该发布你的程序。我将能够更好地帮助你。 – naomik

相关问题