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
        new_list.append(element)
        print ix+1     #List the matching line number !
        
thefile = open('Output.txt','w')
for item in new_list:
    print>>thefile, item 

Comments

Popular posts from this blog

Fasta_Dupicate_Header

Gene Copy Number Matrix

Fasta_Header_Rename