This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Comparing Text Files Using Python

Hi all

I have 29 text files as follows

File 1

Comp1 : 23546

    12313
    23214
    32465

File 2

Comp2 : 23546

    12323
    32125
    32125
    32121

I would like to have python script which computes intersection between these files and finally want to print first column ID and common id between files as follows

Comp1 : 23546
Comp2 : 23546

I have tried following it doesnt work

file1=open("com1.txt","r")
file2=open("com3.txt","r")
file3=open("Overlap_compound1_2","w")
list1=file1.readlines()
list2=file2.readlines()

for line1 in list1:
  for line2 in list2:
    if line1.strip() in line2.strip().split(' '):
      print line2
      file3.write(line2)

Thanks

Ni

python

0 answers

No answers yet.

Log in to answer this question.