Exemplo n.º 1
0
    def get_gi_map(self, gi_map):
        '''download gi_taxid_prot.dmp.gz from ncbi server and extract the complete file'''
        local_version = self.DOWNLOAD_FOLDER + os.sep + gi_map
        # test for actual or existing file
        if not os.path.exists(local_version) or not self.is_actual(self.DOWNLOAD_FOLDER, gi_map):
            try:
                sys.stdout.write("Download %s from %s ...\n" % (gi_map, self.FTP_SERVER))
                # download file
                f = open(local_version, "wb")
                self.get_connection().retrbinary("RETR " + gi_map, f.write)
                f.close()
            except:
                raise FtpDownloadException(gi_map)
        else:
            ActualException(gi_map)

        # extract file, if no extracted content exists
        if not os.path.exists(str.strip(local_version, '.gz')):
            extract_gz(local_version, self.DOWNLOAD_FOLDER)
        return os.path.abspath(str.strip(local_version, '.gz'))
Exemplo n.º 2
0
 def download_file(self, local_folder, item):
     '''download and extract a single file from ftp source'''
     # specify save location
     local_file = local_folder + os.sep + item
     try: 
         # open local file stream
         f = open(local_file, "wb")
         # copy remote stream to local stream
         self.get_connection().retrbinary("RETR " + item, f.write)
         f.close()
     except: 
         raise FtpDownloadException(item)
     # check endings of files for typical compressing endings   
     if is_compressed(local_file):
         # extract *.tgz files
         if is_tgz(local_file):
             extract_tar(local_file, local_folder)
         # unpack gunzip files and ignore *.tar.gz (because of metacv db creation)
         elif is_gz(local_file):
             extract_gz(local_file)
     else: 
         pass
Exemplo n.º 3
0
    def get_idmapping(self, idmapping):
        '''download idmapping.dat.gz from uniprot server and extract the complete file'''
        local_idmapping = self.DOWNLOAD_FOLDER + os.sep + idmapping
        # test for actual or existing file
        if not os.path.exists(local_idmapping) or not self.is_actual(self.DOWNLOAD_FOLDER, idmapping):
            try:
                sys.stdout.write("Download %s from %s ...\n" % (idmapping, self.FTP_SERVER))
                # download file
                f = open(local_idmapping, "wb")
                self.get_connection().retrbinary("RETR " + idmapping, f.write)
                f.close()
            except:
                raise FtpDownloadException(idmapping)
        else:
            ActualException(idmapping)

        # extract file, if no extracted content exists
        if not os.path.exists(str.strip(local_idmapping, '.gz')):
            try:
                extract_gz(local_idmapping, self.DOWNLOAD_FOLDER)
            except:
                raise ExtractionException(idmapping)
        return os.path.abspath(str.strip(local_idmapping, '.gz'))