PEATDB/Ekin/Ekin_map.py
def export_as_csv(self):
        """export struct mapping for specific filters as csv"""
        #prompt user for save dir
        savedir = self.choose_savedir()
        if savedir==None:
            return
        if self.currplatform == 'Windows':
            print 'using windows'

        import List_Utils
        #sub function for tidiness
        def getexplist(assignedto):

            reslist={}
            reskeys=[]
            for key in self.structmappings.keys():
                for n in self.structmappings[key].keys():
                    #check if any dataprop list element contains the key eg 'pK' in pK1, pK2 etc..
                    datapropkey = List_Utils.elements_contain(self.structmappings[key][n]['Data property'], self.dataprop.get())
                    if datapropkey != None:
                        #try to extract the value from the ekin dataset
                        val = self.get_dataprop_value(key, datapropkey)
                        print 'found ',val,' for ', datapropkey
                        #print 'val: ', val
                        #iterate over group elements list
                        elements=self.structmappings[key][n]['Group elements']
                        for e in elements:
                            if assignedto in e:
                                reslist[key] = ([key,val])
                                reskeys.append(key)

            if len(reslist.keys())==0:
                return
            #write the list to a csv file, first add heading
            import string
            #remove whitespace
            name=string.join(assignedto.split(), '')
            name=name.replace(':', '')
            if self.currplatform == 'Windows':
                filename = savedir+'/'+name+'.csv'
            else:
                filename = os.path.join(savedir, name+'.csv')
            print filename
            writer = open(filename, "wb")
            writer.write(assignedto+'\n')
            import csv
            csvwriter = csv.writer(open(filename, "a"))
            keyssorted = self.sort_by_Num(reskeys)
            #print reslist
            #print keyssorted
            p=[];names=[]
            #use key sorted mapping to list residues by number
            for item in keyssorted:
                k=item[1]
                csvwriter.writerow(reslist[k])
                p.append(reslist[k][1])
                names.append(k)
            writer.close()
            #do a plot and save to same dir as file
            try:
                import pylab
            except:
                return
            f=pylab.figure(figsize=(10,4))
            pylab.rc("font", family='serif')
            a=f.add_subplot(111)
            ind=numpy.arange(len(names))
            a.bar(ind, p , linewidth=0.5)
            a.set_xticks(ind)
            a.set_ylabel(self.dataprop.get())
            a.set_title(name+' assignments')
            a.set_xticklabels(names, rotation='vertical', size=5)
            f.savefig(savedir+'/'+name+'.png',dpi=300)
            return

        if self.assignedto.get() == 'All':
            for a in self.get_assigned():
                getexplist(a)
        else:
            getexplist(self.assignedto.get())

        self.close_exp_dialog()
        return
export struct mapping for specific filters as csv
export struct mapping for specific filters as csv
export struct mapping for specific filters as csv
def export_as_csv(self):
        savedir = self.choose_savedir()
        if savedir==None:
            return
        if self.currplatform == 'Windows':
            print 'using windows'
        import List_Utils
        def getexplist(assignedto):
            reslist={}
            reskeys=[]
            for key in self.structmappings.keys():
                for n in self.structmappings[key].keys():
                    datapropkey = List_Utils.elements_contain(self.structmappings[key][n]['Data property'], self.dataprop.get())
                    if datapropkey != None:
                        val = self.get_dataprop_value(key, datapropkey)
                        print 'found ',val,' for ', datapropkey
                        elements=self.structmappings[key][n]['Group elements']
                        for e in elements:
                            if assignedto in e:
                                reslist[key] = ([key,val])
                                reskeys.append(key)
            if len(reslist.keys())==0:
                return
            import string
            name=string.join(assignedto.split(), '')
            name=name.replace(':', '')
            if self.currplatform == 'Windows':
                filename = savedir+'/'+name+'.csv'
            else:
                filename = os.path.join(savedir, name+'.csv')
            print filename
            writer = open(filename, "wb")
            writer.write(assignedto+'\n')
            import csv
            csvwriter = csv.writer(open(filename, "a"))
            keyssorted = self.sort_by_Num(reskeys)
            p=[];names=[]
            for item in keyssorted:
                k=item[1]
                csvwriter.writerow(reslist[k])
                p.append(reslist[k][1])
                names.append(k)
            writer.close()
            try:
                import pylab
            except:
                return
            f=pylab.figure(figsize=(10,4))
            pylab.rc("font", family='serif')
            a=f.add_subplot(111)
            ind=numpy.arange(len(names))
            a.bar(ind, p , linewidth=0.5)
            a.set_xticks(ind)
            a.set_ylabel(self.dataprop.get())
            a.set_title(name+' assignments')
            a.set_xticklabels(names, rotation='vertical', size=5)
            f.savefig(savedir+'/'+name+'.png',dpi=300)
            return
        if self.assignedto.get() == 'All':
            for a in self.get_assigned():
                getexplist(a)
        else:
            getexplist(self.assignedto.get())
        self.close_exp_dialog()
        return
