Python code for matching list
0
0
Entering edit mode
2.6 years ago

hello,

I'm trying matching list by python to get score. For that i write this script and run on windows terminal; import subprocess import re import sys

def combine(pattern, matching):

with open(pattern, 'r') as p:
    data_p = p.readlines()

# create pattern
data_str = ['']*len(data_p)
for idx, line in enumerate(data_p):
    data_str[idx] = re.split('\n', line)[0][:]

#print(data_str[0:5])
#print(data_str)

with open(matching, 'r') as m:
    data_m = m.readlines()[1:]
data_m = '>'.join(data_m)

#print(data_m[0:100])

#test='M37699'
#join_str1 = ''.join(data_str)
#idx1 = join_str1.find(test)
#print(join_str1[idx1:idx1+len(test)])

#idx2 = data_m.find(test)
#print(data_m[idx2:idx2+len(test)])

#sys.exit()

# find pattern
data_matching = ['']*len(data_str)
for i, pattern_i in enumerate(data_str):
    idx = data_m.find(pattern_i)
    length_pattern_i = len(pattern_i)
    idx_stop = data_m.find('>', idx)
    if idx != -1:
        #data_matching[i] = data_m[idx:idx+length_pattern_i]
        data_matching[i] = data_m[idx:idx_stop]
    else:
        print("a key doesn't match the data")
        sys.exit()

#print(data_matching)
#print(data_matching['>Z17DSoi5'])
#print(data_m[data_matching['>Z17DSoi5'][1]+9:data_matching['>Z17DSoi5'][1]+539])


# save the result
***outfile = open('C:\Python Programs/result_DNA_SBcCAS_ACLAME.txt', 'w+')***
outfile.write(''.join(data_matching))
outfile.close()

return None

if __name__ =='__main__':

***pattern = 'C:\Python Programs/SBcCAS_ACLAME.txt'
matching = 'C:\Python Programs/aclame_index.txt'***
combine(pattern, matching)

SBcCAS_ACLAME.txt is file and reference is aclame_index.txt and both are available on directory. but every time i got this error: a key doesn't match the data

Can somebody guide me.

ontology gene resistance Python ARO antibiotic • 481 views
ADD COMMENT

Login before adding your answer.

Traffic: 2523 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6