Looping issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmmg729
    New Member
    • Oct 2011
    • 1

    Looping issues

    I am writing a program to compare two different files.

    For each line in file1 i want to compare it to all the lines in file2, then go to the next line in file1.

    the code i have below is not looping back to the next line in file1, can anyone give me any suggestions to help?
    Code:
    #! /usr/bin/env python
    
    import sys
    import fileinput
    
    # Open the two files
    f1 = open(sys.argv[1], "r")
    f2 = open(sys.argv[2], "r")
    for line in f1:
    	chrR,chrStart,chrEnd,name,score,strand1,codingStart,codingEnd,itemRbg,blockCount,blockSize,BlockStart = line.strip().split()
    	chr = range(int(chrStart), int(chrEnd))	
    	lncRNA = set(chr)
    	for line in f2:
    		chrC,clustStart,clustEnd,annote,score,strand = line.strip().split()
    		clust = range(int(clustStart), int(clustEnd))
    		cluster = set(clust)
    		if strand1 == '-':
    			if chrR == chrC:
    				if strand1 == strand:
    					if lncRNA & cluster:
    						print name, annote, 'transcript'
    					else:
    						continue
    				continue
    		break
    Last edited by bvdet; Oct 19 '11, 10:37 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Reset the file object to the beginning with f1.seek(0)
    - OR -
    Read the first file into a list with file method readlines() and iterate on the list.

    Comment

    Working...