0

enter image description here

I am trying to create adjacency matrix based on comparing overlaps between the substrings of set A.If there is a overlap between the substrings,then I will store +1 in the matrix M else wont.I have already written a code utilizing sequence matcher to compare the strings,but I am getting the following error while trying to execute the code.

import numpy
import array
from difflib import SequenceMatcher as sm
##
###read the file
##f=open('spectrum.txt','r')
##s=f.readlines()
##a=str(s)

a='{ATG,TGG,TGC,GTG,GGC,GCA,GCG,CGT}'
p= dict(enumerate(a[1:-1].split(",")))
print p    
n= p.keys()[-1]
print p.keys()[1]

M=numpy.zeros([n,n],int)
print M
for i in range(0,n-1):
    for j in range(0,n-1):
        if i==j:
            pass
        elif sm(None,p.keys(i),p.keys(j))!=0:
            M[i,j]+=1
        else:
            pass
print M
  • 2
    Possible duplicate of [Find common substring between two strings](http://stackoverflow.com/questions/18715688/find-common-substring-between-two-strings) – Two-Bit Alchemist Nov 29 '15 at 02:29
  • My query was more on i have already written a code utilizing sequence matcher to compare the strings but I think there is error on how the strings from the dictionary should be called. –  Nov 29 '15 at 02:36
  • I don't really get what you're saying, but if you're having an error that you expect us to help with, please post the full text of the error and the full traceback in your question (as text, not a screenshot). – Two-Bit Alchemist Nov 29 '15 at 02:45
  • I have added the screenshot.Will that be helpful to understand my query ? –  Nov 29 '15 at 02:51
  • **(as text, _not_ a screenshot)** – Two-Bit Alchemist Nov 29 '15 at 02:55
  • I can barely read the text in your screenshot but it looks like you are getting `TypeError: keys() takes no arguments (1 given)` which tells you exactly what is wrong. You are calling [`keys()`](https://docs.python.org/2/library/stdtypes.html#dict.keys) with an argument. It does not take one. – Two-Bit Alchemist Nov 29 '15 at 02:58

1 Answers1

0

Your traceback tells you exactly what the problem is. In this line:

elif sm(None,p.keys(i),p.keys(j))!=0:

You've passed i as an argument to .keys. keys takes no arguments. You might have meant to use keys()[i], but realistically, if you're actually trying to access .keys()[i], somewhere you should've used items() instead of keys() so you'd have access to 2-tuples of in the form (key, value) from your dictionary.

g.d.d.c
  • 46,865
  • 9
  • 101
  • 111
  • Ohhkk..Now,I got it.Yes,I have tried to modify it in my code.Thank you. –  Nov 29 '15 at 03:00