xpolak37 / COGtools

A computational tools for improving the functional annotation of bacterial genomes and the classification of CDSs into cllusters of orthologous groups (COGs). It allows summarizing annotations from different resources to provide a more accurate annotation of genes regarding their assignment into COGs and their categories.
MIT License
3 stars 0 forks source link

Bug in selection of a pattern to search for location of CDS #2

Open KSabatova opened 1 year ago

KSabatova commented 1 year ago

I run the tool and got an error message:

'NoneType' object has no attribute 'group'

Altough, this error message was not really specific, it looked like there was a problem with some regex pattern search. After some debugging I found out that em_processor() and also batch_processor() functions contain a command to create a dictionary to store a pattern to locate start and end of CDS and to store a strand direction (lines 34-35 in em_processor(), lines 261-262 in batch_processor()).

dic = {'pattern': "complement\((.*?)\)", 'strand': "-"} if "complement" in record else \
      {'pattern': "location=(.*?)]", 'strand': "+"}

Then on the next line indices of CDS are obtained by search() function and group() method, which raised this exception.

location = search(dic['pattern'], record).group(1)

This exception was raised because the search() function didn't find any match of the pattern in the string.

In my case record variable contained string 'lcl|CP086135.1_prot_UEG76830.1_88 [locus_tag=LKW31_22130] [protein=complement resistance protein TraT] [protein_id=UEG76830.1] [location=108904..109221] [gbkey=CDS]' and the dic variable contained dictionary {'pattern': 'complement\\((.*?)\\)', 'strand': '-'}.

So the pattern in dic was wrongly chosen, because the string in record variable contained word 'complement' in protein description not in location description. Therefore, during the creation of dic variable wrong pattern was chosen.

For now I was able to fix the problem by changing the command for assignment to dic variable.

dic = {'pattern': "complement\((.*?)\)", 'strand': "-"} if "location=complement" in record else \
      {'pattern': "location=(.*?)]", 'strand': "+"}

If necessary, I can provide the files to recreate this bug.

Thank you for a very nice and helpful tool.