def _get_path_assembly_mapping_data(
        self, source_assembly, target_assembly, retries=10
    ):
        """ Get local path to assembly mapping data, downloading if necessary.

        Parameters
        ----------
        source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
            assembly to remap from
        target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
            assembly to remap to
        retries : int
            number of retries per chromosome to download assembly mapping data

        Returns
        -------
        str
            path to <source_assembly>_<target_assembly>.tar.gz

        References
        ----------
        ..[1] Ensembl, Assembly Information Endpoint,
          https://rest.ensembl.org/documentation/info/assembly_info
        ..[2] Ensembl, Assembly Map Endpoint,
          http://rest.ensembl.org/documentation/info/assembly_map

        """

        if not lineage.create_dir(self._resources_dir):
            return None

        chroms = [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10",
            "11",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "21",
            "22",
            "X",
            "Y",
            "MT",
        ]

        assembly_mapping_data = source_assembly + "_" + target_assembly
        destination = os.path.join(
            self._resources_dir, assembly_mapping_data + ".tar.gz"
        )

        if not os.path.exists(destination) or not self._all_chroms_in_tar(
            chroms, destination
        ):
            print("Downloading {}".format(os.path.relpath(destination)))

            try:
                with tarfile.open(destination, "w:gz") as out_tar:
                    for chrom in chroms:
                        file = chrom + ".json"

                        map_endpoint = (
                            "/map/human/"
                            + source_assembly
                            + "/"
                            + chrom
                            + "/"
                            + target_assembly
                            + "?"
                        )

                        # get assembly mapping data
                        response = None
                        retry = 0
                        while response is None and retry < retries:
                            response = self._ensembl_rest_client.perform_rest_action(
                                map_endpoint
                            )
                            retry += 1

                        if response is not None:
                            # open temp file, save json response to file, close temp file
                            with tempfile.NamedTemporaryFile(
                                delete=False, mode="w"
                            ) as f:
                                json.dump(response, f)

                            # add temp file to archive
                            out_tar.add(f.name, arcname=file)

                            # remove temp file
                            os.remove(f.name)
            except Exception as err:
                print(err)
                return None

        return destination
def _get_path_assembly_mapping_data ( self , source_assembly , target_assembly , retries = 10 ) : if not lineage . create_dir ( self . _resources_dir ) : return None chroms = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" , "21" , "22" , "X" , "Y" , "MT" , ] assembly_mapping_data = source_assembly + "_" + target_assembly destination = os . path . join ( self . _resources_dir , assembly_mapping_data + ".tar.gz" ) if not os . path . exists ( destination ) or not self . _all_chroms_in_tar ( chroms , destination ) : print ( "Downloading {}" . format ( os . path . relpath ( destination ) ) ) try : with tarfile . open ( destination , "w:gz" ) as out_tar : for chrom in chroms : file = chrom + ".json" map_endpoint = ( "/map/human/" + source_assembly + "/" + chrom + "/" + target_assembly + "?" ) response = None retry = 0 while response is None and retry < retries : response = self . _ensembl_rest_client . perform_rest_action ( map_endpoint ) retry += 1 if response is not None : with tempfile . NamedTemporaryFile ( delete = False , mode = "w" ) as f : json . dump ( response , f ) out_tar . add ( f . name , arcname = file ) os . remove ( f . name ) except Exception as err : print ( err ) return None return destination
Get local path to assembly mapping data, downloading if necessary.

        Parameters
        ----------
        source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
            assembly to remap from
        target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
            assembly to remap to
        retries : int
            number of retries per chromosome to download assembly mapping data

        Returns
        -------
        str
            path to <source_assembly>_<target_assembly>.tar.gz

        References
        ----------
        ..[1] Ensembl, Assembly Information Endpoint,
          https://rest.ensembl.org/documentation/info/assembly_info
        ..[2] Ensembl, Assembly Map Endpoint,
          http://rest.ensembl.org/documentation/info/assembly_map