本文整理汇总了Python中sortedcontainers.SortedDict.copy方法的典型用法代码示例。如果您正苦于以下问题:Python SortedDict.copy方法的具体用法?Python SortedDict.copy怎么用?Python SortedDict.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedDict
的用法示例。
在下文中一共展示了SortedDict.copy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy
# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import copy [as 别名]
def test_copy():
mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
temp = SortedDict(mapping)
dup = temp.copy()
assert len(temp) == 26
dup.clear()
assert len(temp) == 0
示例2: TreePage
# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import copy [as 别名]
#.........这里部分代码省略.........
def replace_mo(self, state, old_mo, new_mo):
start, end = self._resolve_range(old_mo)
for key in self._storage.irange(start, end-1):
val = self._storage[key]
if val is old_mo:
#assert new_mo.includes(a)
self._storage[key] = new_mo
def store_overwrite(self, state, new_mo, start, end):
# iterate over each item we might overwrite
# track our mutations separately since we're in the process of iterating
deletes = []
updates = { start: new_mo }
for key in self._storage.irange(maximum=end-1, reverse=True):
old_mo = self._storage[key]
# make sure we aren't overwriting all of an item that overlaps the end boundary
if end < self._page_addr + self._page_size and end not in updates and old_mo.includes(end):
updates[end] = old_mo
# we can't set a minimum on the range because we need to do the above for
# the first object before start too
if key < start:
break
# delete any key that falls within the range
deletes.append(key)
#assert all(m.includes(i) for i,m in updates.items())
# perform mutations
for key in deletes:
del self._storage[key]
self._storage.update(updates)
def store_underwrite(self, state, new_mo, start, end):
# track the point that we need to write up to
last_missing = end - 1
# track also updates since we can't update while iterating
updates = {}
for key in self._storage.irange(maximum=end-1, reverse=True):
mo = self._storage[key]
# if the mo stops
if mo.base <= last_missing and not mo.includes(last_missing):
updates[max(mo.last_addr+1, start)] = new_mo
last_missing = mo.base - 1
# we can't set a minimum on the range because we need to do the above for
# the first object before start too
if last_missing < start:
break
# if there are no memory objects <= start, we won't have filled start yet
if last_missing >= start:
updates[start] = new_mo
#assert all(m.includes(i) for i,m in updates.items())
self._storage.update(updates)
def load_mo(self, state, page_idx):
"""
Loads a memory object from memory.
:param page_idx: the index into the page
:returns: a tuple of the object
"""
try:
key = next(self._storage.irange(maximum=page_idx, reverse=True))
except StopIteration:
return None
else:
return self._storage[key]
def load_slice(self, state, start, end):
"""
Return the memory objects overlapping with the provided slice.
:param start: the start address
:param end: the end address (non-inclusive)
:returns: tuples of (starting_addr, memory_object)
"""
keys = list(self._storage.irange(start, end-1))
if not keys or keys[0] != start:
try:
key = next(self._storage.irange(maximum=start, reverse=True))
except StopIteration:
pass
else:
if self._storage[key].includes(start):
items.insert(0, key)
return [(key, self._storage[key]) for key in keys]
def _copy_args(self):
return { 'storage': self._storage.copy() }
示例3: check_split_by_blast
# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import copy [as 别名]
def check_split_by_blast(transcript, cds_boundaries):
"""
This method verifies if a transcript with multiple ORFs has support by BLAST to
NOT split it into its different components.
The minimal overlap between ORF and HSP is defined inside the JSON at the key
["chimera_split"]["blast_params"]["minimal_hsp_overlap"]
basically, we consider a HSP a hit only if the overlap is over a certain threshold
and the HSP evalue under a certain threshold.
The split by CDS can be executed in three different ways - PERMISSIVE, LENIENT, STRINGENT:
- PERMISSIVE: split if two CDSs do not have hits in common,
even when one or both do not have a hit at all.
- STRINGENT: split only if two CDSs have hits and none
of those is in common between them.
- LENIENT: split if *both* lack hits, OR *both* have hits and none
of those is in common.
:param transcript: the transcript instance
:type transcript: Mikado.loci_objects.transcript.Transcript
:param cds_boundaries:
:return: cds_boundaries
:rtype: dict
"""
# Establish the minimum overlap between an ORF and a BLAST hit to consider it
# to establish belongingness
minimal_overlap = transcript.json_conf[
"pick"]["chimera_split"]["blast_params"]["minimal_hsp_overlap"]
cds_hit_dict = SortedDict().fromkeys(cds_boundaries.keys())
for key in cds_hit_dict:
cds_hit_dict[key] = collections.defaultdict(list)
# BUG, this is a hacky fix
if not hasattr(transcript, "blast_hits"):
transcript.logger.warning(
"BLAST hits store lost for %s! Creating a mock one to avoid a crash",
transcript.id)
transcript.blast_hits = []
transcript.logger.debug("%s has %d possible hits", transcript.id, len(transcript.blast_hits))
# Determine for each CDS which are the hits available
min_eval = transcript.json_conf["pick"]['chimera_split']['blast_params']['hsp_evalue']
for hit in transcript.blast_hits:
for hsp in iter(_hsp for _hsp in hit["hsps"] if
_hsp["hsp_evalue"] <= min_eval):
for cds_run in cds_boundaries:
# If I have a valid hit b/w the CDS region and the hit,
# add the name to the set
overlap_threshold = minimal_overlap * (cds_run[1] + 1 - cds_run[0])
overl = overlap(cds_run, (hsp['query_hsp_start'], hsp['query_hsp_end']))
if overl >= overlap_threshold:
cds_hit_dict[cds_run][(hit["target"], hit["target_length"])].append(hsp)
transcript.logger.debug(
"Overlap %s passed for %s between %s CDS and %s HSP (threshold %s)",
overlap,
transcript.id,
cds_run,
(hsp['query_hsp_start'], hsp['query_hsp_end']),
overlap_threshold)
else:
transcript.logger.debug(
"Overlap %s rejected for %s between %s CDS and %s HSP (threshold %s)",
overlap,
transcript.id,
cds_run, (hsp['query_hsp_start'], hsp['query_hsp_end']),
overlap_threshold)
transcript.logger.debug("Final cds_hit_dict for %s: %s", transcript.id, cds_hit_dict)
final_boundaries = SortedDict()
for boundary in __get_boundaries_from_blast(transcript, cds_boundaries, cds_hit_dict):
if len(boundary) == 1:
assert len(boundary[0]) == 2
boundary = boundary[0]
final_boundaries[boundary] = cds_boundaries[boundary]
else:
nboun = (boundary[0][0], boundary[-1][1])
final_boundaries[nboun] = []
for boun in boundary:
final_boundaries[nboun].extend(cds_boundaries[boun])
transcript.logger.debug("Final boundaries for %s: %s",
transcript.id, final_boundaries)
cds_boundaries = final_boundaries.copy()
return cds_boundaries
示例4: RegionMap
# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import copy [as 别名]
class RegionMap(object):
"""
Mostly used in SimAbstractMemory, RegionMap stores a series of mappings between concrete memory address ranges and
memory regions, like stack frames and heap regions.
"""
def __init__(self, is_stack):
"""
Constructor
:param is_stack: Whether this is a region map for stack frames or not. Different strategies apply for stack
regions.
"""
self.is_stack = is_stack
# A sorted list, which maps stack addresses to region IDs
self._address_to_region_id = SortedDict()
# A dict, which maps region IDs to memory address ranges
self._region_id_to_address = { }
#
# Properties
#
def __repr__(self):
return "RegionMap<%s>" % (
"S" if self.is_stack else "H"
)
@property
def is_empty(self):
return len(self._address_to_region_id) == 0
@property
def stack_base(self):
if not self.is_stack:
raise SimRegionMapError('Calling "stack_base" on a non-stack region map.')
return next(self._address_to_region_id.irange(reverse=True))
@property
def region_ids(self):
return self._region_id_to_address.keys()
#
# Public methods
#
@SimStatePlugin.memo
def copy(self, memo): # pylint: disable=unused-argument
r = RegionMap(is_stack=self.is_stack)
# A shallow copy should be enough, since we never modify any RegionDescriptor object in-place
r._address_to_region_id = self._address_to_region_id.copy()
r._region_id_to_address = self._region_id_to_address.copy()
return r
def map(self, absolute_address, region_id, related_function_address=None):
"""
Add a mapping between an absolute address and a region ID. If this is a stack region map, all stack regions
beyond (lower than) this newly added regions will be discarded.
:param absolute_address: An absolute memory address.
:param region_id: ID of the memory region.
:param related_function_address: A related function address, mostly used for stack regions.
"""
if self.is_stack:
# Sanity check
if not region_id.startswith('stack_'):
raise SimRegionMapError('Received a non-stack memory ID "%d" in a stack region map' % region_id)
# Remove all stack regions that are lower than the one to add
while True:
try:
addr = next(self._address_to_region_id.irange(maximum=absolute_address, reverse=True))
descriptor = self._address_to_region_id[addr]
# Remove this mapping
del self._address_to_region_id[addr]
# Remove this region ID from the other mapping
del self._region_id_to_address[descriptor.region_id]
except StopIteration:
break
else:
if absolute_address in self._address_to_region_id:
descriptor = self._address_to_region_id[absolute_address]
# Remove this mapping
del self._address_to_region_id[absolute_address]
del self._region_id_to_address[descriptor.region_id]
# Add this new region mapping
desc = RegionDescriptor(
region_id,
absolute_address,
related_function_address=related_function_address
)
self._address_to_region_id[absolute_address] = desc
#.........这里部分代码省略.........