Beispiel #1
0
    def perform(self, event, cfile=None):
        """ Performs the action. """

        logger.info("Performing save connectome file action")

        # helper variable to use this function not only in the menubar
        exec_as_funct = True

        cfile = self.window.application.get_service("cviewer.plugins.cff2.cfile.CFile")

        wildcard = "Connectome File Format v2.0 (*.cff)|*.cff|" "All files (*.*)|*.*"

        dlg = FileDialog(
            wildcard=wildcard,
            title="Save as Connectome File",
            resizeable=False,
            action="save as",
            default_directory=preference_manager.cviewerui.cffpath,
        )

        if dlg.open() == OK:

            if (dlg.paths[0]).endswith(".cff"):

                cfflib.save_to_cff(cfile.obj, dlg.paths[0])
                logger.info("Saved connectome file to %s" % dlg.paths[0])
Beispiel #2
0
    def _run_interface(self, runtime):
        extracted_networks = []

        for i, con in enumerate(self.inputs.in_files):
            mycon = cf.load(con)
            nets = mycon.get_connectome_network()
            for ne in nets:
                # here, you might want to skip networks with a given
                # metadata information
                ne.load()
                contitle = mycon.get_connectome_meta().get_title()
                ne.set_name( str(i) + ': ' + contitle + ' - ' + ne.get_name() )
                ne.set_src(ne.get_name())
                extracted_networks.append(ne)

        # Add networks to new connectome
        newcon = cf.connectome(title = 'All CNetworks', connectome_network = extracted_networks)
        # Setting additional metadata
        metadata = newcon.get_connectome_meta()
        metadata.set_creator('My Name')
        metadata.set_email('My Email')

        _, name, ext = split_filename(self.inputs.out_file)
        if not ext == '.cff':
            ext = '.cff'
        cf.save_to_cff(newcon, op.abspath(name + ext))

        return runtime
Beispiel #3
0
def create_new_version(old_cff_path, temp_folder, new_cff_path):
    """
    Given a cff file path load the cff object, store the new network data and save to a new cff file
    :param old_cff_path: path to cff file from version 1.1
    :param temp_folder: path to folder where intermediate results are stored
    :param new_cff_path: path where new cff file is stored
    """
    cff_obj = load(old_cff_path)
    networks = cff_obj.get_connectome_network()
    if networks:
        for net in networks:
            net.data = _build_and_store_new_graph(temp_folder, name=net.name)
            tmpdir = tempfile.gettempdir()
            net.tmpsrc = tmpdir + "\\cff_data"
    save_to_cff(cff_obj, new_cff_path)
    shutil.rmtree(temp_folder)
    def perform(self, event, cfile=None):
        """ Performs the action. """

        logger.info('Performing save connectome file action')

        # helper variable to use this function not only in the menubar
        exec_as_funct = True

        cfile = self.window.application.get_service(
            'cviewer.plugins.cff2.cfile.CFile')

        wildcard = "Connectome File Format v2.0 (*.cff)|*.cff|" \
                    "All files (*.*)|*.*"

        dlg = FileDialog(wildcard=wildcard,title="Save as Connectome File",\
                         resizeable=False, action = 'save as',\
                         default_directory=preference_manager.cviewerui.cffpath,)

        if dlg.open() == OK:

            if (dlg.paths[0]).endswith('.cff'):

                cfflib.save_to_cff(cfile.obj, dlg.paths[0])
                logger.info("Saved connectome file to %s" % dlg.paths[0])
