Exemple #1
0
 def _cmdList(self):     ### Sets Attributes from commandline
     '''
     Sets attributes according to commandline parameters:
     - see .__doc__ or run with 'help' option
     '''
     for cmd in self.cmd_list:
         try:
             self._generalCmd(cmd)   ### General Options ### 
             self._forkCmd(cmd)  # Delete if no forking
             ### Class Options (No need for arg if arg = att.lower()) ### 
             #self._cmdRead(cmd,type='str',att='Att',arg='Cmd')  # No need for arg if arg = att.lower()
             self._cmdReadList(cmd,'str',['DBSource','UniField'])   # Normal strings
             #self._cmdReadList(cmd,'path',['Att'])  # String representing directory path 
             self._cmdReadList(cmd,'file',['MITAB'])  # String representing file path
             #self._cmdReadList(cmd,'date',['Att'])  # String representing date YYYY-MM-DD
             self._cmdReadList(cmd,'bool',['AddUni','SpliceVar','Symmetry','UniOnly'])  # True/False Booleans
             #self._cmdReadList(cmd,'int',['Att'])   # Integers
             #self._cmdReadList(cmd,'float',['Att']) # Floats
             #self._cmdReadList(cmd,'min',['Att'])   # Integer value part of min,max command
             #self._cmdReadList(cmd,'max',['Att'])   # Integer value part of min,max command
             self._cmdReadList(cmd,'list',['Complex','IDField','MapDB','MethodField','TaxaField','TypeField'])  # List of strings (split on commas or file lines)
             #self._cmdReadList(cmd,'clist',['Att']) # Comma separated list as a *string* (self.str)
             #self._cmdReadList(cmd,'glist',['Att']) # List of files using wildcards and glob
             #self._cmdReadList(cmd,'cdict',['Att']) # Splits comma separated X:Y pairs into dictionary
             #self._cmdReadList(cmd,'cdictlist',['Att']) # As cdict but also enters keys into list
         except: self.errorLog('Problem with cmd:%s' % cmd)
     self.list['MapDB'] = rje.listLower(self.list['MapDB'])
     self.list['Complex'] = rje.listLower(self.list['Complex'])
Exemple #2
0
 def _cmdList(self):     ### Sets Attributes from commandline
     '''
     Sets attributes according to commandline parameters:
     - see .__doc__ or run with 'help' option
     '''
     for cmd in self.cmd_list:
         try:
             self._generalCmd(cmd)   ### General Options ### 
             self._forkCmd(cmd)  # Delete if no forking
             ### Class Options (No need for arg if arg = att.lower()) ### 
             #self._cmdRead(cmd,type='str',att='Att',arg='Cmd')  # No need for arg if arg = att.lower()
             self._cmdReadList(cmd.lower(),'str',['PeptAlign','PeptDis','PeptCluster','OutMatrix'])   # Normal strings
             #self._cmdReadList(cmd,'path',['Att'])  # String representing directory path 
             self._cmdReadList(cmd,'file',['AAProp','AADis','Peptides','SaveDis','SaveTree'])  # String representing file path 
             self._cmdReadList(cmd,'bool',['Termini'])  # True/False Booleans
             self._cmdReadList(cmd,'int',['MaxGapVar','MaxGapX'])   # Integers
             #self._cmdReadList(cmd,'float',['Att']) # Floats
             #self._cmdReadList(cmd,'min',['Att'])   # Integer value part of min,max command
             #self._cmdReadList(cmd,'max',['Att'])   # Integer value part of min,max command
             self._cmdReadList(cmd,'list',['Peptides','TreeFormats'])  # List of strings (split on commas or file lines)
             #self._cmdReadList(cmd,'clist',['Att']) # Comma separated list as a *string* (self.str)
             #self._cmdReadList(cmd,'glist',['Att']) # List of files using wildcards and glob
             #self._cmdReadList(cmd,'cdict',['Att']) # Splits comma separated X:Y pairs into dictionary
             #self._cmdReadList(cmd,'cdictlist',['Att']) # As cdict but also enters keys into list
         except: self.errorLog('Problem with cmd:%s' % cmd)
     if not self.list['Peptides']: self._cmdRead('peptides=peptides.txt','list','Peptides')
     if self.getStrUC('PeptAlign') in ['F','FALSE']: self.setStr({'PeptAlign':''})
     self.list['TreeFormats'] = rje.listLower(self.list['TreeFormats'])
