Esempio n. 1
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, release_number)) 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 not in dircontent:
                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 missing or 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"]:
                get_files()
                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:
                            raise NotFoundError
                    except NotFoundError:
                        print(
                            f"\nNo {name} file found. Upgrade is impossible.\n"
                        )
                        sys.exit()
                    continue
        #
        #   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 + f".{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 += f"\t{file}.\n"
                    else:
                        raise ValueError
                print(strmess)
                emboss_e = open(os.path.join(base, f"emboss_e.{number}"))
                emboss_r = open(os.path.join(base, f"emboss_r.{number}"))
                emboss_s = open(os.path.join(base, f"emboss_s.{number}"))
                return emboss_e, emboss_r, emboss_s
            except ValueError:
                continue
Esempio n. 2
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, release_number)) 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 missing or 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']:
                get_files()
                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:
                            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