How to command python to continue beyond the loop?
1
0
Entering edit mode
6.4 years ago
KVC_bioinfo ▴ 590

Hello friends,

 pos = [10, 100, 1000]
 cigar = [[(0, 150), (3, 50), (0, 130), (3, 270), (0, 750),(2,50),(1, 70), (0,500)], [(0, 250), (3, 250), (0, 160), (3, 270)(0,750) ,(0,300)], [(0, 150), (3, 150), (0, 130), (3, 250), (0, 950)]] 
   def find (cigar, pos):
        matches=list()
        result=list()
        #name=list()
        for i in cigar:
                if i[0] == 1:
                        continue
                end =  pos + i[1]
        #print i[1]
                item = [i[0], pos, end]
                result.append(item)
                pos=end
        for i in result:
                if i[0] < 1:
                        matches.append([i[1],i[2]])
                        #matches.append([qname])

        return matches

    for x, y in zip(cigar, pos):
        #print x, y
        res = find(x, y)
        print res

I have this code which gives me half of my desired output:

[[10, 160], [210, 340], [610, 1360], [1410, 1910]]
[[100, 350], [600, 760], [1030, 1780], [1780, 2080]]
[[1000, 1150], [1300, 1430], [1680, 2630]]

My desired output is:

[[10,160],[210,340],[610,1910]]
[[100,350],[600-760],[1030-2180]]
[[1000,1150], [1300-1430], [1680-2630]]

From the code:

for i in result:
        if i[0] < 1:
            matches.append([i[1], i[2]])    
    return matches

I want the appending to break every time it hits i[0] == 3. But at the end of the list if it does not find i[3] I want it to continue appending. How can I give that command to the program? Could someone please help me?

Thank you very much in advance.

I also have this question posted at: StackOverflow

And similar post; Biostars

I have been trying this for long but I am not finding a solution to fix this.

python • 1.5k views
ADD COMMENT
0
Entering edit mode

What you mean "End of the list"? Do you mean, the last element of the list? If yes, grab the last element by result[-1]

ADD REPLY
0
Entering edit mode

cigar = [[(0, 150), (3, 50), (0, 130), (3, 270), (0, 750),(2,50),(1, 70), (0,500)], [(0, 250), (3, 250), (0, 160), (3, 270)(0,750) ,(0,300)], [(0, 150), (3, 150), (0, 130), (3, 250), (0, 950)]]

I mean the end of these lists. If you look at the output of my code and my desired output it shows the difference what I am expecting from the code.

ADD REPLY
0
Entering edit mode
6.4 years ago
Hussain Ather ▴ 990

In general, don't repost questions in multiple places.

for i in result:
    if i[0] == 3:
        matches.append([i[1], i[2]])
        break
    else:    
        continue    
return matches if i[0] == 3:
ADD COMMENT
0
Entering edit mode

Thank you and apologizes for posting again. I tried the code you suggested this doesn't give exactly what I want. I just edited the post with my desired output.

ADD REPLY

Login before adding your answer.

Traffic: 1715 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6