def main(inputstructs, inputpdbids):
    """Main function. Calls functions for processing, report generation and visualization."""
    pdbid, pdbpath = None, None
    # #@todo For multiprocessing, implement better stacktracing for errors
    # Print title and version
    title = "* Protein-Ligand Interaction Profiler v%s *" % __version__
    write_message('\n' + '*' * len(title) + '\n')
    write_message(title)
    write_message('\n' + '*' * len(title) + '\n\n')
    outputprefix = config.OUTPUTFILENAME

    if inputstructs is not None:  # Process PDB file(s)
        num_structures = len(inputstructs)
        inputstructs = remove_duplicates(inputstructs)
        read_from_stdin = False
        for inputstruct in inputstructs:
            if inputstruct == '-':
                inputstruct = sys.stdin.read()
                read_from_stdin = True
                if config.RAWSTRING:
                    if sys.version_info < (3,):
                        inputstruct = bytes(inputstruct).decode('unicode_escape')
                    else:
                        inputstruct = bytes(inputstruct, 'utf8').decode('unicode_escape')
            else:
                if os.path.getsize(inputstruct) == 0:
                    sysexit(2, 'Empty PDB file\n')  # Exit if input file is empty
                if num_structures > 1:
                    basename = inputstruct.split('.')[-2].split('/')[-1]
                    config.OUTPATH = '/'.join([config.BASEPATH, basename])
                    outputprefix = 'report'
            process_pdb(inputstruct, config.OUTPATH, as_string=read_from_stdin, outputprefix=outputprefix)
    else:  # Try to fetch the current PDB structure(s) directly from the RCBS server
        num_pdbids = len(inputpdbids)
        inputpdbids = remove_duplicates(inputpdbids)
        for inputpdbid in inputpdbids:
            pdbpath, pdbid = download_structure(inputpdbid)
            if num_pdbids > 1:
                config.OUTPATH = '/'.join([config.BASEPATH, pdbid[1:3].upper(), pdbid.upper()])
                outputprefix = 'report'
            process_pdb(pdbpath, config.OUTPATH, outputprefix=outputprefix)

    if (pdbid is not None or inputstructs is not None) and config.BASEPATH is not None:
        if config.BASEPATH in ['.', './']:
            write_message('\nFinished analysis. Find the result files in the working directory.\n\n')
        else:
            write_message('\nFinished analysis. Find the result files in %s\n\n' % config.BASEPATH)
def main ( inputstructs , inputpdbids ) : pdbid , pdbpath = None , None title = "* Protein-Ligand Interaction Profiler v%s *" % __version__ write_message ( '\n' + '*' * len ( title ) + '\n' ) write_message ( title ) write_message ( '\n' + '*' * len ( title ) + '\n\n' ) outputprefix = config . OUTPUTFILENAME if inputstructs is not None : num_structures = len ( inputstructs ) inputstructs = remove_duplicates ( inputstructs ) read_from_stdin = False for inputstruct in inputstructs : if inputstruct == '-' : inputstruct = sys . stdin . read ( ) read_from_stdin = True if config . RAWSTRING : if sys . version_info < ( 3 , ) : inputstruct = bytes ( inputstruct ) . decode ( 'unicode_escape' ) else : inputstruct = bytes ( inputstruct , 'utf8' ) . decode ( 'unicode_escape' ) else : if os . path . getsize ( inputstruct ) == 0 : sysexit ( 2 , 'Empty PDB file\n' ) if num_structures > 1 : basename = inputstruct . split ( '.' ) [ - 2 ] . split ( '/' ) [ - 1 ] config . OUTPATH = '/' . join ( [ config . BASEPATH , basename ] ) outputprefix = 'report' process_pdb ( inputstruct , config . OUTPATH , as_string = read_from_stdin , outputprefix = outputprefix ) else : num_pdbids = len ( inputpdbids ) inputpdbids = remove_duplicates ( inputpdbids ) for inputpdbid in inputpdbids : pdbpath , pdbid = download_structure ( inputpdbid ) if num_pdbids > 1 : config . OUTPATH = '/' . join ( [ config . BASEPATH , pdbid [ 1 : 3 ] . upper ( ) , pdbid . upper ( ) ] ) outputprefix = 'report' process_pdb ( pdbpath , config . OUTPATH , outputprefix = outputprefix ) if ( pdbid is not None or inputstructs is not None ) and config . BASEPATH is not None : if config . BASEPATH in [ '.' , './' ] : write_message ( '\nFinished analysis. Find the result files in the working directory.\n\n' ) else : write_message ( '\nFinished analysis. Find the result files in %s\n\n' % config . BASEPATH )
Main function. Calls functions for processing, report generation and visualization.