Re: [intact-developers] python TypeError: string and non data type error

10 views
Skip to first unread message

Bruno Aranda

unread,
Oct 29, 2012, 8:01:15 PM10/29/12
to intact-d...@googlegroups.com
Hi Saba,

I think the problem is that getXrefByDatabase(cols[1], 'uniprotkb') assumes that there is a uniprotkb cross reference in the second column of the MITAB file. Maybe the method is failing because there is no such cross reference for one of the records in the results. I guess it would be straightforward to modify that method to add a check to see if no database with that name (uniprotkb) in this case, has been found.

Cheers,

Bruno

On 29 October 2012 14:29, Saba <saba.b...@iiu.edu.pk> wrote:
   Dear Intact taem, 
I am trying to retrieve the specific binary interactions of a data set of proteins. I am getting the following error: Can you suggest me that how to resolve the problem?


f2.write( getXrefByDatabase(cols[0], 'uniprotkb') + ' interacts with ' + getXrefByDatabase(cols[1], 'uniprotkb'))
TypeError: cannot concatenate 'str' and 'NoneType' objects

while this is the code: 

import urllib2
import sys

# ------------------ MITAB FUNCTIONS ------------------

def getXrefByDatabase(line, database):
   fields = line.split('|')

   for field in fields:
       parts = field.split(':')

       db = parts[0]
       value = parts[1].split('(')[0]

       if database == db:
           return value

# -----------------------------------------------------



f1=open ('pro_name.txt', 'r')
f2=open ('interactions.txt', 'w')
for line in f1:
   a = line.rstrip('\n')
   s2 = "%20AND%20taxidA:9606%20AND%20taxidB:9606?"
   queryUrl = s1 + a + s2;
   #print queryUrl
     
   try:
      fileHandle = urllib2.urlopen(queryUrl)
      content = fileHandle.read()
      fileHandle.close()
   except IOError:
      print 'Cannot open URL' % urlStr
      content = ''


   lines = content.splitlines()
   
   f2.write('\n')
   f2.write(a)
   f2.write('\n')
   
   for line in lines: 
      cols = line.split('\t')
      
      f2.write( getXrefByDatabase(cols[0], 'uniprotkb') + ' interacts with ' + getXrefByDatabase(cols[1], 'uniprotkb'))
      f2.write('\n')
      

best regards, 


Reply all
Reply to author
Forward
0 new messages