Beispiel #5
0
    def _run_interface(self, runtime):
        a = cf.connectome()

        if isdefined(self.inputs.title):
            a.connectome_meta.set_title(self.inputs.title)
        else:
            a.connectome_meta.set_title(self.inputs.out_file)

        if isdefined(self.inputs.creator):
            a.connectome_meta.set_creator(self.inputs.creator)
        else:
            #Probably only works on some OSes...
            a.connectome_meta.set_creator(os.getenv('USER'))

        if isdefined(self.inputs.email):
            a.connectome_meta.set_email(self.inputs.email)

        if isdefined(self.inputs.publisher):
            a.connectome_meta.set_publisher(self.inputs.publisher)

        if isdefined(self.inputs.license):
            a.connectome_meta.set_license(self.inputs.license)

        if isdefined(self.inputs.rights):
            a.connectome_meta.set_rights(self.inputs.rights)

        if isdefined(self.inputs.references):
            a.connectome_meta.set_references(self.inputs.references)

        if isdefined(self.inputs.relation):
            a.connectome_meta.set_relation(self.inputs.relation)

        if isdefined(self.inputs.species):
            a.connectome_meta.set_species(self.inputs.species)

        if isdefined(self.inputs.description):
            a.connectome_meta.set_description(self.inputs.description)

        a.connectome_meta.set_created(datetime.date.today())

        count = 0
        if isdefined(self.inputs.graphml_networks):
            for ntwk in self.inputs.graphml_networks:
                # There must be a better way to deal with the unique name problem
                #(i.e. tracks and networks can't use the same name, and previously we were pulling them both from the input files)
                ntwk_name = 'Network {cnt}'.format(cnt=count)
                a.add_connectome_network_from_graphml(ntwk_name, ntwk)
                count += 1

        if isdefined(self.inputs.gpickled_networks):
            unpickled = []
            for ntwk in self.inputs.gpickled_networks:
                _, ntwk_name, _ = split_filename(ntwk)
                unpickled = nx.read_gpickle(ntwk)
                cnet = cf.CNetwork(name = ntwk_name)
                cnet.set_with_nxgraph(unpickled)
                a.add_connectome_network(cnet)
                count += 1

        count = 0
        if isdefined(self.inputs.tract_files):
            for trk in self.inputs.tract_files:
                _, trk_name, _ = split_filename(trk)
                ctrack = cf.CTrack(trk_name, trk)
                a.add_connectome_track(ctrack)
                count += 1

        count = 0
        if isdefined(self.inputs.gifti_surfaces):
            for surf in self.inputs.gifti_surfaces:
                _, surf_name, _ = split_filename(surf)
                csurf = cf.CSurface.create_from_gifti("Surface %d - %s" % (count,surf_name), surf)
                csurf.fileformat='Gifti'
                csurf.dtype='Surfaceset'
                a.add_connectome_surface(csurf)
                count += 1

        count = 0
        if isdefined(self.inputs.gifti_labels):
            for label in self.inputs.gifti_labels:
                _, label_name, _ = split_filename(label)
                csurf = cf.CSurface.create_from_gifti("Surface Label %d - %s" % (count,label_name), label)
                csurf.fileformat='Gifti'
                csurf.dtype='Labels'
                a.add_connectome_surface(csurf)
                count += 1

        if isdefined(self.inputs.nifti_volumes):
            for vol in self.inputs.nifti_volumes:
                _, vol_name, _ = split_filename(vol)
                cvol = cf.CVolume.create_from_nifti(vol_name,vol)
                a.add_connectome_volume(cvol)

        if isdefined(self.inputs.script_files):
            for script in self.inputs.script_files:
                _, script_name, _ = split_filename(script)
                cscript = cf.CScript.create_from_file(script_name, script)
                a.add_connectome_script(cscript)

        if isdefined(self.inputs.data_files):
            for data in self.inputs.data_files:
                _, data_name, _ = split_filename(data)
                cda = cf.CData(name=data_name, src=data, fileformat='NumPy')
                if not string.find(data_name,'lengths') == -1:
                    cda.dtype = 'FinalFiberLengthArray'
                if not string.find(data_name,'endpoints') == -1:
                    cda.dtype = 'FiberEndpoints'
                if not string.find(data_name,'labels') == -1:
                    cda.dtype = 'FinalFiberLabels'
                a.add_connectome_data(cda)

        a.print_summary()
        _, name, ext = split_filename(self.inputs.out_file)
        if not ext == '.cff':
            ext = '.cff'
        cf.save_to_cff(a,op.abspath(name + ext))

        return runtime
