예제 #1
0
if __name__ == "__main__":

    import sys

    if len(sys.argv) != 2:
        print("Usage: python MMCIF2Dict filename.")

    filename = sys.argv[1]

    mmcif_dict = MMCIF2Dict(filename)

    entry = ""
    print("Now type a key ('q' to end, 'k' for a list of all keys):")
    while (entry != "q"):
        entry = _input("MMCIF dictionary key ==> ")
        if entry == "q":
            sys.exit()
        if entry == "k":
            for key in mmcif_dict:
                print(key)
            continue
        try:
            value = mmcif_dict[entry]
            if isinstance(value, list):
                for item in value:
                    print(item)
            else:
                print(value)
        except KeyError:
            print("No such key found.")
예제 #2
0
    def lastrebasefile(self):
        """BD.lastrebasefile() -> None.

        Check the emboss files are up to date and download them if they are not.
        """
        embossnames = ('emboss_e', 'emboss_r', 'emboss_s')
        #
        #   first check if we have the last update:
        #
        emboss_now = ['.'.join((x, LocalTime())) for x in embossnames]
        update_needed = False
        # dircontent = os.listdir(config.Rebase) #    local database content
        dircontent = os.listdir(os.getcwd())
        base = os.getcwd()  # added for biopython current directory
        for name in emboss_now:
            if name in dircontent:
                pass
            else:
                update_needed = True

        if not update_needed:
            #
            #   nothing to be done
            #
            print('\n Using the files : %s' % ', '.join(emboss_now))
            return tuple(open(os.path.join(base, n)) for n in emboss_now)
        else:
            #
            #   may be download the files.
            #
            print('\n The rebase files are more than one month old.\
            \n Would you like to update them before proceeding?(y/n)')
            r = _input(' update [n] >>> ')
            if r in ['y', 'yes', 'Y', 'Yes']:
                updt = RebaseUpdate(self.rebase_pass, self.proxy)
                updt.openRebase()
                updt.getfiles()
                updt.close()
                print('\n Update complete. Creating the dictionaries.\n')
                print('\n Using the files : %s' % ', '.join(emboss_now))
                return tuple(open(os.path.join(base, n)) for n in emboss_now)
            else:
                #
                #   we will use the last files found without updating.
                #   But first we check we have some file to use.
                #
                class NotFoundError(Exception):
                    pass
                for name in embossnames:
                    try:
                        for file in dircontent:
                            if file.startswith(name):
                                break
                        else:
                            pass
                        raise NotFoundError
                    except NotFoundError:
                        print("\nNo %s file found. Upgrade is impossible.\n" % name)
                        sys.exit()
                    continue
                pass
        #
        #   now find the last file.
        #
        last = [0]
        for file in dircontent:
            fs = file.split('.')
            try:
                if fs[0] in embossnames and int(fs[1]) > int(last[-1]):
                    if last[0]:
                        last.append(fs[1])
                    else:
                        last[0] = fs[1]
                else:
                    continue
            except ValueError:
                continue
        last.sort()
        last = last[::-1]
        if int(last[-1]) < 100:
            last[0], last[-1] = last[-1], last[0]

        for number in last:
            files = [(name, name + '.%s' % number) for name in embossnames]
            strmess = '\nLast EMBOSS files found are :\n'
            try:
                for name, file in files:
                    if os.path.isfile(os.path.join(base, file)):
                        strmess += '\t%s.\n' % file
                    else:
                        raise ValueError
                print(strmess)
                emboss_e = open(os.path.join(base, 'emboss_e.%s' % number), 'r')
                emboss_r = open(os.path.join(base, 'emboss_r.%s' % number), 'r')
                emboss_s = open(os.path.join(base, 'emboss_s.%s' % number), 'r')
                return emboss_e, emboss_r, emboss_s
            except ValueError:
                continue
예제 #3
0
    def lastrebasefile(self):
        """Check the emboss files are up to date and download them if not."""
        embossnames = ('emboss_e', 'emboss_r', 'emboss_s')
        #
        #   first check if we have the last update:
        #
        emboss_now = ['.'.join((x, LocalTime())) for x in embossnames]
        update_needed = False
        # dircontent = os.listdir(config.Rebase) #    local database content
        dircontent = os.listdir(os.getcwd())
        base = os.getcwd()  # added for biopython current directory
        for name in emboss_now:
            if name in dircontent:
                pass
            else:
                update_needed = True

        if not update_needed:
            #
            #   nothing to be done
            #
            print('\n Using the files : %s' % ', '.join(emboss_now))
            return tuple(open(os.path.join(base, n)) for n in emboss_now)
        else:
            #
            #   may be download the files.
            #
            print('\n The rebase files are more than one month old.\
            \n Would you like to update them before proceeding?(y/n)')
            r = _input(' update [n] >>> ')
            if r in ['y', 'yes', 'Y', 'Yes']:
                updt = RebaseUpdate(self.proxy)
                updt.openRebase()
                updt.getfiles()
                updt.close()
                print('\n Update complete. Creating the dictionaries.\n')
                print('\n Using the files : %s' % ', '.join(emboss_now))
                return tuple(open(os.path.join(base, n)) for n in emboss_now)
            else:
                #
                #   we will use the last files found without updating.
                #   But first we check we have some file to use.
                #
                class NotFoundError(Exception):
                    pass

                for name in embossnames:
                    try:
                        for file in dircontent:
                            if file.startswith(name):
                                break
                        else:
                            pass
                        raise NotFoundError
                    except NotFoundError:
                        print("\nNo %s file found. Upgrade is impossible.\n" %
                              name)
                        sys.exit()
                    continue
                pass
        #
        #   now find the last file.
        #
        last = [0]
        for file in dircontent:
            fs = file.split('.')
            try:
                if fs[0] in embossnames and int(fs[1]) > int(last[-1]):
                    if last[0]:
                        last.append(fs[1])
                    else:
                        last[0] = fs[1]
                else:
                    continue
            except ValueError:
                continue
        last.sort()
        last = last[::-1]
        if int(last[-1]) < 100:
            last[0], last[-1] = last[-1], last[0]

        for number in last:
            files = [(name + '.%s' % number) for name in embossnames]
            strmess = '\nLast EMBOSS files found are :\n'
            try:
                for file in files:
                    if os.path.isfile(os.path.join(base, file)):
                        strmess += '\t%s.\n' % file
                    else:
                        raise ValueError
                print(strmess)
                emboss_e = open(os.path.join(base, 'emboss_e.%s' % number),
                                'r')
                emboss_r = open(os.path.join(base, 'emboss_r.%s' % number),
                                'r')
                emboss_s = open(os.path.join(base, 'emboss_s.%s' % number),
                                'r')
                return emboss_e, emboss_r, emboss_s
            except ValueError:
                continue
예제 #4
0
if __name__=="__main__":

    import sys

    if len(sys.argv)!=2:
        print("Usage: python MMCIF2Dict filename.")

    filename=sys.argv[1]

    mmcif_dict = MMCIF2Dict(filename)

    entry = ""
    print("Now type a key ('q' to end, 'k' for a list of all keys):")
    while(entry != "q"):
        entry = _input("MMCIF dictionary key ==> ")
        if entry == "q":
            sys.exit()
        if entry == "k":
            for key in mmcif_dict:
                print(key)
            continue
        try:
            value=mmcif_dict[entry]
            if isinstance(value, list):
                for item in value:
                    print(item)
            else:
                print(value)
        except KeyError:
            print("No such key found.")