def export_as_csv ( self ) : savedir = self . choose_savedir ( ) if savedir == None : return if self . currplatform == 'Windows' : print 'using windows' import List_Utils def getexplist ( assignedto ) : reslist = { } reskeys = [ ] for key in self . structmappings . keys ( ) : for n in self . structmappings [ key ] . keys ( ) : datapropkey = List_Utils . elements_contain ( self . structmappings [ key ] [ n ] [ 'Data property' ] , self . dataprop . get ( ) ) if datapropkey != None : val = self . get_dataprop_value ( key , datapropkey ) print 'found ' , val , ' for ' , datapropkey elements = self . structmappings [ key ] [ n ] [ 'Group elements' ] for e in elements : if assignedto in e : reslist [ key ] = ( [ key , val ] ) reskeys . append ( key ) if len ( reslist . keys ( ) ) == 0 : return import string name = string . join ( assignedto . split ( ) , '' ) name = name . replace ( ':' , '' ) if self . currplatform == 'Windows' : filename = savedir + '/' + name + '.csv' else : filename = os . path . join ( savedir , name + '.csv' ) print filename writer = open ( filename , "wb" ) writer . write ( assignedto + '\n' ) import csv csvwriter = csv . writer ( open ( filename , "a" ) ) keyssorted = self . sort_by_Num ( reskeys ) p = [ ] ; names = [ ] for item in keyssorted : k = item [ 1 ] csvwriter . writerow ( reslist [ k ] ) p . append ( reslist [ k ] [ 1 ] ) names . append ( k ) writer . close ( ) try : import pylab except : return f = pylab . figure ( figsize = ( 10 , 4 ) ) pylab . rc ( "font" , family = 'serif' ) a = f . add_subplot ( 111 ) ind = numpy . arange ( len ( names ) ) a . bar ( ind , p , linewidth = 0.5 ) a . set_xticks ( ind ) a . set_ylabel ( self . dataprop . get ( ) ) a . set_title ( name + ' assignments' ) a . set_xticklabels ( names , rotation = 'vertical' , size = 5 ) f . savefig ( savedir + '/' + name + '.png' , dpi = 300 ) return if self . assignedto . get ( ) == 'All' : for a in self . get_assigned ( ) : getexplist ( a ) else : getexplist ( self . assignedto . get ( ) ) self . close_exp_dialog ( ) return
export struct mapping for specific filters as csv
export struct mapping for specific filters as csv
"""export struct mapping for specific filters as csv""" #prompt user for save dir #sub function for tidiness #check if any dataprop list element contains the key eg 'pK' in pK1, pK2 etc.. #try to extract the value from the ekin dataset #print 'val: ', val #iterate over group elements list #write the list to a csv file, first add heading #remove whitespace #print reslist #print keyssorted #use key sorted mapping to list residues by number #do a plot and save to same dir as file
self