Beispiel #6
0
def convert2cff():
    
    # filename from metadata name
    # define path in folder structure, maybe root
    
    outputcff = op.join(gconf.get_cffdir(), '%s_%s.cff' % (gconf.subject_name, gconf.subject_timepoint))
    
    c = cf.connectome()
    
    # creating metadata
    c.connectome_meta.set_title('%s - %s' % (gconf.subject_name, gconf.subject_timepoint) )
    c.connectome_meta.set_creator(gconf.creator)
    c.connectome_meta.set_email(gconf.email)
    c.connectome_meta.set_publisher(gconf.publisher)
    c.connectome_meta.set_created(gconf.created)
    c.connectome_meta.set_modified(gconf.modified)
    c.connectome_meta.set_license(gconf.license)
    c.connectome_meta.set_rights(gconf.rights)
    c.connectome_meta.set_references(gconf.reference)
    c.connectome_meta.set_relation(gconf.relation)
    c.connectome_meta.set_species(gconf.species)
    c.connectome_meta.set_description(gconf.description)

    mydict = {}
    for ele in gconf.subject_metadata:
        if str(ele.key) == "":
            continue
        mydict[str(ele.key)] = str(ele.value)
        
    mydict['subject_name'] = gconf.subject_name
    mydict['subject_timepoint'] = gconf.subject_timepoint
    mydict['subject_workingdir'] = gconf.subject_workingdir
    c.connectome_meta.update_metadata(mydict)

    # XXX: depending on what was checked
    if gconf.cff_fullnetworkpickle:
        # adding networks
        add_networks2connectome(c)
        
    if gconf.cff_originalfibers:
        add_fibersoriginal2connectome(c)
        
    if gconf.cff_filteredfibers:
        add_fibers2connectome(c)

    if gconf.cff_finalfiberlabels:
        add_finaltractandlabels(c)
        
    if gconf.cff_fiberarr:
        add_fiberarr2connectome(c)
        
    if gconf.cff_rawdiffusion:
        add_raw2connectome(c, 'rawdiffusion')
        
    if gconf.cff_rawT1:
        add_raw2connectome(c, 'rawT1')
        
    if gconf.cff_rawT2:
        add_raw2connectome(c, 'rawT2')
    
    if gconf.cff_scalars:
        add_scalars2connectome(c, 'gfa')
        add_scalars2connectome(c, 'skewness')
        add_scalars2connectome(c, 'kurtosis')
        add_scalars2connectome(c, 'P0')
    
    if gconf.cff_roisegmentation:
        add_roiseg2connectome(c)    
    
    if gconf.cff_surfaces:
        add_surfaces2connectome(c)
    
    cf.save_to_cff(c,outputcff)
Beispiel #7
0
# and produces a new connectome file containing only the requested
# connectome object types. The new connectome object names are composed
# of the originial connectome file title and the original connectome
# object name

import cfflib as cf

original_connectomes = ['myconnectome1.cff', 'myconnectome2.cff']

extracted_networks = []

for i, con in enumerate(original_connectomes):
    mycon = cf.load(con)
    nets = mycon.get_connectome_network()
    for ne in nets:
        # here, you might want to skip networks with a given
        # metadata information
        ne.load()
        contitle = mycon.get_connectome_meta().get_title()
        ne.set_name(str(i) + ': ' + contitle + ' - ' + ne.get_name())
        extracted_networks.append(ne)

# add networks to new connectome
newcon = cf.connectome(title='All CNetworks',
                       connectome_network=extracted_networks)
# Setting additional metadata
metadata = newcon.get_connectome_meta()
metadata.set_creator('My Name')
metadata.set_email('My Email')
cf.save_to_cff(newcon, 'merged_cnetworks.cff')
# This script takes a set of compressed connectome files .cff
# and produces a new connectome file containing only the requested
# connectome object types. The new connectome object names are composed
# of the originial connectome file title and the original connectome
# object name

import cfflib as cf

original_connectomes = ['myconnectome1.cff', 'myconnectome2.cff']

extracted_networks = []

for i, con in enumerate(original_connectomes):
    mycon = cf.load(con)
    nets = mycon.get_connectome_network()
    for ne in nets:
        # here, you might want to skip networks with a given
        # metadata information
        ne.load()
        contitle = mycon.get_connectome_meta().get_title()
        ne.set_name( str(i) + ': ' + contitle + ' - ' + ne.get_name() )
        extracted_networks.append(ne)

# add networks to new connectome
newcon = cf.connectome(title = 'All CNetworks', connectome_network = extracted_networks )
# Setting additional metadata
metadata = newcon.get_connectome_meta()
metadata.set_creator('My Name')
metadata.set_email('My Email')
cf.save_to_cff(newcon, 'merged_cnetworks.cff')