本文整理汇总了Python中builtins.dict方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.dict方法的具体用法?Python builtins.dict怎么用?Python builtins.dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类builtins
的用法示例。
在下文中一共展示了builtins.dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_file
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def update_file(self, filepath, df, notes=None):
"""
Sets a new DataFrame for the DataFrameModel registered to filepath.
:param filepath (str)
The filepath to the DataFrameModel to be updated
:param df (pandas.DataFrame)
The new DataFrame to register to the model.
:param notes (str, default None)
Optional notes to register along with the update.
"""
assert isinstance(df, pd.DataFrame), "Cannot update file with type '{}'".format(type(df))
self._models[filepath].setDataFrame(df, copyDataFrame=False)
if notes:
update = dict(date=pd.Timestamp(datetime.datetime.now()),
notes=notes)
self._updates[filepath].append(update)
self._paths_updated.append(filepath)
示例2: get_case_lists
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def get_case_lists(study_id):
"""Return a list of the case set ids for a particular study.
TAKE NOTE the "case_list_id" are the same thing as "case_set_id"
Within the data, this string is referred to as a "case_list_id".
Within API calls it is referred to as a 'case_set_id'.
The documentation does not make this explicitly clear.
Parameters
----------
study_id : str
The ID of the cBio study.
Example: 'cellline_ccle_broad' or 'paad_icgc'
Returns
-------
case_set_ids : dict[dict[int]]
A dict keyed to cases containing a dict keyed to genes
containing int
"""
data = {'cmd': 'getCaseLists',
'cancer_study_id': study_id}
df = send_request(**data)
case_set_ids = df['case_list_id'].tolist()
return case_set_ids
示例3: get_protein_refs
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def get_protein_refs(self, hms_lincs_id):
"""Get the refs for a protein from the LINCs protein metadata.
Parameters
----------
hms_lincs_id : str
The HMS LINCS ID for the protein
Returns
-------
dict
A dictionary of protein references.
"""
# TODO: We could get phosphorylation states from the protein data.
refs = {'HMS-LINCS': hms_lincs_id}
entry = self._get_entry_by_id(self._prot_data, hms_lincs_id)
# If there is no entry for this ID
if not entry:
return refs
mappings = dict(egid='Gene ID', up='UniProt ID')
for k, v in mappings.items():
if entry.get(v):
refs[k.upper()] = entry.get(v)
return refs
示例4: get_mutations
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def get_mutations(gene_names, cell_types):
"""Return protein amino acid changes in given genes and cell types.
Parameters
----------
gene_names : list
HGNC gene symbols for which mutations are queried.
cell_types : list
List of cell type names in which mutations are queried.
The cell type names follow the CCLE database conventions.
Example: LOXIMVI_SKIN, BT20_BREAST
Returns
-------
res : dict[dict[list]]
A dictionary keyed by cell line, which contains another dictionary
that is keyed by gene name, with a list of amino acid substitutions
as values.
"""
mutations = cbio_client.get_ccle_mutations(gene_names, cell_types)
return mutations
示例5: send_query
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def send_query(query_dict):
"""Query ChEMBL API
Parameters
----------
query_dict : dict
'query' : string of the endpoint to query
'params' : dict of params for the query
Returns
-------
js : dict
dict parsed from json that is unique to the submitted query
"""
query = query_dict['query']
params = query_dict['params']
url = 'https://www.ebi.ac.uk/chembl/api/data/' + query + '.json'
r = requests.get(url, params=params)
r.raise_for_status()
js = r.json()
return js
示例6: activities_by_target
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def activities_by_target(activities):
"""Get back lists of activities in a dict keyed by ChEMBL target id
Parameters
----------
activities : list
response from a query returning activities for a drug
Returns
-------
targ_act_dict : dict
dictionary keyed to ChEMBL target ids with lists of activity ids
"""
targ_act_dict = defaultdict(lambda: [])
for activity in activities:
target_chembl_id = activity['target_chembl_id']
activity_id = activity['activity_id']
targ_act_dict[target_chembl_id].append(activity_id)
for target_chembl_id in targ_act_dict:
targ_act_dict[target_chembl_id] = \
list(set(targ_act_dict[target_chembl_id]))
return targ_act_dict
示例7: get_protein_targets_only
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def get_protein_targets_only(target_chembl_ids):
"""Given list of ChEMBL target ids, return dict of SINGLE PROTEIN targets
Parameters
----------
target_chembl_ids : list
list of chembl_ids as strings
Returns
-------
protein_targets : dict
dictionary keyed to ChEMBL target ids with lists of activity ids
"""
protein_targets = {}
for target_chembl_id in target_chembl_ids:
target = query_target(target_chembl_id)
if 'SINGLE PROTEIN' in target['target_type']:
protein_targets[target_chembl_id] = target
return protein_targets
示例8: get_evidence
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def get_evidence(assay):
"""Given an activity, return an INDRA Evidence object.
Parameters
----------
assay : dict
an activity from the activities list returned by a query to the API
Returns
-------
ev : :py:class:`Evidence`
an :py:class:`Evidence` object containing the kinetics of the
"""
kin = get_kinetics(assay)
source_id = assay.get('assay_chembl_id')
if not kin:
return None
annotations = {'kinetics': kin}
chembl_doc_id = str(assay.get('document_chembl_id'))
pmid = get_pmid(chembl_doc_id)
ev = Evidence(source_api='chembl', pmid=pmid, source_id=source_id,
annotations=annotations)
return ev
示例9: _load_data
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def _load_data():
"""Load the data from the csv in data.
The "gene_id" is the Entrez gene id, and the "approved_symbol" is the
standard gene symbol. The "hms_id" is the LINCS ID for the drug.
Returns
-------
data : list[dict]
A list of dicts of row values keyed by the column headers extracted from
the csv file, described above.
"""
# Get the cwv reader object.
csv_path = path.join(HERE, path.pardir, path.pardir, 'resources',
DATAFILE_NAME)
data_iter = list(read_unicode_csv(csv_path))
# Get the headers.
headers = data_iter[0]
# For some reason this heading is oddly formatted and inconsistent with the
# rest, or with the usual key-style for dicts.
headers[headers.index('Approved.Symbol')] = 'approved_symbol'
return [{header: val for header, val in zip(headers, line)}
for line in data_iter[1:]]
示例10: make_annotation
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def make_annotation(self):
"""Returns a dictionary with all properties of the action
and each of its action mentions."""
annotation = dict()
# Put all properties of the action object into the annotation
for item in dir(self):
if len(item) > 0 and item[0] != '_' and \
not inspect.ismethod(getattr(self, item)):
annotation[item] = getattr(self, item)
# Add properties of each action mention
annotation['action_mentions'] = list()
for action_mention in self.action_mentions:
annotation_mention = action_mention.make_annotation()
annotation['action_mentions'].append(annotation_mention)
return annotation
示例11: _init_action_list
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def _init_action_list(self, action_filename):
"""Parses the file and populates the data."""
self.actions = list()
self.hiid_to_action_index = dict()
f = codecs.open(action_filename, 'r', encoding='latin-1')
first_line = True
for line in f:
line = line.rstrip()
if first_line:
# Ignore the first line
first_line = False
else:
self.actions.append(GenewaysAction(line))
latestInd = len(self.actions)-1
hiid = self.actions[latestInd].hiid
if hiid in self.hiid_to_action_index:
raise Exception('action hiid not unique: %d' % hiid)
self.hiid_to_action_index[hiid] = latestInd
示例12: __init__
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def __init__(self, sentence_segmentations):
self.index_to_text = dict()
# It would be less memory intensive to use a tree, but this is simpler
# to code
root = etree.fromstring(sentence_segmentations.encode('utf-8'))
for element in root.iter('sentence'):
offset_str = element.get('charOffset')
offset_list = offset_str.split('-')
#
first_offset = int(offset_list[0])
second_offset = int(offset_list[1])
text = element.get('text')
for i in range(first_offset, second_offset+1):
self.index_to_text[i] = text
示例13: _get_dict_from_list
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def _get_dict_from_list(dict_key, list_of_dicts):
"""Retrieve a specific dict from a list of dicts.
Parameters
----------
dict_key : str
The (single) key of the dict to be retrieved from the list.
list_of_dicts : list
The list of dicts to search for the specific dict.
Returns
-------
dict value
The value associated with the dict_key (e.g., a list of nodes or
edges).
"""
the_dict = [cur_dict for cur_dict in list_of_dicts
if cur_dict.get(dict_key)]
if not the_dict:
raise ValueError('Could not find a dict with key %s' % dict_key)
return the_dict[0][dict_key]
示例14: _initialize_edge_attributes
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def _initialize_edge_attributes(self):
edge_attr = _get_dict_from_list('edgeAttributes', self.cx)
for ea in edge_attr:
edge_id = ea.get('po')
ea_type = ea.get('n')
ea_value = ea.get('v')
ea_info = self._edge_attributes.get(edge_id)
# If we don't have any info about this edge, initialize an empty
# dict
if ea_info is None:
ea_info = {'pmids': []}
self._edge_attributes[edge_id] = ea_info
# Collect PMIDs from the various edge types
if ea_type == 'ndex:citation' or ea_type == 'citation_ids':
pmids = []
assert isinstance(ea_value, list)
# ndex:citations are in the form 'pmid:xxxxx'
for cit in ea_value:
if cit.upper().startswith('PMID:'):
pmid = cit[5:]
if pmid: # Check for empty PMID strings!
pmids.append(pmid)
else:
logger.info("Unexpected PMID format: %s" % cit)
ea_info['pmids'] += pmids
示例15: process_cx
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import dict [as 别名]
def process_cx(cx_json, summary=None, require_grounding=True):
"""Process a CX JSON object into Statements.
Parameters
----------
cx_json : list
CX JSON object.
summary : Optional[dict]
The network summary object which can be obtained via
get_network_summary through the web service. THis contains metadata
such as the owner and the creation time of the network.
require_grounding: bool
Whether network nodes lacking grounding information should be included
among the extracted Statements (default is True).
Returns
-------
NdexCxProcessor
Processor containing Statements.
"""
ncp = NdexCxProcessor(cx_json, summary=summary,
require_grounding=require_grounding)
ncp.get_statements()
return ncp