Exemple #3
0
    def setup(self):    ### Main class setup method.
        '''Main class setup method.'''
        try:### ~ [1] Setup Objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###
            if not self.getStrLC('DBSource'): self.setStr({'DBSource':string.split(rje.stripPath(self.getStr('MITAB')),'.')[0]})
            if not self.obj['DB']: self.obj['DB'] = rje_db.Database(self.log,self.cmd_list)
            pdb = self.db('pairwise',add=False)
            pfields = ['#','Hub','Spoke','HubUni','SpokeUni','HubTaxID','SpokeTaxID','Evidence','IType']
            if not pdb: self.db().addEmptyTable('pairwise',pfields,['#'],log=True)
            if not self.obj['XRef']:
                xcmd = ['mapfields=Gene,%s,Secondary,Ensembl,Aliases,Accessions,RefSeq,Previous Symbols,Synonyms' % self.getStr('UniField')]
                self.obj['XRef'] = rje_xref.XRef(self.log,xcmd+self.cmd_list)
                self.obj['XRef'].setup()
            skip_comments = True
            for field in self.list['IDField']:
                if field[:1] == '#': skip_comments = False
            if self.list['MapDB'] and 'uniprotkb' not in self.list['MapDB']:
                self.list['MapDB'].append('uniprotkb')
                self.printLog('#MAP','uniprotkb added to MapDB list.')
            elif not self.list['MapDB']: self.printLog('#MAP','No MapDB list: will attempt to match all IDs to xref KeyID "%s".' % self.obj['XRef'].getStr('KeyID'))
            ### ~ [2] Setup MITAB File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###
            self.open('MITAB')
            if not self.file['MITAB']: raise IOError
            self.printLog('#MITAB','Parse PPI from %s.' % self.getStr('MITAB'))
            ## ~ [2a] MITAB file headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
            headers = []
            while not headers:
                self.list['Headers'] = headers = self.readDelimit('MITAB')
                if not headers: break
                if headers[0][:1] == '#' and skip_comments: headers = []; continue
            #self.debug(headers)
            ## ~ [2b] IDField headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
            idfields = []
            for hfield in headers:
                #self.bugPrint(hfield.upper())
                for idfield in rje.sortUnique(self.list['IDField'])[0:]:
                    idfield = string.replace(idfield.upper(),'(','\(')
                    idfield = string.replace(idfield,')','\)')
                    idmatch = rje.matchExp('^(%s\s?[AB])$' % idfield.upper(),hfield.upper())
                    if not idmatch: idmatch = rje.matchExp('^(%s\s?[AB]) \(\S+\)$' % idfield.upper(),hfield.upper())
                    if idmatch and hfield not in idfields:
                        idfields.append(hfield)
                        self.printLog('#ID','IDField: %s' % hfield)
                        #self.bugPrint(idfields)
                        break
            #self.debug(idfields)
            self.list['IDField'] = idfields
            if not self.list['IDField']: raise ValueError('No IDField found in MITAB headers.')
            ## ~ [2c] TaxaField headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
            taxafields = []
            for tfield in self.list['TaxaField'][0:]:
                for hfield in headers:
                    tmatch = rje.matchExp('^(%s\s?[AB])$' % tfield.upper(),hfield.upper())
                    if not tmatch: tmatch = rje.matchExp('^(%s\s?[AB]) \(\S+\)$' % tfield.upper(),hfield.upper())
                    if tmatch and hfield not in taxafields:
                        taxafields.append(hfield)
                        self.printLog('#TAX','TaxaField: %s' % hfield)
            self.list['TaxaField'] = taxafields
            if not self.list['TaxaField']: self.warnLog('No TaxaField found in MITAB headers.',quitchoice=True)
            ## ~ [2d] TypeField headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
            methfields = []
            lctypes = rje.listLower(self.list['MethodField'])
            for hfield in headers:
                if hfield.lower() in lctypes:
                    methfields.append(hfield)
                    self.printLog('#METH','MethodField: %s' % hfield)
            self.list['MethodField'] = methfields
            if not self.list['MethodField']: self.warnLog('No MethodField found in MITAB headers.',quitchoice=True)
            ## ~ [2e] TypeField headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
            typefields = []
            lctypes = rje.listLower(self.list['TypeField'])
            for hfield in headers:
                if hfield.lower() in lctypes:
                    typefields.append(hfield)
                    self.printLog('#TYPE','TypeField: %s' % hfield)
            self.list['TypeField'] = typefields
            if not self.list['TypeField']: self.warnLog('No TypeField found in MITAB headers.',quitchoice=True)

            return True     # Setup successful
        except: self.errorLog('Problem during %s setup.' % self.prog()); return False  # Setup failed