Пример #1
0
 def refresh_cache(self):
     """Will download the required zip files to the cache directory."""
     download_from_url(self.url,
                       self.zip_path,
                       stream=True,
                       progress=True,
                       uncompress=False)
Пример #2
0
    def install(cls, prefix="~/programs/fastQValidator/"):
        """
        To automatically download and install the fastQValidator software
        on this computer and for the current user, type these commands in
        python:

            >>> from fasta.validator import Validator
            >>> Validator.install()
        """
        # Check we are on an OS with aptitude #
        check_apt_exists()
        # Start with the required apt packages #
        get_apt_packages(cls.apt_packages, verbose=True)
        # Download tarball 1 #
        tmp_dir_1 = new_temp_dir()
        tgz_url_1 = 'https://github.com/statgen/libStatGen/archive/master.tar.gz'
        tgz_loc_1 = download_from_url(tgz_url_1,
                                      tmp_dir_1,
                                      stream=True,
                                      progress=True)
        src_dir_1 = tgz_loc_1.untargz_to()
        # Download tarball 2 #
        tmp_dir_2 = new_temp_dir()
        tgz_url_2 = 'https://github.com/statgen/fastQValidator/archive/master.tar.gz'
        tgz_loc_2 = download_from_url(tgz_url_2,
                                      tmp_dir_2,
                                      stream=True,
                                      progress=True)
        src_dir_2 = tgz_loc_2.untargz_to()
        # Uncompressed 1 #
        src_dir_1 = src_dir_1.sub_directory
        # Uncompressed 2 #
        src_dir_2 = src_dir_2.sub_directory
        # Make 1 #
        sh.make('-C', src_dir_1, _out=sys.stdout, _err=sys.stderr)
        # Make 2 #
        sh.make(
            '-C',
            src_dir_2,
            'LIB_PATH_FASTQ_VALIDATOR=%s' % src_dir_1,
            _out=sys.stdout,
            _err=sys.stderr,
        )
        # Move the executable #
        binary = src_dir_2 + 'bin/fastQValidator'
        path = binary.move_to(prefix, overwrite=True)
        # The directory that contains the executable #
        bin_dir = path.directory.with_tilda[:-1].replace('~', '$HOME')
        # Suggest adding to the $PATH #
        print("\n fastQValidator was installed successfully. You should now "
              "add this line to your .bash_profile: \n\n    "
              "export PATH=%s:$PATH\n" % bin_dir)
Пример #3
0
 def prepare(self):
     """Check that the file exists, optionally downloads it.
     Checks that the file is indeed an SQLite3 database.
     Optionally check the MD5."""
     if not os.path.exists(self.path):
         if self.retrieve:
             print("Downloading SQLite3 database...")
             download_from_url(self.retrieve, self.path, progress=True)
         else:
             raise Exception("The file '" + self.path + "' does not exist.")
     self.check_format()
     if self.known_md5: assert self.known_md5 == self.md5
     self.prepared = True
Пример #4
0
 def refresh_cache(self):
     """Will download the required zip files to the cache directory."""
     return download_from_url(self.base_url + self.url_param,
                              self.zip_path,
                              stream=False,
                              progress=False,
                              uncompress=False)
Пример #5
0
    def install(cls, prefix="~/programs/FastQC/"):
        """
        To automatically download and install the FastQC software on this
        computer and for the current user, type these commands in python:

            >>> from fasta.fastqc import FastQC
            >>> FastQC.install()
        """
        # Start with required apt packages #
        get_apt_packages(cls.apt_packages, verbose=True)
        # Make a temporary directory #
        tmp_dir = new_temp_dir()
        # Download tarball #
        zip_loc = download_from_url(cls.zip_url, tmp_dir, stream=True,
                                    progress=True)
        # Uncompress #
        src_dir = zip_loc.unzip_to(prefix, single=False).sub_directory
        # Set executable permissions #
        bin_loc = src_dir + 'fastqc'
        bin_loc.permissions.make_executable()
        # The directory that contains the executable #
        bin_dir = src_dir.with_tilda[:-1].replace('~', '$HOME')
        # Suggest adding to the $PATH #
        print("\nFastQC was installed successfully. You should now "
              "add this line to your .bash_profile: \n\n    "
              "export PATH=%s:$PATH\n" % bin_dir)
Пример #6
0
 def get_one_xls(self, row):
     """Download one xls file and put it in the cache directory."""
     # We are not interested in all countries #
     if row['country'] not in country_codes['country'].values: return
     # Get the matching iso2_code #
     iso2_code = country_codes.query("country == '%s'" % row['country'])
     iso2_code = iso2_code['iso2_code'].iloc[0]
     # The destination directory #
     destination = Path(self.cache_dir + iso2_code + '.xls')
     # Save to disk #
     result = download_from_url(row['xls'], destination, user_agent=None)
     # We don't want to flood the server #
     time.sleep(2)
     # Return #
     return result