本文整理汇总了Python中frozendict.frozendict方法的典型用法代码示例。如果您正苦于以下问题:Python frozendict.frozendict方法的具体用法?Python frozendict.frozendict怎么用?Python frozendict.frozendict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frozendict
的用法示例。
在下文中一共展示了frozendict.frozendict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _default
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def _default(obj):
if type(obj) is frozendict:
# fishing the protected dict out of the object is a bit nasty,
# but we don't really want the overhead of copying the dict.
return obj._dict
raise TypeError('Object of type %s is not JSON serializable' %
obj.__class__.__name__)
# ideally we'd set ensure_ascii=False, but the ensure_ascii codepath is so
# much quicker (assuming c speedups are enabled) that it's actually much
# quicker to let it do that and then substitute back (it's about 2.5x faster).
#
# (in any case, simplejson's ensure_ascii doesn't get U+2028 and U+2029 right,
# as per https://github.com/simplejson/simplejson/issues/206).
#
示例2: get_args
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def get_args(pipeline_args):
args = tools.misc.HashableNamespace()
args.genomes = list(pipeline_args.target_genomes) + [pipeline_args.ref_genome]
args.out_dir = os.path.join(pipeline_args.out_dir, 'assemblyHub')
args.hub_txt = os.path.join(args.out_dir, 'hub.txt')
args.genomes_txt = os.path.join(args.out_dir, 'genomes.txt')
args.groups_txt = os.path.join(args.out_dir, 'groups.txt')
genome_files = frozendict({genome: GenomeFiles.get_args(pipeline_args, genome) for genome in args.genomes})
sizes = {}
twobits = {}
trackdbs = {}
for genome, genome_file in genome_files.items():
sizes[genome] = (genome_file.sizes, os.path.join(args.out_dir, genome, 'chrom.sizes'))
twobits[genome] = (genome_file.two_bit, os.path.join(args.out_dir, genome, '{}.2bit'.format(genome)))
trackdbs[genome] = os.path.join(args.out_dir, genome, 'trackDb.txt')
args.sizes = frozendict(sizes)
args.twobits = frozendict(twobits)
args.trackdbs = frozendict(trackdbs)
args.hal = os.path.join(args.out_dir, os.path.basename(pipeline_args.hal))
return args
示例3: definitions
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def definitions(self) -> Dict[str, GraphOutput]:
"""
Property returns definitions of the output ports by extracting them on the fly from the bound outputs.
..info:
This property actually returns a FrozenDict containing port definitions to indicate that
port definitions SHOULD not be used during the actual binding.
Returns:
Dictionary of neural types associated with bound outputs.
"""
# Get the right output dictionary.
d = self._manual_outputs if len(self._manual_outputs) > 0 else self._default_outputs
# Extract port definitions (Neural Types) and return an immutable dictionary,
# so the user won't be able to modify its content by an accident!
return frozendict({k: v.ntype for k, v in d.items()})
示例4: tensors
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def tensors(self) -> Dict[str, "NmTensor"]:
"""
Property returns output tensors by extracting them on the fly from the bound outputs.
Returns:
Dictionary of tensors in the format (output-name: tensor).
"""
# Get the right output dictionary.
d = self._manual_outputs if len(self._manual_outputs) > 0 else self._default_outputs
output_tensors = {}
# Get tensors by acessing the producer-ports.
# At that point all keys (k) are unigue - we made sure of that during binding/__setitem__.
for k, v in d.items():
producer_step = v.producer_step_module_port.step_number
producer_port_name = v.producer_step_module_port.port_name
# Find the right output tensor.
tensor = self._tensors_ref[producer_step][producer_port_name]
# Add it to the dictionary.
output_tensors[k] = tensor
# Return the result as an immutable dictionary,
# so the user won't be able to modify its content by an accident!
return frozendict(output_tensors)
示例5: _get_options
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def _get_options(self, safe=False):
options = itertools.chain(
(
(
safe and option.safe_name or option.name or attr,
getattr(self, attr),
)
for attr, option in
(self._safe_options if safe else self._options).items()
),
(self._other_safe_options if safe else self._other_options).items(),
)
evaluated_options = (
(option, value(self) if callable(value) else value)
for option, value in options
)
return frozendict(
(option, value)
for option, value in evaluated_options
if value is not None
)
示例6: update_options
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def update_options(self):
options = itertools.chain(
(
(option, value)
for option, value in self._update_options.items()
),
self._other_options.items(),
)
evaluated_options = (
(option, value(self) if callable(value) else value)
for option, value in options
)
return frozendict(
(
(option, value)
for option, value in evaluated_options
if value is not None
),
args=self.cmd,
)
示例7: test_frozen_dict
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def test_frozen_dict(self):
self.assertEqual(
encode_canonical_json(frozendict({"a": 1})),
b'{"a":1}',
)
self.assertEqual(
encode_pretty_printed_json(frozendict({"a": 1})),
b'{\n "a": 1\n}')
示例8: get_databases
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def get_databases(pipeline_args):
"""wrapper for get_database() that provides all of the databases"""
dbs = {genome: PipelineTask.get_database(pipeline_args, genome) for genome in pipeline_args.hal_genomes}
return frozendict(dbs)
示例9: convert
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def convert(genes):
# Genes supplied as dictionary.
if isinstance(genes, Mapping):
return frozendict(genes)
# Genes supplied as iterable of (gene, weight) tuples.
elif isinstance(genes, Iterable) and all(isinstance(n, tuple) for n in genes):
return frozendict(genes)
# Genes supplied as iterable of genes.
elif isinstance(genes, Iterable) and all(isinstance(n, str) for n in genes):
return frozendict(zip(genes, repeat(1.0)))
示例10: union
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def union(self, other: Type['GeneSignature']) -> Type['GeneSignature']:
"""
Creates a new :class:`GeneSignature` instance which is the union of this signature and the other supplied
signature.
The weight associated with the genes in the intersection is the maximum of the weights in the composing signatures.
:param other: The other :class:`GeneSignature`.
:return: the new :class:`GeneSignature` instance.
"""
return self.copy(name="({} | {})".format(self.name, other.name) if self.name != other.name else self.name,
gene2weight=frozendict(merge_with(max, self.gene2weight, other.gene2weight)))
示例11: difference
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def difference(self, other: Type['GeneSignature']) -> Type['GeneSignature']:
"""
Creates a new :class:`GeneSignature` instance which is the difference of this signature and the supplied other
signature.
The weight associated with the genes in the difference are taken from this gene signature.
:param other: The other :class:`GeneSignature`.
:return: the new :class:`GeneSignature` instance.
"""
return self.copy(name="({} - {})".format(self.name, other.name) if self.name != other.name else self.name,
gene2weight=frozendict(dissoc(dict(self.gene2weight), *other.genes)))
示例12: intersection
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def intersection(self, other: Type['GeneSignature']) -> Type['GeneSignature']:
"""
Creates a new :class:`GeneSignature` instance which is the intersection of this signature and the supplied other
signature.
The weight associated with the genes in the intersection is the maximum of the weights in the composing signatures.
:param other: The other :class:`GeneSignature`.
:return: the new :class:`GeneSignature` instance.
"""
genes = set(self.gene2weight.keys()).intersection(set(other.gene2weight.keys()))
return self.copy(name="({} & {})".format(self.name, other.name) if self.name != other.name else self.name,
gene2weight=frozendict(keyfilter(lambda k: k in genes,
merge_with(max, self.gene2weight, other.gene2weight))))
示例13: test_frozendict_init_write_once
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def test_frozendict_init_write_once():
odict = OrderedDict()
odict['test'] = 'best value ever'
obj.popsicle = odict
assert isinstance(obj.popsicle, frozendict)
assert obj.popsicle is not None
assert 'test' in obj.popsicle
assert obj.popsicle['test'] == 'best value ever'
示例14: validate
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def validate(self, obj, value):
return frozendict(super().validate(obj, value))
示例15: __init__
# 需要导入模块: import frozendict [as 别名]
# 或者: from frozendict import frozendict [as 别名]
def __init__(self, driver):
self._driver = driver
self._available_fx = frozendict(self._load_fx())