Example #1
0
    def __init__(self, lasagna):
        super(plugin, self).__init__(lasagna)
        self.lasagna = lasagna

        self.pluginShortName = "ARA explorer"
        self.pluginLongName = "Allen Reference Atlas explorer"
        self.pluginAuthor = "Rob Campbell"

        #Read file locations from preferences file (creating a default file if none exists)
        self.pref_file = lasHelp.getLasagna_prefDir() + 'ARA_plugin_prefs.yml'
        self.prefs = lasHelp.loadAllPreferences(
            prefFName=self.pref_file, defaultPref=self.defaultPrefs())

        #The last value the mouse hovered over. When this changes, we re-calculate the contour
        self.lastValue = -1

        #default names of the three files that we need:
        self.atlasFileName = 'atlas'
        self.templateFileName = 'template'
        self.labelsFileName = 'labels'

        #The root node index of the ARA
        self.rootNode = 8

        #Warn and quit if there are no paths
        if len(self.prefs['ara_paths']) == 0:
            self.warnAndQuit(
                'Please fill in preferences file at<br>%s<br><a href="http://raacampbell.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell.github.io/lasagna/ara_explorer_plugin.html</a>'
                % self.pref_file)
            return

        #Set up the UI
        self.setupUi(self)
        self.show()
        self.statusBarName_checkBox.setChecked(
            self.prefs['enableNameInStatusBar'])
        self.highlightArea_checkBox.setChecked(self.prefs['enableOverlay'])

        self.brainArea_itemModel = QtGui.QStandardItemModel(
            self.brainArea_treeView)
        self.brainArea_treeView.setModel(self.brainArea_itemModel)

        #Link the selections in the tree view to a slot in order to allow highlighting of the selected area
        self.brainArea_treeView.selectionModel().selectionChanged[
            QtCore.QItemSelection,
            QtCore.QItemSelection].connect(self.highlightSelectedAreaFromList)

        #Link signals to slots
        self.araName_comboBox.activated.connect(self.araName_comboBox_slot)
        self.load_pushButton.released.connect(self.load_pushButton_slot)
        self.overlayTemplate_checkBox.stateChanged.connect(
            self.overlayTemplate_checkBox_slot)

        self.statusBarName_checkBox.stateChanged.connect(
            self.statusBarName_checkBox_slot)
        self.highlightArea_checkBox.stateChanged.connect(
            self.highlightArea_checkBox_slot)

        #Loop through all paths and add to combobox.
        self.paths = dict()
        n = 1
        for path in self.prefs['ara_paths']:

            if not os.path.exists(path):
                print("%s does not exist. skipping" % path)
                continue

            filesInPath = os.listdir(path)
            if len(filesInPath) == 0:
                print("No files in %s . skipping" % path)
                continue

            pths = dict(atlas='', labels='', template='')
            print("\n %d. Looking for files in directory %s" % (n, path))
            n += 1

            files = os.listdir(path)

            #get the file names
            for thisFile in files:
                if thisFile.startswith(self.atlasFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['atlas'] = os.path.join(path, thisFile)
                    print("Adding atlas file %s" % thisFile)
                    break

            for thisFile in files:
                if thisFile.startswith(self.labelsFileName):
                    pths['labels'] = os.path.join(path, thisFile)
                    print("Adding labels file %s" % thisFile)
                    break

            for thisFile in files:
                if thisFile.startswith(self.templateFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['template'] = os.path.join(path, thisFile)
                    print("Adding template file %s" % thisFile)
                    break

            if len(pths['atlas']) == 0 | len(pths['labels']) == 0:
                print('Skipping empty empty paths entry')
                continue

            #If we're here, this entry should at least have a valid atlas file and a valid labels file

            #We will index the self.paths dictionary by the name of the atlas file as this is also
            #what will be put into the combobox.
            atlasDirName = path.split(os.path.sep)[-1]

            #skip if a file with this name already exists
            if atlasDirName in self.paths:
                print(
                    "Skipping as a directory called %s is already in the list"
                    % atlasDirName)
                continue

            #Add this ARA to the paths dictionary and to the combobox
            self.paths[atlasDirName] = pths
            self.araName_comboBox.addItem(atlasDirName)

        #blank line
        print("")

        #If we have no paths to ARAs by the end of this, issue an error alertbox and quit
        if len(self.paths) == 0:
            self.warnAndQuit(
                'Found no valid paths in preferences file at<br>%s.<br>SEE <a href="http://raacampbell.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell.github.io/lasagna/ara_explorer_plugin.html</a>'
                % self.pref_file)
            return

        self.lasagna.removeIngredientByType(
            'imagestack')  #remove all image stacks

        #If the user has asked for this, load the first ARA entry automatically
        self.data = dict(currentlyLoadedAtlasName='',
                         currentlyLoadedOverlay='')

        currentlySelectedARA = str(
            self.araName_comboBox.itemText(
                self.araName_comboBox.currentIndex()))
        if self.prefs['loadFirstAtlasOnStartup']:
            print("Auto-Loading " + currentlySelectedARA)
            self.loadARA(currentlySelectedARA)
            self.load_pushButton.setEnabled(
                False
            )  #disable because the current selection has now been loaded

        #Make a lines ingredient that will house the contours for the currently selected area.
        self.contourName = 'aracontour'
        self.lasagna.addIngredient(objectName=self.contourName,
                                   kind='lines',
                                   data=[])
        self.lasagna.returnIngredientByName(
            self.contourName).addToPlots()  #Add item to all three 2D plots
    def __init__(self,lasagna):
        super(plugin,self).__init__(lasagna)
        self.lasagna=lasagna

        self.pluginShortName="ARA explorer"
        self.pluginLongName="Allen Reference Atlas explorer"
        self.pluginAuthor="Rob Campbell"


        #Read file locations from preferences file (creating a default file if none exists)
        self.pref_file = lasHelp.getLasagna_prefDir() + 'ARA_plugin_prefs.yml'
        self.prefs = lasHelp.loadAllPreferences(prefFName=self.pref_file,defaultPref=self.defaultPrefs())

        #The last value the mouse hovered over. When this changes, we re-calculate the contour 
        self.lastValue=-1


        #default names of the three files that we need:
        self.atlasFileName = 'atlas'
        self.templateFileName = 'template'
        self.labelsFileName = 'labels'

        #The root node index of the ARA
        self.rootNode=8  

        #Warn and quit if there are no paths
        if len(self.prefs['ara_paths'])==0:
           self.warnAndQuit('Please fill in preferences file at<br>%s<br><a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>' % self.pref_file)
           return

        #Set up the UI
        self.setupUi(self)
        self.show()
        self.statusBarName_checkBox.setChecked(self.prefs['enableNameInStatusBar'])
        self.highlightArea_checkBox.setChecked(self.prefs['enableOverlay'])
        
        self.brainArea_itemModel = QtGui.QStandardItemModel(self.brainArea_treeView)
        self.brainArea_treeView.setModel(self.brainArea_itemModel)

        #Link the selections in the tree view to a slot in order to allow highlighting of the selected area
        QtCore.QObject.connect(self.brainArea_treeView.selectionModel(), QtCore.SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.highlightSelectedAreaFromList) 


        #Link signals to slots
        self.araName_comboBox.activated.connect(self.araName_comboBox_slot)
        self.load_pushButton.released.connect(self.load_pushButton_slot)
        self.overlayTemplate_checkBox.stateChanged.connect(self.overlayTemplate_checkBox_slot)

        self.statusBarName_checkBox.stateChanged.connect(self.statusBarName_checkBox_slot)
        self.highlightArea_checkBox.stateChanged.connect(self.highlightArea_checkBox_slot)

        #Loop through all paths and add to combobox.
        self.paths = dict()
        n=1
        for path in self.prefs['ara_paths']:

            if not os.path.exists(path):
                print "%s does not exist. skipping" % path 
                continue

            filesInPath = os.listdir(path) 
            if len(filesInPath)==0:
                print "No files in %s . skipping" % path 
                continue

            pths = dict(atlas='', labels='', template='')
            print "\n %d. Looking for files in directory %s" % (n,path)
            n += 1

            files = os.listdir(path)

            #get the file names
            for thisFile in files:
                if thisFile.startswith(self.atlasFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['atlas'] = os.path.join(path,thisFile)
                    print "Adding atlas file %s" % thisFile
                    break 

            for thisFile in files:
                if thisFile.startswith(self.labelsFileName):
                    pths['labels'] = os.path.join(path,thisFile)
                    print "Adding labels file %s" % thisFile
                    break 

            for thisFile in files:
                if thisFile.startswith(self.templateFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['template'] = os.path.join(path,thisFile)
                    print "Adding template file %s" % thisFile
                    break 


            if len(pths['atlas'])==0 | len(pths['labels'])==0 :
                print 'Skipping empty empty paths entry'
                continue


            #If we're here, this entry should at least have a valid atlas file and a valid labels file

            #We will index the self.paths dictionary by the name of the atlas file as this is also 
            #what will be put into the combobox. 
            atlasDirName = path.split(os.path.sep)[-1]

            #skip if a file with this name already exists
            if self.paths.has_key(atlasDirName):
                print "Skipping as a directory called %s is already in the list" % atlasDirName
                continue


            #Add this ARA to the paths dictionary and to the combobox
            self.paths[atlasDirName] = pths
            self.araName_comboBox.addItem(atlasDirName)


        #blank line
        print ""

        #If we have no paths to ARAs by the end of this, issue an error alertbox and quit
        if len(self.paths)==0:
           self.warnAndQuit('Found no valid paths is preferences file at<br>%s.<br>SEE <a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>' % self.pref_file)
           return

        self.lasagna.removeIngredientByType('imagestack') #remove all image stacks

        #If the user has asked for this, load the first ARA entry automatically
        self.data = dict(currentlyLoadedAtlasName='', currentlyLoadedOverlay='') 

        currentlySelectedARA = str(self.araName_comboBox.itemText(self.araName_comboBox.currentIndex()))
        if self.prefs['loadFirstAtlasOnStartup']:
            print "Auto-Loading " +  currentlySelectedARA
            self.loadARA(currentlySelectedARA)
            self.load_pushButton.setEnabled(False) #disable because the current selection has now been loaded

        #Make a lines ingredient that will house the contours for the currently selected area.
        self.contourName = 'aracontour'
        self.lasagna.addIngredient(objectName=self.contourName, 
                                kind='lines', 
                                data=[])
        self.lasagna.returnIngredientByName(self.contourName).addToPlots() #Add item to all three 2D plots
    def __init__(self,lasagna):
        super(plugin,self).__init__(lasagna)
        self.lasagna=lasagna

        self.pluginShortName="area namer"
        self.pluginLongName="brain area namer"
        self.pluginAuthor="Rob Campbell"


        #Read file locations from preferences file (creating a default file if none exists)
        self.pref_file = lasHelp.getLasagna_prefDir() + 'ARA_plugin_prefs.yml'
        self.prefs = lasHelp.loadAllPreferences(prefFName=self.pref_file,defaultPref=self.defaultPrefs())

        #The last value the mouse hovered over. When this changes, we re-calcualte the contour 
        self.lastValue=-1


        #default names of the three files that we need:
        self.atlasFileName = 'atlas'
        self.labelsFileName = 'labels'

        #The root node index of the ARA
        self.rootNode=8  

        #Warn and quit if there are no paths
        if len(self.prefs['ara_paths'])==0:
           self.warnAndQuit('Please fill in preferences file at<br>%s<br><a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>' % self.pref_file)
           return

        #Set up the UI
        self.setupUi(self)
        self.show()
        self.statusBarName_checkBox.setChecked(self.prefs['enableNameInStatusBar'])
        self.highlightArea_checkBox.setChecked(self.prefs['enableOverlay'])
        

        #Link signals to slots
        self.araName_comboBox.activated.connect(self.araName_comboBox_slot)
        self.loadOrig_pushButton.released.connect(self.loadOrig_pushButton_slot)
        self.loadOther_pushButton.released.connect(self.loadOther_pushButton_slot)

        self.statusBarName_checkBox.stateChanged.connect(self.statusBarName_checkBox_slot)
        self.highlightArea_checkBox.stateChanged.connect(self.highlightArea_checkBox_slot)

        #Loop through all paths and add to combobox.
        self.paths = dict()
        n=1
        for path in self.prefs['ara_paths']:

            if not os.path.exists(path):
                print "%s does not exist. skipping" % path 
                continue

            filesInPath = os.listdir(path) 
            if len(filesInPath)==0:
                print "No files in %s . skipping" % path 
                continue

            pths = dict(atlas='', labels='')
            print "\n %d. Looking for files in directory %s" % (n,path)
            n += 1

            files = os.listdir(path)

            #get the file names
            for thisFile in files:
                if thisFile.startswith(self.atlasFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['atlas'] = os.path.join(path,thisFile)
                    print "Adding atlas file %s" % thisFile
                    break 

            for thisFile in files:
                if thisFile.startswith(self.labelsFileName):
                    pths['labels'] = os.path.join(path,thisFile)
                    print "Adding labels file %s" % thisFile
                    break 


            if len(pths['atlas'])==0 | len(pths['labels'])==0 :
                print 'Skipping empty empty paths entry'
                continue


            #If we're here, this entry should at least have a valid atlas file and a valid labels file

            #We will index the self.paths dictionary by the name of the atlas file as this is also 
            #what will be put into the combobox. 
            atlasDirName = path.split(os.path.sep)[-1]

            #skip if a file with this name already exists
            if self.paths.has_key(atlasDirName):
                print "Skipping as a directory called %s is already in the list" % atlasDirName
                continue


            #Add this ARA to the paths dictionary and to the combobox
            self.paths[atlasDirName] = pths
            self.araName_comboBox.addItem(atlasDirName)


        #blank line
        print ""

        #If we have no paths to ARAs by the end of this, issue an error alertbox and quit
        if len(self.paths)==0:
           self.warnAndQuit('Found no valid paths is preferences file at<br>%s.<br>SEE <a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>' % self.pref_file)
           return

        #If the user has asked for this, load the first ARA entry automatically
        self.data = dict(currentlyLoadedAtlasName='', currentlyLoadedOverlay='', atlas=np.ndarray([])) 

        #Make a lines ingredient that will house the contours for the currently selected area.
        self.addAreaContour() #from ARA_plotter
Example #4
0
    def __init__(self, lasagna):
        super(plugin, self).__init__(lasagna)
        self.lasagna = lasagna

        self.pluginShortName = "area namer"
        self.pluginLongName = "brain area namer"
        self.pluginAuthor = "Rob Campbell"

        #Read file locations from preferences file (creating a default file if none exists)
        self.pref_file = lasHelp.getLasagna_prefDir() + 'ARA_plugin_prefs.yml'
        self.prefs = lasHelp.loadAllPreferences(
            prefFName=self.pref_file, defaultPref=self.defaultPrefs())

        #The last value the mouse hovered over. When this changes, we re-calcualte the contour
        self.lastValue = -1

        #default names of the three files that we need:
        self.atlasFileName = 'atlas'
        self.labelsFileName = 'labels'

        #The root node index of the ARA
        self.rootNode = 8

        #Warn and quit if there are no paths
        if len(self.prefs['ara_paths']) == 0:
            self.warnAndQuit(
                'Please fill in preferences file at<br>%s<br><a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>'
                % self.pref_file)
            return

        #Set up the UI
        self.setupUi(self)
        self.show()
        self.statusBarName_checkBox.setChecked(
            self.prefs['enableNameInStatusBar'])
        self.highlightArea_checkBox.setChecked(self.prefs['enableOverlay'])

        #Link signals to slots
        self.araName_comboBox.activated.connect(self.araName_comboBox_slot)
        self.loadOrig_pushButton.released.connect(
            self.loadOrig_pushButton_slot)
        self.loadOther_pushButton.released.connect(
            self.loadOther_pushButton_slot)

        self.statusBarName_checkBox.stateChanged.connect(
            self.statusBarName_checkBox_slot)
        self.highlightArea_checkBox.stateChanged.connect(
            self.highlightArea_checkBox_slot)

        #Loop through all paths and add to combobox.
        self.paths = dict()
        n = 1
        for path in self.prefs['ara_paths']:

            if not os.path.exists(path):
                print "%s does not exist. skipping" % path
                continue

            filesInPath = os.listdir(path)
            if len(filesInPath) == 0:
                print "No files in %s . skipping" % path
                continue

            pths = dict(atlas='', labels='')
            print "\n %d. Looking for files in directory %s" % (n, path)
            n += 1

            files = os.listdir(path)

            #get the file names
            for thisFile in files:
                if thisFile.startswith(self.atlasFileName):
                    if thisFile.endswith('raw'):
                        continue
                    pths['atlas'] = os.path.join(path, thisFile)
                    print "Adding atlas file %s" % thisFile
                    break

            for thisFile in files:
                if thisFile.startswith(self.labelsFileName):
                    pths['labels'] = os.path.join(path, thisFile)
                    print "Adding labels file %s" % thisFile
                    break

            if len(pths['atlas']) == 0 | len(pths['labels']) == 0:
                print 'Skipping empty empty paths entry'
                continue

            #If we're here, this entry should at least have a valid atlas file and a valid labels file

            #We will index the self.paths dictionary by the name of the atlas file as this is also
            #what will be put into the combobox.
            atlasDirName = path.split(os.path.sep)[-1]

            #skip if a file with this name already exists
            if self.paths.has_key(atlasDirName):
                print "Skipping as a directory called %s is already in the list" % atlasDirName
                continue

            #Add this ARA to the paths dictionary and to the combobox
            self.paths[atlasDirName] = pths
            self.araName_comboBox.addItem(atlasDirName)

        #blank line
        print ""

        #If we have no paths to ARAs by the end of this, issue an error alertbox and quit
        if len(self.paths) == 0:
            self.warnAndQuit(
                'Found no valid paths is preferences file at<br>%s.<br>SEE <a href="http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html">http://raacampbell13.github.io/lasagna/ara_explorer_plugin.html</a>'
                % self.pref_file)
            return

        #If the user has asked for this, load the first ARA entry automatically
        self.data = dict(currentlyLoadedAtlasName='',
                         currentlyLoadedOverlay='',
                         atlas=np.ndarray([]))

        #Make a lines ingredient that will house the contours for the currently selected area.
        self.addAreaContour()  #from ARA_plotter