Question: How to command python to continue beyond the loop?
0
gravatar for KVC_bioinfo
2.2 years ago by
KVC_bioinfo410
Boston
KVC_bioinfo410 wrote:

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 • 657 views
ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by KVC_bioinfo410

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 REPLYlink modified 2.2 years ago • written 2.2 years ago by ramesh.8v200

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 REPLYlink written 2.2 years ago by KVC_bioinfo410
0
gravatar for Hussain Ather
2.2 years ago by
Hussain Ather940
National Institutes of Health, Bethesda, MD
Hussain Ather940 wrote:

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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by Hussain Ather940

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 REPLYlink written 2.2 years ago by KVC_bioinfo410
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2330 users visited in the last hour