473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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?
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2.  
  3. import sys
  4. import fileinput
  5.  
  6. # Open the two files
  7. f1 = open(sys.argv[1], "r")
  8. f2 = open(sys.argv[2], "r")
  9. for line in f1:
  10.     chrR,chrStart,chrEnd,name,score,strand1,codingStart,codingEnd,itemRbg,blockCount,blockSize,BlockStart = line.strip().split()
  11.     chr = range(int(chrStart), int(chrEnd))    
  12.     lncRNA = set(chr)
  13.     for line in f2:
  14.         chrC,clustStart,clustEnd,annote,score,strand = line.strip().split()
  15.         clust = range(int(clustStart), int(clustEnd))
  16.         cluster = set(clust)
  17.         if strand1 == '-':
  18.             if chrR == chrC:
  19.                 if strand1 == strand:
  20.                     if lncRNA & cluster:
  21.                         print name, annote, 'transcript'
  22.                     else:
  23.                         continue
  24.                 continue
  25.         break
Oct 19 '11 #1
1 927
bvdet
2,851 Expert Mod 2GB
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.
Oct 19 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
8
by: jason.vanbrackel | last post by:
I have a VB6 Application that shells out some activity to another VB6 application in a separate thread. This second application relies heavily upon the Microsoft Access 10.0 Object Library. I...
2
by: randy1200 | last post by:
My hope is that somebody has a thought on this, or can point to toward an article that's useful. I have the following: DataSet ds = new DataSet(); ds.ReadXml("MyData.xml"); Each MainTable...
4
by: musosdev | last post by:
Hi I need to extend the contents of the src element of the <link relcss tags in the <headsection of my masterpage. From code, how can I access the <link elements within the <head? Cheers
0
by: robertkc | last post by:
Ok, here's an interesting one, and any help would be greatly appreciated! I'm looping through an xml document in order to set properties of an object. I have one property that is actually a...
9
by: brochu121 | last post by:
What I am trying to do is compare two files to each other. If the 2nd file contains the same line the first file contains, I want to print it. I wrote up the following code: ...
4
by: wbosw | last post by:
I'm trying to take a word (stEAdy) and find the index positions of the uppercase characters(2,3) in the word. I have them stored in an array (positionarray). Then I reverse the word and set all...
1
by: gwenky | last post by:
Hello, so I was working this out yesterday and I am working on a function (w/o using arrays) that moves through the digits of a user inputted number and finds max/min ...this is the max option and it...
4
by: PHPstarter | last post by:
Heya. I have a loop which generates a table code for a specific number of times. What I'm having problems with is to echo a variable inside the loop. The loop runs 10 times, and there are 10...
16
Knut Ole
by: Knut Ole | last post by:
I have a function to draw some shapes on a form depending on values in queries/tables. The whole procedure takes up to ten seconds however, and as I'm new to coding, I assume I might have a lot to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.