This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Why Is This For Statement Appending Twice? Python
alpha_sum = [2396, 780, 2022, 596]
alpha_b_sum = [2206, 828, 1962, 597]
results_alpha = [[145, 142, 142, 111, 121, 151, 111, 113, 121, 106, 67, 151, 57, 111, 106, 101, 111, 98, 142, 106, 83], [142, 106, 83, 69, 145, 121, 114], [69, 145, 121, 114, 57, 121, 111, 121, 151, 77, 121, 77, 101, 113, 142, 77, 113, 108, 83], [113, 108, 83, 77, 114, 101], [57, 106, 98, 101, 101, 108, 108, 77, 114, 106, 142, 57, 113, 67], [101, 121, 77, 121, 57, 142, 142, 114, 121]]
values_alpha= [145, 142, 142, 111, 121, 151, 111, 113, 121, 106, 67, 151, 57, 111, 106, 101, 111, 98, 142, 106, 83, 69, 145, 121, 114, 57, 121, 111, 121, 151, 77, 121, 77, 101, 113, 142, 77, 113, 108, 83, 77, 114, 101, 69, 151, 67, 57, 106, 98, 101, 101, 108, 108, 77, 114, 106, 142, 57, 113, 67, 77, 101, 121, 77, 121, 57, 142, 142, 114, 121]



for alpha, alpha_b in zip(alpha_sum,  alpha_b_sum):
    for i in range(len(values_alpha)):
        if alpha > alpha_b:

            for element in results_alpha:

                length = len(element)
                if values_alpha[i:i+length] == element:

                    export.append('Alpha'+'\t'+'[%d, %d]' % (i, i+length-1)+'\n') 
                    #print '[%d,%d]' % (i, i+length-1)+'\n'

                else:
                    pass

print export
['Alpha\t[0, 20]\n', 'Alpha\t[18, 24]\n', 'Alpha\t[21, 39]\n', 'Alpha\t[37, 42]\n', 'Alpha\t[46, 59]\n', 'Alpha\t[61, 69]\n', 
 'Alpha\t[0, 20]\n', 'Alpha\t[18, 24]\n', 'Alpha\t[21, 39]\n', 'Alpha\t[37, 42]\n', 'Alpha\t[46, 59]\n', 'Alpha\t[61, 69]\n']

Why is it appending the data twice???

Whats going on here is a list of numbers -> values_alpha

and within that list there are certain portions which were appended to -> results_alpha

so resultsalpha has portions of valuesalpha

i'm trying to check if each element in alphasum > alphabsum and if it is, add the positions that particular sequence occurred (element in resultsalpha) within the original sequence (values_alpha) . if not then just skip it, hence the pass command

python off

Again a question which should be discussed at stackoverflow.com

there is no obvious reference to bioinformatics

0 answers

No answers yet.

Log in to answer this question.