sequence stringlengths 492 15.9k | code stringlengths 75 8.58k |
|---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:values; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 20; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:key; 8, parameters; 8, 9; 9, identifier:th; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 1... | def values(self):
def key(th):
return len(th.__class__.__mro__)
return sorted(dict.values(self), key=key, reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 16; 5, 26; 5, 42; 5, 48; 5, 66; 5, 70; 5, 117; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:graph; 9, attribute; 9, 10; 9, 11; 10, i... | def topological_sort(self):
graph = self.graph
in_degree = {}
for u in graph:
in_degree[u] = 0
for u in graph:
for v in graph[u]:
in_degree[v] += 1
queue = deque()
for u in in_degree:
if in_degree[u] == 0:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_music_lib_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:search; 6, identifier:start; 7, identifier:max_items; 8, block; 8, 9; 8, 38; 8, 42; 8, 63; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 1... | def _music_lib_search(self, search, start, max_items):
response = self.contentDirectory.Browse([
('ObjectID', search),
('BrowseFlag', 'BrowseDirectChildren'),
('Filter', '*'),
('StartingIndex', start),
('RequestedCount', max_items),
('SortC... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:unique; 3, parameters; 3, 4; 4, identifier:seq; 5, block; 5, 6; 5, 10; 5, 26; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:cleaned; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:each; 12, ident... | def unique(seq):
cleaned = []
for each in seq:
if each not in cleaned:
cleaned.append(each)
return cleaned |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_schema_info; 3, parameters; 3, 4; 4, identifier:connection_alias; 5, block; 5, 6; 5, 13; 5, 17; 5, 127; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:connection; 9, call; 9, 10; 9, 11; 10, identifier:get_valid_co... | def build_schema_info(connection_alias):
connection = get_valid_connection(connection_alias)
ret = []
with connection.cursor() as cursor:
tables_to_introspect = connection.introspection.table_names(cursor, include_views=_include_views())
for table_name in tables_to_introspect:
if... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:fetchThreads; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:thread_location; 6, default_parameter; 6, 7; 6, 8; 7, identifier:before; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:after; 11, None;... | def fetchThreads(self, thread_location, before=None, after=None, limit=None):
threads = []
last_thread_timestamp = None
while True:
if limit and len(threads) >= limit:
break
candidates = self.fetchThreadList(
before=last_thread_timestamp, t... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_key_value; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:is_hll; 8, False; 9, block; 9, 10; 9, 12; 10, expression_statement; 10, 11; 11, string:'''
Returns t... | def _get_key_value(self, key, is_hll=False):
'''
Returns the proper key value for the stats
@param key: the redis key
@param is_hll: the key is a HyperLogLog, else is a sorted set
'''
if is_hll:
return self.redis_conn.execute_command("PFCOUNT", key)
el... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_bin; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:key; 6, block; 6, 7; 6, 9; 6, 13; 6, 62; 7, expression_statement; 7, 8; 8, string:'''
Returns a binned dictionary based on redis zscore
@return: The sorted d... | def _get_bin(self, key):
'''
Returns a binned dictionary based on redis zscore
@return: The sorted dict
'''
sortedDict = {}
for item in self.redis_conn.zscan_iter(key):
my_item = ujson.loads(item[0])
my_score = -item[1]
if my_score not ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_is_viable_phone_number; 3, parameters; 3, 4; 4, identifier:number; 5, block; 5, 6; 5, 16; 5, 24; 6, if_statement; 6, 7; 6, 13; 7, comparison_operator:<; 7, 8; 7, 12; 8, call; 8, 9; 8, 10; 9, identifier:len; 10, argument_list; 10, 11; 11, ident... | def _is_viable_phone_number(number):
if len(number) < _MIN_LENGTH_FOR_NSN:
return False
match = fullmatch(_VALID_PHONE_NUMBER_PATTERN, number)
return bool(match) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__encoded_params_for_signature; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:params; 6, block; 6, 7; 6, 109; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:encoded_pairs; 9, parameters; 9, 10; 10, identifier:params; ... | def __encoded_params_for_signature(cls, params):
def encoded_pairs(params):
for k, v in six.iteritems(params):
if k == 'hmac':
continue
if k.endswith('[]'):
k = k.rstrip('[]')
v = json.dumps(list(map(str, v))... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:group_keys; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 20; 7, identifier:key; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:listdir... | def group_keys(self):
for key in sorted(listdir(self._store, self._path)):
path = self._key_prefix + key
if contains_group(self._store, path):
yield key |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:array_keys; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 20; 7, identifier:key; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:listdir... | def array_keys(self):
for key in sorted(listdir(self._store, self._path)):
path = self._key_prefix + key
if contains_array(self._store, path):
yield key |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 36; 2, function_name:init_array; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 4, identifier:store; 5, identifier:shape; 6, default_parameter; 6, 7; 6, 8; 7, identifier:chunks; 8, True; 9, default_parameter; 9, 10; ... | def init_array(store, shape, chunks=True, dtype=None, compressor='default',
fill_value=None, order='C', overwrite=False, path=None,
chunk_store=None, filters=None, object_codec=None):
path = normalize_storage_path(path)
_require_parent_group(path, store=store, chunk_store=chunk_sto... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:view; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:shape; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:chunks; 10, None; 11, default_parame... | def view(self, shape=None, chunks=None, dtype=None,
fill_value=None, filters=None, read_only=None,
synchronizer=None):
store = self._store
chunk_store = self._chunk_store
path = self._path
if read_only is None:
read_only = self._read_only
if ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:image_field_data; 3, parameters; 3, 4; 3, 5; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_empty_option; 7, False; 8, block; 8, 9; 8, 37; 8, 51; 8, 61; 8, 93; 8, 105; 9, try_statement; 9, 10; 9, 23; 10, block; 1... | def image_field_data(request, include_empty_option=False):
try:
images = get_available_images(request, request.user.project_id)
except Exception:
exceptions.handle(request, _('Unable to retrieve images'))
images.sort(key=lambda c: c.name)
images_list = [('', _('Select Image'))]
for i... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_flavor_list; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:request; 5, identifier:flavors; 6, default_parameter; 6, 7; 6, 8; 7, identifier:with_menu_label; 8, True; 9, block; 9, 10; 9, 43; 10, function_definition; 10, 11; 10, 12; 10, 15; ... | def sort_flavor_list(request, flavors, with_menu_label=True):
def get_key(flavor, sort_key):
try:
return getattr(flavor, sort_key)
except AttributeError:
LOG.warning('Could not find sort key "%s". Using the default '
'"ram" instead.', sort_key)
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:image_list_detailed; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:marker; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, str... | def image_list_detailed(request, marker=None, sort_dir='desc',
sort_key='created_at', filters=None, paginate=False,
reversed_order=False, **kwargs):
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
page_size = utils.get_page_size(request)
if paginate:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:metadefs_namespace_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:request; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filters; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_dir; 10, string:'asc'... | def metadefs_namespace_list(request,
filters=None,
sort_dir='asc',
sort_key='namespace',
marker=None,
paginate=False):
if get_version() < 2:
return [], False, False
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_js_files; 3, parameters; 3, 4; 4, identifier:js_files; 5, block; 5, 6; 5, 21; 5, 36; 5, 51; 5, 84; 5, 90; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:modules; 9, list_comprehension; 9, 10; 9, 11; 9, 14; 10, iden... | def sort_js_files(js_files):
modules = [f for f in js_files if f.endswith(MODULE_EXT)]
mocks = [f for f in js_files if f.endswith(MOCK_EXT)]
specs = [f for f in js_files if f.endswith(SPEC_EXT)]
other_sources = [f for f in js_files
if (not f.endswith(MODULE_EXT) and
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_slice_mostly_sorted; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:array; 5, identifier:keep; 6, identifier:rest; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ind; 9, None; 10, block; 10, 11; 10, 28; 10, 46; 10, 50; 10, 70; 10, 80; ... | def _slice_mostly_sorted(array, keep, rest, ind=None):
if ind is None:
ind = np.arange(len(array))
idx = np.argsort(np.concatenate([keep, ind[rest]]))
slices = []
if keep[0] > 0:
slices.append(slice(None, keep[0]))
slices.append([keep[0]])
windows = zip(keep[:-1], keep[1:])
f... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 24; 2, function_name:sort_servers_closest; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:servers; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Sequence; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, ty... | def sort_servers_closest(servers: Sequence[str]) -> Sequence[Tuple[str, float]]:
if not {urlparse(url).scheme for url in servers}.issubset({'http', 'https'}):
raise TransportError('Invalid server urls')
get_rtt_jobs = set(
gevent.spawn(lambda url: (url, get_http_rtt(url)), server_url)
fo... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_runs_by_id; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:config_id; 6, block; 6, 7; 6, 15; 6, 19; 6, 108; 6, 122; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:d; 10, subscript; 10, 11; 10, 14; 11,... | def get_runs_by_id(self, config_id):
d = self.data[config_id]
runs = []
for b in d.results.keys():
try:
err_logs = d.exceptions.get(b, None)
if d.results[b] is None:
r = Run(config_id, b, None, None , d.time_stamps[b], err_logs)
else:
r = Run(config_id, b, d.results[b]['loss'], d.results[... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 15; 2, function_name:spell; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:word; 7, type; 7, 8; 8, identifier:str; 9, type; 9, 10; 10, generic_type; 10, 11; 10, 12; 11, identifier:List; 12, type_parameter; 12, 13... | def spell(self, word: str) -> List[str]:
if not word:
return ""
candidates = (
self.known([word])
or self.known(_edits1(word))
or self.known(_edits2(word))
or [word]
)
candidates.sort(key=self.freq, reverse=True)
return ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 1, 19; 2, function_name:rank; 3, parameters; 3, 4; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:words; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, typed_default_par... | def rank(words: List[str], exclude_stopwords: bool = False) -> Counter:
if not words:
return None
if exclude_stopwords:
words = [word for word in words if word not in _STOPWORDS]
return Counter(words) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:iter; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:offset; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:count; 10, None; 11, default_parameter; 11, 12; 11,... | def iter(self, offset=0, count=None, pagesize=None, **kwargs):
assert pagesize is None or pagesize > 0
if count is None:
count = self.null_count
fetched = 0
while count == self.null_count or fetched < count:
response = self.get(count=pagesize or count, offset=offs... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:count; 7, None; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, ... | def list(self, count=None, **kwargs):
return list(self.iter(count=count, **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:query; 7, block; 7, 8; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:json; 12, identifier:l... | def query(self, **query):
return json.loads(self._get('', **query).body.read().decode('utf-8')) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:area; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:date; 10, None; 11, default_p... | def query(self, area=None, date=None, raw=None, area_relation='Intersects',
order_by=None, limit=None, offset=0, **keywords):
query = self.format_query(area, date, raw, area_relation, **keywords)
self.logger.debug("Running query: order_by=%s, limit=%s, offset=%s, query=%s",
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_suggested_type_names; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:schema; 5, identifier:output_type; 6, identifier:field_name; 7, block; 7, 8; 7, 128; 8, if_statement; 8, 9; 8, 16; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, ar... | def get_suggested_type_names(schema, output_type, field_name):
if isinstance(output_type, (GraphQLInterfaceType, GraphQLUnionType)):
suggested_object_types = []
interface_usage_count = OrderedDict()
for possible_type in schema.get_possible_types(output_type):
if not possible_type... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:suggestion_list; 3, parameters; 3, 4; 3, 5; 4, identifier:inp; 5, identifier:options; 6, block; 6, 7; 6, 13; 6, 22; 6, 59; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:options_by_distance; 10, call; 10, 11; 10, 12; 1... | def suggestion_list(inp, options):
options_by_distance = OrderedDict()
input_threshold = len(inp) / 2
for option in options:
distance = lexical_distance(inp, option)
threshold = max(input_threshold, len(option) / 2, 1)
if distance <= threshold:
options_by_distance[option]... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:lexical_distance; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 26; 6, 35; 6, 80; 6, 221; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:d; 10, boolean_operator:or; 10, 11; 10, 25; 11,... | def lexical_distance(a, b):
d = [[i] for i in range(len(a) + 1)] or []
d_len = len(d) or 1
for i in range(d_len):
for j in range(1, len(b) + 1):
if i == 0:
d[i].append(j)
else:
d[i].append(0)
for i in range(1, len(a) + 1):
for j in ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:arrange; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:df; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 21; 9, 56; 9, 75; 9, 92; 10, expression_statement; 10, 11;... | def arrange(df, *args, **kwargs):
flat_args = [a for a in flatten(args)]
series = [df[arg] if isinstance(arg, str) else
df.iloc[:, arg] if isinstance(arg, int) else
pd.Series(arg) for arg in flat_args]
sorter = pd.concat(series, axis=1).reset_index(drop=True)
sorter = sorter.... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:csort; 3, parameters; 3, 4; 3, 5; 4, identifier:objs; 5, identifier:key; 6, block; 6, 7; 6, 24; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:idxs; 10, call; 10, 11; 10, 12; 11, identifier:dict; 12, generator_expressi... | def csort(objs, key):
idxs = dict((obj, i) for (i, obj) in enumerate(objs))
return sorted(objs, key=lambda obj: (key(obj), idxs[obj])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:fast_combine_pairs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:files; 5, identifier:force_single; 6, identifier:full_name; 7, identifier:separators; 8, block; 8, 9; 8, 16; 8, 26; 8, 40; 8, 51; 8, 58; 8, 85; 8, 103; 9, expression_state... | def fast_combine_pairs(files, force_single, full_name, separators):
files = sort_filenames(files)
chunks = tz.sliding_window(10, files)
pairs = [combine_pairs(chunk, force_single, full_name, separators) for chunk in chunks]
pairs = [y for x in pairs for y in x]
longest = defaultdict(list)
for pa... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:align_bam; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:in_bam; 5, identifier:ref_file; 6, identifier:names; 7, identifier:align_dir; 8, identifier:data; 9, block; 9, 10; 9, 16; 9, 35; 9, 45; 9, 55; 9, 65; 9, 77; 9, 98; 9, 219; 10... | def align_bam(in_bam, ref_file, names, align_dir, data):
config = data["config"]
out_file = os.path.join(align_dir, "{0}-sort.bam".format(names["lane"]))
samtools = config_utils.get_program("samtools", config)
bedtools = config_utils.get_program("bedtools", config)
resources = config_utils.get_resou... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_combine_regions; 3, parameters; 3, 4; 3, 5; 4, identifier:all_regions; 5, identifier:ref_regions; 6, block; 6, 7; 6, 11; 6, 28; 6, 47; 6, 51; 6, 81; 6, 90; 6, 106; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:chrom_... | def _combine_regions(all_regions, ref_regions):
chrom_order = {}
for i, x in enumerate(ref_regions):
chrom_order[x.chrom] = i
def wchrom_key(x):
chrom, start, end = x
return (chrom_order[chrom], start, end)
all_intervals = []
for region_group in all_regions:
for regio... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_add_meta; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:xs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sample; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:config; 10, None; 11, block; 11, 12; 11, 16; 11, 153; 12, expressio... | def _add_meta(xs, sample=None, config=None):
out = []
for x in xs:
if not isinstance(x["path"], six.string_types) or not os.path.exists(x["path"]):
raise ValueError("Unexpected path for upload: %s" % x)
x["mtime"] = shared.get_file_timestamp(x["path"])
if sample:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:report; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:align_bam; 6, identifier:ref_file; 7, identifier:is_paired; 8, identifier:bait_file; 9, identifier:target_file; 10, identifier:variant_r... | def report(self, align_bam, ref_file, is_paired, bait_file, target_file,
variant_region_file, config):
dup_metrics = self._get_current_dup_metrics(align_bam)
align_metrics = self._collect_align_metrics(align_bam, ref_file)
gc_graph = None
insert_graph, insert_metrics, hybr... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:report; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:align_bam; 6, identifier:ref_file; 7, identifier:gtf_file; 8, default_parameter; 8, 9; 8, 10; 9, identifier:is_paired; 10, False; 11, default_paramet... | def report(self, align_bam, ref_file, gtf_file, is_paired=False, rrna_file="null"):
dup_metrics = self._get_current_dup_metrics(align_bam)
align_metrics = self._collect_align_metrics(align_bam, ref_file)
insert_graph, insert_metrics = (None, None)
if is_paired:
insert_graph, ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:apply_recal; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 22; 5, 28; 5, 141; 5, 163; 5, 200; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:orig_bam; 9, boolean_operator:or; 9, 10; 9, 16; 10, call; 10, 11... | def apply_recal(data):
orig_bam = dd.get_align_bam(data) or dd.get_work_bam(data)
had_work_bam = "work_bam" in data
if dd.get_recalibrate(data) in [True, "gatk"]:
if data.get("prep_recal"):
logger.info("Applying BQSR recalibration with GATK: %s " % str(dd.get_sample_name(data)))
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_prep_callable_bed; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:in_file; 5, identifier:work_dir; 6, identifier:stats; 7, identifier:data; 8, block; 8, 9; 8, 37; 8, 47; 8, 106; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10,... | def _prep_callable_bed(in_file, work_dir, stats, data):
out_file = os.path.join(work_dir, "%s-merge.bed.gz" % utils.splitext_plus(os.path.basename(in_file))[0])
gsort = config_utils.get_program("gsort", data)
if not utils.file_uptodate(out_file, in_file):
with file_transaction(data, out_file) as tx_... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:fake_index; 3, parameters; 3, 4; 3, 5; 4, identifier:in_bam; 5, identifier:data; 6, block; 6, 7; 6, 13; 6, 53; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:index_file; 10, binary_operator:%; 10, 11; 10, 12; 11, strin... | def fake_index(in_bam, data):
index_file = "%s.bai" % in_bam
if not utils.file_exists(index_file):
with file_transaction(data, index_file) as tx_out_file:
with open(tx_out_file, "w") as out_handle:
out_handle.write("name sorted -- no index")
return index_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:in_bam; 5, identifier:config; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, string:"coordinate"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:out_dir; 11, None; 12, b... | def sort(in_bam, config, order="coordinate", out_dir=None):
assert is_bam(in_bam), "%s in not a BAM file" % in_bam
if bam_already_sorted(in_bam, config, order):
return in_bam
sort_stem = _get_sort_stem(in_bam, order, out_dir)
sort_file = sort_stem + ".bam"
if not utils.file_exists(sort_file)... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:tobam_cl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:data; 5, identifier:out_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:is_paired; 8, False; 9, block; 9, 10; 9, 17; 9, 26; 10, expression_statement; 10, 11; 11, assignment; 11, 12;... | def tobam_cl(data, out_file, is_paired=False):
do_dedup = _check_dedup(data)
umi_consensus = dd.get_umi_consensus(data)
with file_transaction(data, out_file) as tx_out_file:
if not do_dedup:
yield (sam_to_sortbam_cl(data, tx_out_file), tx_out_file)
elif umi_consensus:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sam_to_sortbam_cl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:data; 5, identifier:tx_out_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name_sort; 8, False; 9, block; 9, 10; 9, 22; 9, 34; 9, 47; 9, 54; 10, expression_statement; 10, 1... | def sam_to_sortbam_cl(data, tx_out_file, name_sort=False):
samtools = config_utils.get_program("samtools", data["config"])
cores, mem = _get_cores_memory(data, downscale=2)
tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
sort_flag = "-n" if name_sort else ""
return ("{samtools} sort -@... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:samblaster_dedup_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:data; 5, identifier:tx_out_file; 6, identifier:tx_sr_file; 7, identifier:tx_disc_file; 8, block; 8, 9; 8, 21; 8, 33; 8, 46; 8, 51; 8, 63; 8, 81; 8, 100; 8, 148; 8, 152;... | def samblaster_dedup_sort(data, tx_out_file, tx_sr_file, tx_disc_file):
samblaster = config_utils.get_program("samblaster", data["config"])
samtools = config_utils.get_program("samtools", data["config"])
tmp_prefix = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
tobam_cmd = ("{samtools} sort {sort_... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_biobambam_dedup_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:data; 5, identifier:tx_out_file; 6, block; 6, 7; 6, 19; 6, 31; 6, 44; 6, 124; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:samtools; 10, call; 10, 11; 1... | def _biobambam_dedup_sort(data, tx_out_file):
samtools = config_utils.get_program("samtools", data["config"])
cores, mem = _get_cores_memory(data, downscale=2)
tmp_file = "%s-sorttmp" % utils.splitext_plus(tx_out_file)[0]
if data.get("align_split"):
sort_opt = "-n" if data.get("align_split") and... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_prepare_bam_file; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:bam_file; 5, identifier:tmp_dir; 6, identifier:config; 7, block; 7, 8; 7, 16; 7, 30; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sort_mode; 11, cal... | def _prepare_bam_file(bam_file, tmp_dir, config):
sort_mode = _get_sort_order(bam_file, config)
if sort_mode != "queryname":
bam_file = sort(bam_file, config, "queryname")
return bam_file |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_concat_records; 3, parameters; 3, 4; 3, 5; 4, identifier:items_by_key; 5, identifier:input_order; 6, block; 6, 7; 6, 11; 6, 33; 6, 42; 6, 51; 6, 99; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:all_records; 10, list... | def _concat_records(items_by_key, input_order):
all_records = []
for (k, t) in input_order.items():
if t == "record":
all_records.append(k)
out_items_by_key = utils.deepish_copy(items_by_key)
out_input_order = utils.deepish_copy(input_order)
if len(all_records) > 1:
final... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_combine_files; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:tsv_files; 5, identifier:work_dir; 6, identifier:data; 7, block; 7, 8; 7, 28; 7, 37; 7, 52; 7, 122; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:header... | def _combine_files(tsv_files, work_dir, data):
header = "\t".join(["caller", "sample", "chrom", "start", "end", "svtype",
"lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"])
sample = dd.get_sample_name(data)
out_file = os.path.join(work_dir, "%s-prio... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_filenames; 3, parameters; 3, 4; 4, identifier:filenames; 5, block; 5, 6; 5, 21; 5, 45; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:basenames; 9, list_comprehension; 9, 10; 9, 18; 10, call; 10, 11; 10, 16; 11, at... | def sort_filenames(filenames):
basenames = [os.path.basename(x) for x in filenames]
indexes = [i[0] for i in sorted(enumerate(basenames), key=lambda x:x[1])]
return [filenames[x] for x in indexes] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_csv; 3, parameters; 3, 4; 4, identifier:in_file; 5, block; 5, 6; 5, 12; 5, 73; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:out_file; 9, binary_operator:%; 9, 10; 9, 11; 10, string:"%s.sort"; 11, identifier:in_fi... | def sort_csv(in_file):
out_file = "%s.sort" % in_file
if not (os.path.exists(out_file) and os.path.getsize(out_file) > 0):
cl = ["sort", "-k", "1,1", in_file]
with open(out_file, "w") as out_handle:
child = subprocess.Popen(cl, stdout=out_handle)
child.wait()
return o... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:hydra_to_vcf_writer; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:hydra_file; 5, identifier:genome_2bit; 6, identifier:options; 7, identifier:out_handle; 8, block; 8, 9; 8, 14; 8, 26; 8, 39; 9, expression_statement; 9, 10; 10, call; 10,... | def hydra_to_vcf_writer(hydra_file, genome_2bit, options, out_handle):
_write_vcf_header(out_handle)
brends = list(_get_vcf_breakends(hydra_file, genome_2bit, options))
brends.sort(key=attrgetter("chrom", "pos"))
for brend in brends:
_write_vcf_breakend(brend, out_handle) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_split_by_ready_regions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:ext; 5, identifier:file_key; 6, identifier:dir_ext_fn; 7, block; 7, 8; 7, 30; 7, 103; 7, 251; 8, function_definition; 8, 9; 8, 10; 8, 12; 9, function_name:_sort_by_size; 10... | def _split_by_ready_regions(ext, file_key, dir_ext_fn):
def _sort_by_size(region_w_bams):
region, _ = region_w_bams
_, start, end = region
return end - start
def _assign_bams_to_regions(data):
for i, region in enumerate(data["region"]):
work_bams = []
for ... |
0, module; 0, 1; 1, ERROR; 1, 2; 1, 137; 2, function_definition; 2, 3; 2, 4; 2, 9; 3, function_name:_combine_variants; 4, parameters; 4, 5; 4, 6; 4, 7; 4, 8; 5, identifier:in_vcfs; 6, identifier:out_file; 7, identifier:ref_file; 8, identifier:config; 9, block; 9, 10; 9, 16; 9, 20; 9, 121; 10, expression_statement; 10, ... | def _combine_variants(in_vcfs, out_file, ref_file, config):
in_vcfs.sort()
wrote_header = False
with open(out_file, "w") as out_handle:
for in_vcf in (x[-1] for x in in_vcfs):
with open(in_vcf) as in_handle:
header = list(itertools.takewhile(lambda x: x.startswith("
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:picard_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:picard; 5, identifier:align_bam; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort_order; 8, string:"coordinate"; 9, default_parameter; 9, 10; 9, 11; 10, identi... | def picard_sort(picard, align_bam, sort_order="coordinate",
out_file=None, compression_level=None, pipe=False):
base, ext = os.path.splitext(align_bam)
if out_file is None:
out_file = "%s-sort%s" % (base, ext)
if not file_exists(out_file):
with tx_tmpdir(picard._config) as tm... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:picard_fix_rgs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:picard; 5, identifier:in_bam; 6, identifier:names; 7, block; 7, 8; 7, 23; 7, 110; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:out_file; 11, binary_ope... | def picard_fix_rgs(picard, in_bam, names):
out_file = "%s-fixrgs.bam" % os.path.splitext(in_bam)[0]
if not file_exists(out_file):
with tx_tmpdir(picard._config) as tmp_dir:
with file_transaction(picard._config, out_file) as tx_out_file:
opts = [("INPUT", in_bam),
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_enforce_max_region_size; 3, parameters; 3, 4; 3, 5; 4, identifier:in_file; 5, identifier:data; 6, block; 6, 7; 6, 11; 6, 15; 6, 41; 6, 52; 6, 120; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:max_size; 10, integer:2... | def _enforce_max_region_size(in_file, data):
max_size = 20000
overlap_size = 250
def _has_larger_regions(f):
return any(r.stop - r.start > max_size for r in pybedtools.BedTool(f))
out_file = "%s-regionlimit%s" % utils.splitext_plus(in_file)
if not utils.file_exists(out_file):
if _has... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_prep_vrn_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:in_file; 5, identifier:vcaller; 6, identifier:work_dir; 7, identifier:somatic_info; 8, identifier:ignore_file; 9, identifier:config; 10, block; 10, 11; 10, 41; 10... | def _prep_vrn_file(in_file, vcaller, work_dir, somatic_info, ignore_file, config):
if vcaller.startswith("vardict"):
variant_type = "vardict"
elif vcaller == "mutect":
variant_type = "mutect-smchet"
else:
raise ValueError("Unexpected variant caller for PhyloWGS prep: %s" % vcaller)
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:concat; 3, parameters; 3, 4; 3, 5; 4, identifier:bed_files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:catted; 7, None; 8, block; 8, 9; 8, 19; 8, 68; 8, 113; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:be... | def concat(bed_files, catted=None):
bed_files = [x for x in bed_files if x]
if len(bed_files) == 0:
if catted:
sorted_bed = catted.sort()
if not sorted_bed.fn.endswith(".bed"):
return sorted_bed.moveto(sorted_bed.fn + ".bed")
else:
retu... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_sv_callers; 3, parameters; 3, 4; 4, identifier:items; 5, block; 5, 6; 5, 10; 5, 33; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:callers; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:data... | def _get_sv_callers(items):
callers = []
for data in items:
for sv in data.get("sv", []):
callers.append(sv["variantcaller"])
return list(set([x for x in callers if x != "sv-ensemble"])).sort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_sort_cmd; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:tmp_dir; 6, None; 7, block; 7, 8; 7, 24; 7, 37; 7, 64; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:has_versionsort; 11, call; 11, ... | def get_sort_cmd(tmp_dir=None):
has_versionsort = subprocess.check_output("sort --help | grep version-sort; exit 0", shell=True).strip()
if has_versionsort:
cmd = "sort -V"
else:
cmd = "sort"
if tmp_dir and os.path.exists(tmp_dir) and os.path.isdir(tmp_dir):
cmd += " -T %s" % tmp... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:clean_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:in_file; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:prefix; 8, string:""; 9, default_parameter; 9, 10; 9, 11; 10, identifier:bedprep_dir; 11, None... | def clean_file(in_file, data, prefix="", bedprep_dir=None, simple=None):
simple = "iconv -c -f utf-8 -t ascii | sed 's/ //g' |" if simple else ""
if in_file:
if not bedprep_dir:
bedprep_dir = utils.safe_makedir(os.path.join(data["dirs"]["work"], "bedprep"))
if prefix and os.path.base... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_sort_by_region; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:fnames; 5, identifier:regions; 6, identifier:ref_file; 7, identifier:config; 8, block; 8, 9; 8, 13; 8, 36; 8, 40; 8, 53; 8, 60; 8, 174; 8, 180; 9, expression_statement; 9, 10... | def _sort_by_region(fnames, regions, ref_file, config):
contig_order = {}
for i, sq in enumerate(ref.file_contigs(ref_file, config)):
contig_order[sq.name] = i
sitems = []
assert len(regions) == len(fnames), (regions, fnames)
added_fnames = set([])
for region, fname in zip(regions, fname... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_file_list; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:orig_files; 5, identifier:out_file; 6, identifier:regions; 7, identifier:ref_file; 8, identifier:config; 9, block; 9, 10; 9, 20; 9, 46; 9, 102; 9, 117; 9, 130; 9, 155; 1... | def _get_file_list(orig_files, out_file, regions, ref_file, config):
sorted_files = _sort_by_region(orig_files, regions, ref_file, config)
exist_files = [(c, x) for c, x in sorted_files if os.path.exists(x) and vcf_has_variants(x)]
if len(exist_files) == 0:
exist_files = [x for c, x in sorted_files ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by_ref; 3, parameters; 3, 4; 3, 5; 4, identifier:vcf_file; 5, identifier:data; 6, block; 6, 7; 6, 20; 6, 148; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:out_file; 10, binary_operator:%; 10, 11; 10, 12; 11, str... | def sort_by_ref(vcf_file, data):
out_file = "%s-prep.vcf.gz" % utils.splitext_plus(vcf_file)[0]
if not utils.file_uptodate(out_file, vcf_file):
with file_transaction(data, out_file) as tx_out_file:
header_file = "%s-header.txt" % utils.splitext_plus(tx_out_file)[0]
with open(head... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:align_to_sort_bam; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:fastq1; 5, identifier:fastq2; 6, identifier:aligner; 7, identifier:data; 8, block; 8, 9; 8, 15; 8, 28; 8, 47; 8, 55; 8, 72; 8, 85; 8, 122; 8, 211; 9, expression_statement; ... | def align_to_sort_bam(fastq1, fastq2, aligner, data):
names = data["rgnames"]
align_dir_parts = [data["dirs"]["work"], "align", names["sample"]]
if data.get("disambiguate"):
align_dir_parts.append(data["disambiguate"]["genome_build"])
aligner_index = _get_aligner_index(aligner, data)
align_d... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_align_from_fastq; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:fastq1; 5, identifier:fastq2; 6, identifier:aligner; 7, identifier:align_ref; 8, identifier:sam_ref; 9, identifier:names; 10, identifier:align_di... | def _align_from_fastq(fastq1, fastq2, aligner, align_ref, sam_ref, names,
align_dir, data):
config = data["config"]
align_fn = TOOLS[aligner].align_fn
out = align_fn(fastq1, fastq2, align_ref, names, align_dir, data)
if isinstance(out, dict):
assert out.get("work_bam"), (dd... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:picard_prep; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:in_bam; 5, identifier:names; 6, identifier:ref_file; 7, identifier:dirs; 8, identifier:data; 9, block; 9, 10; 9, 22; 9, 44; 9, 52; 9, 82; 9, 110; 9, 122; 9, 133; 10, expres... | def picard_prep(in_bam, names, ref_file, dirs, data):
runner = broad.runner_from_path("picard", data["config"])
work_dir = utils.safe_makedir(os.path.join(dirs["work"], "bamclean", names["sample"]))
runner.run_fn("picard_index_ref", ref_file)
reorder_bam = os.path.join(work_dir, "%s-reorder.bam" %
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:iterate_flattened_separately; 3, parameters; 3, 4; 3, 5; 4, identifier:dictionary; 5, default_parameter; 5, 6; 5, 7; 6, identifier:manually_sorted_keys; 7, None; 8, block; 8, 9; 8, 18; 8, 34; 8, 65; 8, 79; 8, 108; 9, if_statement; 9, 10; 9, 13;... | def iterate_flattened_separately(dictionary, manually_sorted_keys=None):
if manually_sorted_keys is None:
manually_sorted_keys = []
for key in manually_sorted_keys:
if key in dictionary:
yield key, dictionary[key]
single_line_keys = [key for key in dictionary.keys() if
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:gather_command_line_options; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:filter_disabled; 6, None; 7, block; 7, 8; 7, 22; 7, 40; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:is; 9, 10; 9, 11; 10, identifier:filt... | def gather_command_line_options(filter_disabled=None):
if filter_disabled is None:
filter_disabled = not SETTINGS.COMMAND_LINE.SHOW_DISABLED_OPTIONS
options = [opt for opt in get_inheritors(CommandLineOption)
if not filter_disabled or opt._enabled]
return sorted(options, key=lambda op... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 2, function_name:bar; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:figsize; 7, tuple; 7, 8; 7, 9; 8, integer:24; 9, integer:10; 10, default_parameter... | def bar(df, figsize=(24, 10), fontsize=16, labels=None, log=False, color='dimgray', inline=False,
filter=None, n=0, p=0, sort=None):
nullity_counts = len(df) - df.isnull().sum()
df = nullity_filter(df, filter=filter, n=n, p=p)
df = nullity_sort(df, sort=sort)
plt.figure(figsize=figsize)
(nul... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 44; 2, function_name:heatmap; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 25; 3, 28; 3, 31; 3, 34; 3, 38; 3, 41; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:inline; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifie... | def heatmap(df, inline=False,
filter=None, n=0, p=0, sort=None,
figsize=(20, 12), fontsize=16, labels=True,
cmap='RdBu', vmin=-1, vmax=1, cbar=True
):
df = nullity_filter(df, filter=filter, n=n, p=p)
df = nullity_sort(df, sort=sort)
plt.figure(figsize=figsize... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:dendrogram; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:method; 7, string:'average'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filte... | def dendrogram(df, method='average',
filter=None, n=0, p=0, sort=None,
orientation=None, figsize=None,
fontsize=16, inline=False
):
if not figsize:
if len(df.columns) <= 50 or orientation == 'top' or orientation == 'bottom':
figsize = (... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:nullity_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort; 7, None; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 13; 9, 36; 9, 68; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:so... | def nullity_sort(df, sort=None):
if sort == 'ascending':
return df.iloc[np.argsort(df.count(axis='columns').values), :]
elif sort == 'descending':
return df.iloc[np.flipud(np.argsort(df.count(axis='columns').values)), :]
else:
return df |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:sortino_ratio; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:returns; 5, default_parameter; 5, 6; 5, 7; 6, identifier:required_return; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:period; 10, identifier:... | def sortino_ratio(returns,
required_return=0,
period=DAILY,
annualization=None,
out=None,
_downside_risk=None):
allocated_output = out is None
if allocated_output:
out = np.empty(returns.shape[1:])
return_1d = ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:downside_risk; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:returns; 5, default_parameter; 5, 6; 5, 7; 6, identifier:required_return; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:period; 10, identifier:DAILY; ... | def downside_risk(returns,
required_return=0,
period=DAILY,
annualization=None,
out=None):
allocated_output = out is None
if allocated_output:
out = np.empty(returns.shape[1:])
returns_1d = returns.ndim == 1
if len(returns) ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetLoadingOrder; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 39; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, dictionary; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, pattern_list; ... | def GetLoadingOrder(self):
result = {}
for filename, mapping in self._file_mapping.iteritems():
loading_order = mapping['loading_order']
if loading_order is not None:
result[loading_order] = filename
return list(result[key] for key in sorted(result)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetOrderKey; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 11; 5, 20; 5, 31; 5, 35; 5, 51; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:context_attributes; 9, list:['_type']; 9, 10; 10, string:'_type'; 1... | def GetOrderKey(self):
context_attributes = ['_type']
context_attributes.extend(ExceptionWithContext.CONTEXT_PARTS)
context_attributes.extend(self._GetExtraOrderAttributes())
tokens = []
for context_attribute in context_attributes:
tokens.append(getattr(self, context_attribute, None))
retu... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:AddShapePointObjectUnsorted; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:shapepoint; 6, identifier:problems; 7, block; 7, 8; 7, 70; 7, 100; 7, 199; 7, 216; 7, 228; 7, 240; 8, if_statement; 8, 9; 8, 29; 8, 39; 8, 54; 9, pa... | def AddShapePointObjectUnsorted(self, shapepoint, problems):
if (len(self.sequence) == 0 or
shapepoint.shape_pt_sequence >= self.sequence[-1]):
index = len(self.sequence)
elif shapepoint.shape_pt_sequence <= self.sequence[0]:
index = 0
else:
index = bisect.bisect(self.sequence, sha... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:GetStopTimes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:problems; 7, None; 8, block; 8, 9; 8, 21; 8, 37; 8, 41; 8, 51; 8, 62; 8, 138; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 1... | def GetStopTimes(self, problems=None):
cursor = self._schedule._connection.cursor()
cursor.execute(
'SELECT arrival_secs,departure_secs,stop_headsign,pickup_type,'
'drop_off_type,shape_dist_traveled,stop_id,stop_sequence,timepoint '
'FROM stop_times '
'WHERE trip_id=? '
'... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:GetFrequencyStartTimes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 50; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:start_times; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 17; 11, ident... | def GetFrequencyStartTimes(self):
start_times = []
for freq_tuple in self.GetFrequencyTuples():
(start_secs, end_secs, headway_secs) = freq_tuple[0:3]
run_secs = start_secs
while run_secs < end_secs:
start_times.append(run_secs)
run_secs += headway_secs
return start_times |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:create; 3, parameters; 3, 4; 3, 5; 4, identifier:filename; 5, identifier:spec; 6, block; 6, 7; 6, 12; 6, 50; 6, 63; 6, 74; 6, 90; 6, 103; 6, 112; 6, 146; 6, 162; 6, 191; 6, 228; 6, 234; 6, 280; 6, 301; 6, 338; 6, 381; 7, import_from_statement; ... | def create(filename, spec):
from . import _segyio
if not structured(spec):
tracecount = spec.tracecount
else:
tracecount = len(spec.ilines) * len(spec.xlines) * len(spec.offsets)
ext_headers = spec.ext_headers if hasattr(spec, 'ext_headers') else 0
samples = numpy.asarray(spec.sample... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:rotation; 3, parameters; 3, 4; 3, 5; 4, identifier:f; 5, default_parameter; 5, 6; 5, 7; 6, identifier:line; 7, string:'fast'; 8, block; 8, 9; 8, 19; 8, 43; 8, 86; 8, 92; 8, 111; 8, 131; 8, 169; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, ... | def rotation(f, line = 'fast'):
if f.unstructured:
raise ValueError("Rotation requires a structured file")
lines = { 'fast': f.fast,
'slow': f.slow,
'iline': f.iline,
'xline': f.xline,
}
if line not in lines:
error = "Unknown line {}".for... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:from_array3D; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 17; 3, 20; 4, identifier:filename; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:iline; 8, integer:189; 9, default_parameter; 9, 10; 9, 11; 10, identifier:xli... | def from_array3D(filename, data, iline=189,
xline=193,
format=SegySampleFormat.IBM_FLOAT_4_BYTE,
dt=4000,
delrt=0):
data = np.asarray(data)
dimensions = len(data.shape)
if dime... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:open; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:filename; 5, default_parameter; 5, 6; 5, 7; 6, identifier:mode; 7, string:"r"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:iline; 10, integer:189; 11, defaul... | def open(filename, mode="r", iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big'):
if 'w' in mode:
problem = 'w in mode would truncate the file'
solution =... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:calc_min_interval; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:alpha; 6, block; 6, 7; 6, 14; 6, 20; 6, 34; 6, 40; 6, 54; 6, 71; 6, 80; 6, 86; 6, 94; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:n; 10, c... | def calc_min_interval(x, alpha):
n = len(x)
cred_mass = 1.0 - alpha
interval_idx_inc = int(np.floor(cred_mass * n))
n_intervals = n - interval_idx_inc
interval_width = x[interval_idx_inc:] - x[:n_intervals]
if len(interval_width) == 0:
print_('Too few elements for interval calculation')
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_compute_gas_price; 3, parameters; 3, 4; 3, 5; 4, identifier:probabilities; 5, identifier:desired_probability; 6, block; 6, 7; 6, 13; 6, 20; 6, 48; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:first; 10, subscript; 1... | def _compute_gas_price(probabilities, desired_probability):
first = probabilities[0]
last = probabilities[-1]
if desired_probability >= first.prob:
return int(first.gas_price)
elif desired_probability <= last.prob:
return int(last.gas_price)
for left, right in sliding_window(2, proba... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:generate_X_grid; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:term; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n; 8, integer:100; 9, default_parameter; 9, 10; 9, 11; 10, identifier:meshgrid; 11, False; 12, bloc... | def generate_X_grid(self, term, n=100, meshgrid=False):
if not self._is_fitted:
raise AttributeError('GAM has not been fitted. Call fit first.')
if self.terms[term].isintercept:
raise ValueError('cannot create grid for intercept term')
if self.terms[term].istensor:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:build_from_info; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:info; 6, block; 6, 7; 6, 11; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:terms; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11,... | def build_from_info(cls, info):
terms = []
for term_info in info['terms']:
terms.append(SplineTerm.build_from_info(term_info))
return cls(*terms) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_kate_imports; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:add_imports; 6, tuple; 7, default_parameter; 7, 8; 7, 9; 8, identifier:remove_imports; 9, tuple; 10, block; 10, 11; 10, 19; 10, 27; 10, 35; 10, 43; 1... | def sort_kate_imports(add_imports=(), remove_imports=()):
document = kate.activeDocument()
view = document.activeView()
position = view.cursorPosition()
selection = view.selectionRange()
sorter = SortImports(file_contents=document.text(), add_imports=add_imports, remove_imports=remove_imports,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 7; 2, function_name:_get_line; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, identifier:str; 7, block; 7, 8; 7, 18; 7, 24; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:line; 11, subscript; 11, 12; 11, 15; 12, attrib... | def _get_line(self) -> str:
line = self.in_lines[self.index]
self.index += 1
return line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 1, 24; 2, function_name:_add_comments; 3, parameters; 3, 4; 3, 5; 3, 17; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:comments; 7, type; 7, 8; 8, generic_type; 8, 9; 8, 10; 9, identifier:Optional; 10, type_parameter; 10, 11; 11, type; 11, ... | def _add_comments(
self,
comments: Optional[Sequence[str]],
original_string: str = ""
) -> str:
if self.config['ignore_comments']:
return self._strip_comments(original_string)[0]
if not comments:
return original_string
else:
return ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:_wrap; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:line; 7, type; 7, 8; 8, identifier:str; 9, type; 9, 10; 10, identifier:str; 11, block; 11, 12; 11, 20; 11, 370; 12, expression_statement;... | def _wrap(self, line: str) -> str:
wrap_mode = self.config['multi_line_output']
if len(line) > self.config['line_length'] and wrap_mode != WrapModes.NOQA:
line_without_comment = line
comment = None
if '
line_without_comment, comment = line.split('
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_formatter; 3, parameters; 3, 4; 4, identifier:name; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 12; 7, identifier:k; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 11, identifier:_FORMATTERS; 12, block; 12, 13; ... | def get_formatter(name):
for k in sorted(_FORMATTERS):
if k.startswith(name):
return _FORMATTERS[k] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:call_once; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 15; 5, 35; 5, 73; 5, 79; 5, 88; 5, 100; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:argspec; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12... | def call_once(func):
argspec = inspect.getargspec(func)
if argspec.args or argspec.varargs or argspec.keywords:
raise ValueError('Can only decorate functions with no args', func, argspec)
@functools.wraps(func)
def _wrapper():
if not _wrapper.HasRun():
_wrapper.MarkAsRun()
_wrapper.return_va... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:paginate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:self; 5, identifier:model_class; 6, identifier:order_by; 7, default_parameter; 7, 8; 7, 9; 8, identifier:page_num; 9, integer:1; 10, default_parameter; 10, 11;... | def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None):
'''
Selects records and returns a single page of model instances.
- `model_class`: the model class matching the query's table,
or `None` for getting back instances of an ad-hoc model.
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compute_memory_contents_under_schedule; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:schedule; 6, block; 6, 7; 6, 15; 6, 21; 6, 25; 6, 117; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:out_degree; 10,... | def compute_memory_contents_under_schedule(self, schedule):
out_degree = self._compute_initial_out_degree()
curr_memory_contents = set()
memory_contents_for_each_operation = []
for operation_id in schedule:
operation_name = self._operations[operation_id].name
for output_name in self.get_oper... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 14; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:by; 7, type; 7, 8; 8, identifier:str; 9, typed_default_parameter; 9, 10; 9, 11; 9, 13; 10, identifier:out; 11, type; 11, 12;... | def sort(self, by: str, out: object = '', **kwargs) -> 'SASdata':
outstr = ''
options = ''
if out:
if isinstance(out, str):
fn = out.partition('.')
if fn[1] == '.':
libref = fn[0]
table = fn[2]
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:find_items; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:self; 5, identifier:q; 6, default_parameter; 6, 7; 6, 8; 7, identifier:shape; 8, identifier:ID_ONLY; 9, default_parameter; 9, 10; 9, 11;... | def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None,
calendar_view=None, page_size=None, max_items=None, offset=0):
if shape not in SHAPE_CHOICES:
raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES))
if depth... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.