Pick Matching lines with list of keywords

#Simple code to find the occurrence of list of search terms in single line in a huge file. 

Search_terms = ['A','B','C','D']

with open('BigFile.txt','r') as infile:
    entries = infile.read()
each_line = entries.splitlines()

new_list = []
for ix,row in enumerate(each_line):
    element = row.split("\t")
    if set(Search_terms) == set(element): #Use <= if you want no strict option
        print ix+1     #List the matching line number !
thefile = open('Output.txt','w')
for item in new_list:
    print>>thefile, item 


Popular posts from this blog

Condense fasta header

Fasta Header Replacer

Map multiple annotations using pandas