datasnakes / OrthoEvolution

An easy to use and comprehensive python package which aids in the analysis and visualization of orthologous genes. 🐵
https://orthoevolution.readthedocs.io/en/master/
29 stars 4 forks source link

Attribute Configuration Error #149

Closed sdhutchins closed 5 years ago

sdhutchins commented 5 years ago

What is the error or issue?

Traceback (most recent call last):
  File "/ddn/home5/r2295/GitRepo/OrthoEvolution/tests/test_orthologs.py", line 28, in test_baseblastn
    copy_from_package=True)
  File "/ddn/home5/r2295/GitRepo/OrthoEvolution/OrthoEvol/Orthologs/Blast/base_blastn.py", line 40, in __init__
    template=template, save_data=save_data, verbose=verbose, **kwargs)
  File "/ddn/home5/r2295/GitRepo/OrthoEvolution/OrthoEvol/Orthologs/Blast/comparative_genetics.py", line 473, in __init__
    post_blast=post_blast, hgnc=False, **kwargs)
  File "/ddn/home5/r2295/GitRepo/OrthoEvolution/OrthoEvol/Orthologs/Blast/comparative_genetics.py", line 134, in __init__
    self.project_index)
AttributeError: 'BaseBlastN' object has no attribute 'project_index'
Can you reproduce the behavior/error (place code below)?

The error is stemming from OrthoEvol/utilities.py in the attribute_config function.

In comparative_genetics.py, the function is called as seen below...

        # Configuration of class attributes.
        add_self = self.blast_utils.attribute_config(cls=self,
                                                     composer=proj_mana,
                                                     checker=ProjectManagement,
                                                     project=project,
                                                     project_path=project_path)
        for variable, attribute in add_self.__dict__.items():
            setattr(self, variable, attribute)

I've tried a number of different ways to get this to work properly, but I continue to have issues with it unless I set proj_mana to None.

Also, I'm currently using Python version 3.6.7 on linux.

@grabear Any thoughts on a fix?

grabear commented 5 years ago

@sdhutchins Can you show me what your script looks like?

grabear commented 5 years ago

Taking a look at the ProjectManagement class: https://github.com/datasnakes/OrthoEvolution/blob/c62bfe213f09b1a4f12b37ab530232bc2b3e6630/OrthoEvol/Manager/management.py#L249-L326

If the logic failed to pass here: https://github.com/datasnakes/OrthoEvolution/blob/c62bfe213f09b1a4f12b37ab530232bc2b3e6630/OrthoEvol/Manager/management.py#L277

Then you wouldn't have a self.project_index, and you would end up getting an AtrributeError

sdhutchins commented 5 years ago

Yes, the class itself is working with similar parameters.

There's no script. This code (attribute_config) has existed in the BlastN class for some time, and I'm guessing I'd never tested it with ProjectManagement because I was trying to circumvent that.

sdhutchins commented 5 years ago

It seems not to be setting the attributes from the ProjectManagement class. I tried a bit of debugging and inspecting the class, methods, and the attribute_config function but I wasn't able to figure out a way to solve the issue.

The other option is to inherit from the ProjectManagement class which wouldn't be very difficult imo. I was just curious if you had an idea about fixing this. Didn't want to just throw away that function entirely for this class.

grabear commented 5 years ago

There's no script.

Then how are you getting the error you're reporting? 😉 What I mean is "Can you give me a reproducible example?".

Show me the code you used to get this error.

I've tried a number of different ways to get this to work properly, but I continue to have issues with it unless I set proj_mana to None.

If you are using BlastN without ProjectManagement, then this is currently the only way to get things working.

The other option is to inherit from the ProjectManagement class which wouldn't be very difficult imo. I was just curious if you had an idea about fixing this

The goal was to remove any explicit inheritance of the management stuff from the class so that you could set it up however you wanted. It still forces you to use specific directories, but you can supply the root path (e.g. project_path). This could be expanded upon so that you could give it a bunch of custom locations instead of forcing this directory structure:

image

Didn't want to just throw away that function entirely for this class.

The attribute_config function is literally used in all of the Orthologs modules. So don't throw it away! It may just need to be expanded upon based on your needs. image

grabear commented 5 years ago

That being said...

I'm guessing I'd never tested it with ProjectManagement because I was trying to circumvent that.

In the past I've only used BlastN with ProjectManagement, and it's worked fine. So I'm not sure what's going on. Maybe I can speak more to it tomorrow after I've done some testing myself.

grabear commented 5 years ago

_See db_mana_test.py for an example on how I've gotten PM to work with other modules. (it uses initialize_new.yml_ to set up kwargs for PM.

Not sure if this will help or not, but that's all I can go off of without testing it myself or seeing what you're running.

grabear commented 5 years ago

And I see now this was for your tests...

sdhutchins commented 5 years ago

haha yes, I'm running this test...not sure how I missed mentioning that....Feel free to check out that branch and run it.

And yes, the ability of those classes to be used with ProjectManagement is important - as well as for it to not be used there so I definitely understand keeping that function - hence the issue after I spent the past 2 days breaking allllllllllll my code down and then reverting it all to see if it was just something I did. Could be the python version (I would guess not but who knows?). Then, I thought it may be my ide - but I tried this on 3 different ide's...and the OS...and...wellllllllp lol

Of course, just change the proj_mana or comment out that line....

"""This is the test suite for Orthologs."""
import unittest
from shutil import rmtree

from OrthoEvol.Orthologs.Blast import BaseBlastN

class TestOrthologs(unittest.TestCase):
    """Test the Orthologs module."""

    def setUp(self, project="gpcr", project_path="projects"):
        self.project = project
        self.project_path = project_path

    def delete_project(self, project_path):
        rmtree(project_path)

    def test_baseblastn(self):
        """Test the BaseBlastN class."""
        # The with statement is for travisci where a BLASTDB variable
        # is not set.
        # TIP: Remove the with statement if testing locally.
        with self.assertRaises(EnvironmentError):
            gpcr_blastn = BaseBlastN(project=self.project, method=3,
                                     save_data=True, acc_file="gpcr.csv",
                                     proj_mana=None,
                                     project_path=self.project_path,
                                     copy_from_package=True)
            self.assertEqual(gpcr_blastn.proj_mana, None)
            self.assertEqual(gpcr_blastn.acc_file, "gpcr.csv")
            self.assertTrue(gpcr_blastn.copy_from_package)
            self.delete_project(project_path=self.project_path)

if __name__ == '__main__':
    unittest.main()
sdhutchins commented 5 years ago

Resolved per our discussion...

In summary, proj_mana should be None or input an instance of the ProjectManagement class.