code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
# Make a list of all task configurations needed to supervise
sup_configs = sorted(dependencies.keys())
try:
logging.info("Validating supervisor data...")
# Make an api call to list task configurations in the workspace
r = fapi.list_workspace_configs(args['project'], args['work... | def validate_monitor_tasks(dependencies, args) | Validate that all entries in the supervisor are valid task configurations and
that all permissions requirements are satisfied. | 4.601579 | 4.464048 | 1.030809 |
try:
logging.info("Attempting to recover Supervisor data from " + recovery_file)
with open(recovery_file) as rf:
recovery_data = json.load(rf)
monitor_data = recovery_data['monitor_data']
dependencies = recovery_data['dependencies']
args = recover... | def recover_and_supervise(recovery_file) | Retrieve monitor data from recovery_file and resume monitoring | 3.674647 | 3.410041 | 1.077596 |
''' List accessible workspaces, in TSV form: <namespace><TAB>workspace'''
r = fapi.list_workspaces()
fapi._check_response_code(r, 200)
spaces = []
project = args.project
if project:
project = re.compile('^' + project)
for space in r.json():
ns = space['workspace']['namespa... | def space_list(args) | List accessible workspaces, in TSV form: <namespace><TAB>workspace | 5.06971 | 3.588435 | 1.412791 |
# The return value is the INVERSE of UNIX exit status semantics, (where
# 0 = good/true, 1 = bad/false), so to check existence in UNIX one would do
# if ! fissfc space_exists blah ; then
# ...
# fi
try:
r = fapi.get_workspace(args.project, args.workspace)
fapi._chec... | def space_exists(args) | Determine if the named space exists in the given project (namespace) | 8.71143 | 7.98122 | 1.091491 |
r = fapi.lock_workspace(args.project, args.workspace)
fapi._check_response_code(r, 204)
if fcconfig.verbosity:
eprint('Locked workspace {0}/{1}'.format(args.project, args.workspace))
return 0 | def space_lock(args) | Lock a workspace | 5.998089 | 5.56573 | 1.077682 |
r = fapi.unlock_workspace(args.project, args.workspace)
fapi._check_response_code(r, 204)
if fcconfig.verbosity:
eprint('Unlocked workspace {0}/{1}'.format(args.project,args.workspace))
return 0 | def space_unlock(args) | Unlock a workspace | 5.932284 | 5.493971 | 1.079781 |
r = fapi.create_workspace(args.project, args.workspace,
args.authdomain, dict())
fapi._check_response_code(r, 201)
if fcconfig.verbosity:
eprint(r.content)
return 0 | def space_new(args) | Create a new workspace. | 11.892485 | 9.643991 | 1.23315 |
r = fapi.get_workspace(args.project, args.workspace)
fapi._check_response_code(r, 200)
return r.text | def space_info(args) | Get metadata for a workspace. | 5.704651 | 4.522629 | 1.261357 |
message = "WARNING: this will delete workspace: \n\t{0}/{1}".format(
args.project, args.workspace)
if not args.yes and not _confirm_prompt(message):
return 0
r = fapi.delete_workspace(args.project, args.workspace)
fapi._check_response_code(r, [200, 202, 204, 404])
if fcconfig.v... | def space_delete(args) | Delete a workspace. | 4.016022 | 3.786785 | 1.060536 |
# FIXME: add --deep copy option (shallow by default)
# add aliasing capability, then make space_copy alias
if not args.to_workspace:
args.to_workspace = args.workspace
if not args.to_project:
args.to_project = args.project
if (args.project == args.to_project
and a... | def space_clone(args) | Replicate a workspace | 4.970095 | 4.71473 | 1.054163 |
''' Retrieve access control list for a workspace'''
r = fapi.get_workspace_acl(args.project, args.workspace)
fapi._check_response_code(r, 200)
result = dict()
for user, info in sorted(r.json()['acl'].items()):
result[user] = info['accessLevel']
return result | def space_acl(args) | Retrieve access control list for a workspace | 4.780094 | 4.38507 | 1.090084 |
acl_updates = [{"email": user,
"accessLevel": args.role} for user in args.users]
r = fapi.update_workspace_acl(args.project, args.workspace, acl_updates)
fapi._check_response_code(r, 200)
errors = r.json()['usersNotFound']
if len(errors):
eprint("Unable to assign rol... | def space_set_acl(args) | Assign an ACL role to list of users for a workspace | 5.157502 | 4.837502 | 1.06615 |
r = fapi.list_workspaces()
fapi._check_response_code(r, 200)
# Parse the JSON for workspace + namespace; then filter by
# search terms: each term is treated as a regular expression
workspaces = r.json()
extra_terms = []
if args.bucket:
workspaces = [w for w in workspaces
... | def space_search(args) | Search for workspaces matching certain criteria | 5.692708 | 5.304138 | 1.073258 |
project = args.project
workspace = args.workspace
chunk_size = args.chunk_size
with open(args.tsvfile) as tsvf:
headerline = tsvf.readline().strip()
entity_data = [l.rstrip('\n') for l in tsvf]
return _batch_load(project, workspace, headerline, entity_data, chunk_size) | def entity_import(args) | Upload an entity loadfile. | 3.972025 | 3.729401 | 1.065057 |
'''Return a list of lines in TSV form that would suffice to reconstitute a
container (set) entity, if passed to entity_import. The first line in
the list is the header, and subsequent lines are the container members.
'''
r = fapi.get_entity(args.project, args.workspace, args.entity_type, arg... | def set_export(args) | Return a list of lines in TSV form that would suffice to reconstitute a
container (set) entity, if passed to entity_import. The first line in
the list is the header, and subsequent lines are the container members. | 6.190633 | 2.975616 | 2.080455 |
r = fapi.list_entity_types(args.project, args.workspace)
fapi._check_response_code(r, 200)
return r.json().keys() | def entity_types(args) | List entity types in a workspace | 4.793005 | 4.544603 | 1.054658 |
r = fapi.get_entities_with_type(args.project, args.workspace)
fapi._check_response_code(r, 200)
return [ '{0}\t{1}'.format(e['entityType'], e['name']) for e in r.json() ] | def entity_list(args) | List entities in a workspace. | 4.550299 | 4.284588 | 1.062016 |
''' List participants within a container'''
# Case 1: retrieve participants within a named data entity
if args.entity_type and args.entity:
# Edge case: caller asked for participant within participant (itself)
if args.entity_type == 'participant':
return [ args.entity.strip() ]
... | def participant_list(args) | List participants within a container | 5.861207 | 5.805262 | 1.009637 |
''' List pairs within a container. '''
# Case 1: retrieve pairs within a named data entity
if args.entity_type and args.entity:
# Edge case: caller asked for pair within a pair (itself)
if args.entity_type == 'pair':
return [ args.entity.strip() ]
# Edge case: pairs for ... | def pair_list(args) | List pairs within a container. | 6.290188 | 6.238305 | 1.008317 |
''' List samples within a container. '''
# Case 1: retrieve samples within a named data entity
if args.entity_type and args.entity:
# Edge case: caller asked for samples within a sample (itself)
if args.entity_type == 'sample':
return [ args.entity.strip() ]
# Edge case:... | def sample_list(args) | List samples within a container. | 5.639068 | 5.644554 | 0.999028 |
msg = "WARNING: this will delete {0} {1} in {2}/{3}".format(
args.entity_type, args.entity, args.project, args.workspace)
if not (args.yes or _confirm_prompt(msg)):
return
json_body=[{"entityType": args.entity_type,
"entityName": args.entity}]
r = fapi.delete_enti... | def entity_delete(args) | Delete entity in a workspace. | 4.271573 | 4.10869 | 1.039643 |
r = fapi.update_repository_method(args.namespace, args.method,
args.synopsis, args.wdl, args.doc,
args.comment)
fapi._check_response_code(r, 201)
if fcconfig.verbosity:
print("Method %s installed to project %s" % (args.... | def meth_new(args) | Submit a new workflow (or update) to the methods repository. | 8.351179 | 6.74987 | 1.237236 |
message = "WARNING: this will delete workflow \n\t{0}/{1}:{2}".format(
args.namespace, args.method, args.snapshot_id)
if not args.yes and not _confirm_prompt(message):
return
r = fapi.delete_repository_method(args.namespace, args.method,
... | def meth_delete(args) | Remove (redact) a method from the method repository | 6.118511 | 5.804845 | 1.054035 |
''' Retrieve WDL for given version of a repository method'''
r = fapi.get_repository_method(args.namespace, args.method,
args.snapshot_id, True)
fapi._check_response_code(r, 200)
return r.text | def meth_wdl(args) | Retrieve WDL for given version of a repository method | 9.111466 | 5.907403 | 1.542381 |
''' Retrieve access control list for given version of a repository method'''
r = fapi.get_repository_method_acl(args.namespace, args.method,
args.snapshot_id)
fapi._check_response_code(r, 200)
acls = sorted(r.json(), key=lambda k: k['user'])
return... | def meth_acl(args) | Retrieve access control list for given version of a repository method | 5.69971 | 4.514194 | 1.26262 |
acl_updates = [{"user": user, "role": args.role} \
for user in set(expand_fc_groups(args.users)) \
if user != fapi.whoami()]
id = args.snapshot_id
if not id:
# get the latest snapshot_id for this method from the methods repo
r = fapi.list_repositor... | def meth_set_acl(args) | Assign an ACL role to a list of users for a workflow. | 3.516549 | 3.478945 | 1.010809 |
groups = None
for user in users:
fcgroup = None
if '@' not in user:
fcgroup = user
elif user.lower().endswith('@firecloud.org'):
if groups is None:
r = fapi.get_groups()
fapi._check_response_code(r, 200)
groups ... | def expand_fc_groups(users) | If user is a firecloud group, return all members of the group.
Caveat is that only group admins may do this. | 3.170025 | 2.968549 | 1.06787 |
r = fapi.list_repository_methods(namespace=args.namespace,
name=args.method,
snapshotId=args.snapshot_id)
fapi._check_response_code(r, 200)
# Parse the JSON for the workspace + namespace
methods = r.json()
results = []
... | def meth_list(args) | List workflows in the methods repository | 4.267213 | 4.083517 | 1.044985 |
'''Invoke a task (method configuration), on given entity in given space'''
# Try to use call caching (job avoidance)? Flexibly accept range of answers
cache = getattr(args, "cache", True)
cache = cache is True or (cache.lower() in ["y", "true", "yes", "t", "1"])
if not args.namespace:
arg... | def config_start(args) | Invoke a task (method configuration), on given entity in given space | 8.934056 | 7.082476 | 1.261431 |
'''Abort a task (method configuration) by submission ID in given space'''
r = fapi.abort_submission(args.project, args.workspace,
args.submission_id)
fapi._check_response_code(r, 204)
return ("Aborted {0} in {1}/{2}".format(args.submission_id,
... | def config_stop(args) | Abort a task (method configuration) by submission ID in given space | 7.990494 | 4.091342 | 1.953025 |
verbose = fcconfig.verbosity
if args.workspace:
if verbose:
print("Retrieving method configs from space {0}".format(args.workspace))
if not args.project:
eprint("No project given, and no default project configured")
return 1
r = fapi.list_workspac... | def config_list(args) | List configuration(s) in the methods repository or a workspace. | 5.150846 | 4.708622 | 1.093918 |
''' Retrieve access control list for a method configuration'''
r = fapi.get_repository_config_acl(args.namespace, args.config,
args.snapshot_id)
fapi._check_response_code(r, 200)
acls = sorted(r.json(), key=lambda k: k['user'])
return map(lambda ac... | def config_acl(args) | Retrieve access control list for a method configuration | 6.075271 | 5.020621 | 1.210064 |
acl_updates = [{"user": user, "role": args.role} \
for user in set(expand_fc_groups(args.users)) \
if user != fapi.whoami()]
id = args.snapshot_id
if not id:
# get the latest snapshot_id for this method from the methods repo
r = fapi.list_repositor... | def config_set_acl(args) | Assign an ACL role to a list of users for a config. | 3.751929 | 3.646334 | 1.028959 |
r = fapi.get_workspace_config(args.project, args.workspace,
args.namespace, args.config)
fapi._check_response_code(r, 200)
# Setting ensure_ascii to False ensures unicode string returns
return json.dumps(r.json(), indent=4, separators=(',', ': '),
... | def config_get(args) | Retrieve a method config from a workspace, send stdout | 4.857651 | 4.641401 | 1.046592 |
r = fapi.get_workspace_config(args.project, args.workspace,
args.namespace, args.config)
fapi._check_response_code(r, 200)
method = r.json()["methodRepoMethod"]
args.namespace = method["methodNamespace"]
args.method = method["methodName"]
args.s... | def config_wdl(args) | Retrieve the WDL for a method config in a workspace, send stdout | 6.309422 | 5.362054 | 1.17668 |
config_1 = config_get(args).splitlines()
args.project = args.Project
args.workspace = args.Workspace
cfg_1_name = args.config
if args.Config is not None:
args.config = args.Config
if args.Namespace is not None:
args.namespace = args.Namespace
config_2 = config_get(args).... | def config_diff(args) | Compare method configuration definitions across workspaces. Ignores
methodConfigVersion if the verbose argument is not set | 3.360673 | 3.382367 | 0.993586 |
'''Install a valid method configuration into a workspace, in one of several
ways: from a JSON file containing a config definition (both file names
and objects are supported); as a string representing the content of such
a JSON file; or as a dict generated from such JSON content, e.g via
... | def config_put(args) | Install a valid method configuration into a workspace, in one of several
ways: from a JSON file containing a config definition (both file names
and objects are supported); as a string representing the content of such
a JSON file; or as a dict generated from such JSON content, e.g via
json.lo... | 5.491509 | 2.03959 | 2.692457 |
'''Attempt to install a new method config into a workspace, by: generating
a template from a versioned method in the methods repo, then launching
a local editor (respecting the $EDITOR environment variable) to fill in
the incomplete input/output fields. Returns True if the config was
su... | def config_new(args) | Attempt to install a new method config into a workspace, by: generating
a template from a versioned method in the methods repo, then launching
a local editor (respecting the $EDITOR environment variable) to fill in
the incomplete input/output fields. Returns True if the config was
successfu... | 14.370977 | 7.059225 | 2.035773 |
r = fapi.delete_workspace_config(args.project, args.workspace,
args.namespace, args.config)
fapi._check_response_code(r, [200,204])
return r.text if r.text else None | def config_delete(args) | Remove a method config from a workspace | 4.849499 | 4.269876 | 1.135747 |
if not (args.tospace or args.toname or args.toproject or args.tonamespace):
raise RuntimeError('A new config name OR workspace OR project OR ' +
'namespace must be given (or all)')
copy = fapi.get_workspace_config(args.fromproject, args.fromspace,
... | def config_copy(args) | Copy a method config to new name/space/namespace/project (or all 4) | 3.123722 | 2.774382 | 1.125916 |
'''Return a dict of attribute name/value pairs: if entity name & type
are specified then attributes will be retrieved from that entity,
otherwise workspace-level attributes will be returned. By default all
attributes attached to the given object will be returned, but a subset
can be selected by spe... | def attr_get(args) | Return a dict of attribute name/value pairs: if entity name & type
are specified then attributes will be retrieved from that entity,
otherwise workspace-level attributes will be returned. By default all
attributes attached to the given object will be returned, but a subset
can be selected by specifying... | 8.889065 | 6.382315 | 1.392765 |
'''Retrieve names of all attributes attached to a given object, either
an entity (if entity type+name is provided) or workspace (if not)'''
args.attributes = None
result = attr_get(args)
names = result.get("__header__",[])
if names:
names = names[1:]
else:
names = result.k... | def attr_list(args) | Retrieve names of all attributes attached to a given object, either
an entity (if entity type+name is provided) or workspace (if not) | 10.190878 | 4.064328 | 2.507396 |
''' Set key=value attributes: if entity name & type are specified then
attributes will be set upon that entity, otherwise the attribute will
be set at the workspace level'''
if args.entity_type and args.entity:
prompt = "Set {0}={1} for {2}:{3} in {4}/{5}?\n[Y\\n]: ".format(
... | def attr_set(args) | Set key=value attributes: if entity name & type are specified then
attributes will be set upon that entity, otherwise the attribute will
be set at the workspace level | 3.116896 | 2.477005 | 1.258333 |
''' Delete key=value attributes: if entity name & type are specified then
attributes will be deleted from that entity, otherwise the attribute will
be removed from the workspace'''
if args.entity_type and args.entities:
# Since there is no attribute deletion endpoint, we must perform 2 steps
... | def attr_delete(args) | Delete key=value attributes: if entity name & type are specified then
attributes will be deleted from that entity, otherwise the attribute will
be removed from the workspace | 3.836501 | 3.549597 | 1.080827 |
if not args.to_workspace:
args.to_workspace = args.workspace
if not args.to_project:
args.to_project = args.project
if (args.project == args.to_project
and args.workspace == args.to_workspace):
eprint("destination project and namespace must differ from"
" ... | def attr_copy(args) | Copy workspace attributes between workspaces. | 2.722123 | 2.636168 | 1.032606 |
r = fapi.health()
fapi._check_response_code(r, 200)
return r.content | def health(args) | Health FireCloud Server | 5.867196 | 5.701084 | 1.029137 |
''' Loop over all sample sets in a workspace, performing a func '''
# Ensure that the requested action is a valid fiss_cmd
fiss_func = __cmd_to_func(args.action)
if not fiss_func:
eprint("invalid FISS cmd '" + args.action + "'")
return 1
# First get the sample set names
r = fapi... | def sset_loop(args) | Loop over all sample sets in a workspace, performing a func | 6.234228 | 5.628 | 1.107716 |
''' Retrieve status of jobs submitted from a given workspace, as a list
of TSV lines sorted by descending order of job submission date'''
r = fapi.list_submissions(args.project, args.workspace)
fapi._check_response_code(r, 200)
statuses = sorted(r.json(), key=lambda k: k['submissionDate'], rever... | def monitor(args) | Retrieve status of jobs submitted from a given workspace, as a list
of TSV lines sorted by descending order of job submission date | 5.76896 | 4.041941 | 1.427275 |
''' Run legacy, Firehose-style workflow of workflows'''
project = args.project
workspace = args.workspace
namespace = args.namespace
workflow = args.workflow
sample_sets = args.sample_sets
recovery_file = args.json_checkpoint
# If no sample sets are provided, run on all sample sets
... | def supervise(args) | Run legacy, Firehose-style workflow of workflows | 4.690404 | 3.930053 | 1.193471 |
if not args.to_workspace:
args.to_workspace = args.workspace
if not args.to_project:
args.to_project = args.project
if (args.project == args.to_project
and args.workspace == args.to_workspace):
eprint("destination project and namespace must differ from"
" ... | def entity_copy(args) | Copy entities from one workspace to another. | 3.057877 | 2.977168 | 1.027109 |
'''Retrieve the list of billing projects accessible to the caller/user, and
show the level of access granted for each (e.g. Owner, User, ...)'''
projects = fapi.list_billing_projects()
fapi._check_response_code(projects, 200)
projects = sorted(projects.json(), key=lambda d: d['projectName'])
... | def proj_list(args) | Retrieve the list of billing projects accessible to the caller/user, and
show the level of access granted for each (e.g. Owner, User, ...) | 8.146361 | 4.401787 | 1.850694 |
''' Validate a workspace configuration: if an entity was specified (i.e.
upon which the configuration should operate), then also validate that
the entity has the necessary attributes'''
r = fapi.validate_config(args.project, args.workspace, args.namespace,
... | def config_validate(args) | Validate a workspace configuration: if an entity was specified (i.e.
upon which the configuration should operate), then also validate that
the entity has the necessary attributes | 3.406346 | 2.830283 | 1.203535 |
# 4 ways to have invalid config:
invalid_inputs = sorted(config_d["invalidInputs"])
invalid_outputs = sorted(config_d["invalidOutputs"])
# Also insert values for invalid i/o
invalid_inputs = [(i, config_d['methodConfiguration']['inputs'][i]) for i in invalid_inputs]
invalid_outputs = [... | def _validate_helper(args, config_d, workspace_d, entity_d=None) | Return FISSFC validation information on config for a certain entity | 5.755045 | 5.65665 | 1.017395 |
answer = input(message + prompt)
return answer in affirmations | def _confirm_prompt(message, prompt="\nAre you sure? [y/yes (default: no)]: ",
affirmations=("Y", "Yes", "yes", "y")) | Display a message, then confirmation prompt, and return true
if the user responds with one of the affirmations. | 7.070701 | 6.089376 | 1.161154 |
value = str(string)
if len(value) == 0:
msg = "No project provided and no default project configured"
raise argparse.ArgumentTypeError(msg)
return value | def _nonempty_project(string) | Argparse validator for ensuring a workspace is provided | 4.539819 | 3.702154 | 1.226264 |
page = 1
all_entities = []
# Make initial request
r = fapi.get_entities_query(namespace, workspace, etype, page=page,
page_size=page_size, sort_direction=sort_direction,
filter_terms=filter_terms)
fapi._check_response_code(r, 200)
resp... | def _entity_paginator(namespace, workspace, etype, page_size=500,
filter_terms=None, sort_direction="asc") | Pages through the get_entities_query endpoint to get all entities in
the workspace without crashing. | 2.356831 | 2.351245 | 1.002376 |
fiss_module = sys.modules[__name__]
# Returns None if string is not a recognized FISS command
func = getattr(fiss_module, cmd, None)
if func and not hasattr(func, 'fiss_cmd'):
func = None
return func | def __cmd_to_func(cmd) | Returns the function object in this module matching cmd. | 5.232221 | 4.845909 | 1.079719 |
if not l:
return False
headers = l.split('\t')
first_col = headers[0]
tsplit = first_col.split(':')
if len(tsplit) != 2:
return False
if tsplit[0] in ('entity', 'update'):
return tsplit[1] in ('participant_id', 'participant_set_id',
's... | def _valid_headerline(l) | return true if the given string is a valid loadfile header | 3.789483 | 3.788381 | 1.000291 |
if fcconfig.verbosity:
print("Batching " + str(len(entity_data)) + " updates to Firecloud...")
# Parse the entity type from the first cell, e.g. "entity:sample_id"
# First check that the header is valid
if not _valid_headerline(headerline):
eprint("Invalid loadfile header:\n" + h... | def _batch_load(project, workspace, headerline, entity_data, chunk_size=500) | Submit a large number of entity updates in batches of chunk_size | 3.959737 | 3.84177 | 1.030706 |
'''Use this entry point to call HL fiss funcs as though from the UNIX CLI.
(see firecloud/tests/highlevel_tests.py:call_cli for usage examples)'''
try:
result = main(argv)
except Exception as e:
result = __pretty_print_fc_exception(e)
# FIXME: we should invert True/False return va... | def main_as_cli(argv=None) | Use this entry point to call HL fiss funcs as though from the UNIX CLI.
(see firecloud/tests/highlevel_tests.py:call_cli for usage examples) | 23.271034 | 6.763853 | 3.4405 |
#First check that all entities are of the same type
types = {e.etype for e in entities}
if len(types) != 1:
raise ValueError("Can't create payload with " +
str(len(types)) + " types")
all_attrs = set()
for e in entities:
... | def create_payload(entities) | Create a tsv payload describing entities.
A TSV payload consists of 1 header row describing entity type
and attribute names. Each subsequent line is an entity_id followed
by attribute values separated by the tab "\\t" character. This
payload can be uploaded to the workspace via
... | 3.059539 | 2.730352 | 1.120565 |
with open(f, 'w') as out:
out.write(Entity.create_payload(entities)) | def create_loadfile(entities, f) | Create payload and save to file. | 6.247815 | 4.086842 | 1.528764 |
gcloud_default_path = ['google-cloud-sdk', 'bin']
if platform.system() != "Windows":
gcloud_default_path = os.path.join(os.path.expanduser('~'),
*gcloud_default_path)
else:
gcloud_default_path = os.path.join(os.envir... | def needs_gcloud(self) | Returns true if gcloud is unavailable and needed for
authentication. | 2.762044 | 2.66828 | 1.03514 |
for input_file in arguments.input_files:
logging.info(input_file)
# Generate a temporary file
with common.atomic_write(
input_file.name, file_factory=common.FileType('wt')) as tf:
convert.transform_file(input_file, tf, arguments)
if hasattr(input_... | def action(arguments) | Run mogrify. Most of the action is in convert, this just creates a temp
file for the output. | 6.087412 | 5.606001 | 1.085874 |
result = [[]]
for c in sequence_str:
result = [i + [a] for i in result for a in _AMBIGUOUS_MAP.get(c, c)]
return [''.join(i) for i in result] | def all_unambiguous(sequence_str) | All unambiguous versions of sequence_str | 3.551231 | 3.507179 | 1.012561 |
parser.add_argument(
'sequence_file',
type=FileType('r'),
help=)
parser.add_argument(
'--input-qual',
type=FileType('r'),
help=)
parser.add_argument(
'output_file',
type=FileType('w'),
help=)
output_group = parser.add_argument... | def build_parser(parser) | Generate a subparser | 2.162974 | 2.159521 | 1.001599 |
it = iter(iterable)
d = collections.deque(itertools.islice(it, n - 1))
d.appendleft(0)
s = sum(d)
for elem in it:
s += elem - d.popleft()
d.append(elem)
yield s / float(n) | def moving_average(iterable, n) | From Python collections module documentation
moving_average([40, 30, 50, 46, 39, 44]) --> 40.0 42.0 45.0 43.0 | 2.05707 | 2.413932 | 0.852166 |
tr = trie.trie()
reader = csv.reader(fp)
if header:
# Skip header
next(reader)
# Skip blank rows
records = (record for record in reader if record)
for record in records:
specimen, barcode = record[:2]
if primer is not None:
pr = primer
... | def parse_barcode_file(fp, primer=None, header=False) | Load label, barcode, primer records from a CSV file.
Returns a map from barcode -> label
Any additional columns are ignored | 5.032435 | 5.240089 | 0.960372 |
if arguments.quality_window_mean_qual and not arguments.quality_window:
raise ValueError("--quality-window-mean-qual specified without "
"--quality-window")
if trie is None or triefind is None:
raise ValueError(
'Missing Bio.trie and/or Bio.triefind mod... | def action(arguments) | Given parsed arguments, filter input files. | 3.124166 | 3.094833 | 1.009478 |
for record in iterable:
self(name, record)
yield record | def iterable_hook(self, name, iterable) | Fire an event named ``name`` with each item in iterable | 8.540811 | 9.862789 | 0.865963 |
assert record.id == self.current_record['sequence_name']
self.current_record['sample'] = sample | def _found_barcode(self, record, sample, barcode=None) | Hook called when barcode is found | 8.896487 | 7.906541 | 1.125206 |
for record in records:
try:
filtered = self.filter_record(record)
assert (filtered)
# Quick tracking whether the sequence was modified
if filtered.seq == record.seq:
self.passed_unchanged += 1
... | def filter_records(self, records) | Apply the filter to records | 4.633291 | 4.599479 | 1.007351 |
quality_scores = record.letter_annotations['phred_quality']
mean_score = mean(quality_scores)
if mean_score >= self.min_mean_score:
return record
else:
raise FailedFilter(mean_score) | def filter_record(self, record) | Filter a single record | 5.515133 | 5.354036 | 1.030089 |
quality_scores = record.letter_annotations['phred_quality']
# Simple case - window covers whole sequence
if len(record) <= self.window_size:
mean_score = mean(quality_scores)
if mean_score >= self.min_mean_score:
return record
else:
... | def filter_record(self, record) | Filter a single record | 5.032946 | 4.958039 | 1.015108 |
nloc = record.seq.find('N')
if nloc == -1:
return record
elif self.action == 'truncate':
return record[:nloc]
elif self.action == 'drop':
raise FailedFilter()
else:
assert False | def filter_record(self, record) | Filter a record, truncating or dropping at an 'N' | 5.452857 | 3.95887 | 1.377377 |
if len(record) >= self.min_length:
return record
else:
raise FailedFilter(len(record)) | def filter_record(self, record) | Filter record, dropping any that don't meet minimum length | 7.349077 | 5.268901 | 1.394803 |
if len(record) >= self.max_length:
return record[:self.max_length]
else:
return record | def filter_record(self, record) | Filter record, truncating any over some maximum length | 3.827832 | 2.601223 | 1.471551 |
is_alignment = True
avg_length = None
min_length = sys.maxsize
max_length = 0
sequence_count = 0
# Get an iterator and analyze the data.
with common.FileType('rt')(source_file) as fp:
if not file_type:
file_type = fileformat.from_handle(fp)
for record in Seq... | def summarize_sequence_file(source_file, file_type=None) | Summarizes a sequence file, returning a tuple containing the name,
whether the file is an alignment, minimum sequence length, maximum
sequence length, average length, number of sequences. | 3.010628 | 2.780783 | 1.082655 |
# Ignore SIGPIPE, for head support
common.exit_on_sigpipe()
common.exit_on_sigint()
handle = arguments.destination_file
output_format = arguments.output_format
if not output_format:
try:
output_format = 'align' if handle.isatty() else 'tab'
except AttributeError... | def action(arguments) | Given one more more sequence files, determine if the file is an alignment,
the maximum sequence length and the total number of sequences. Provides
different output formats including tab (tab-delimited), csv and align
(aligned as if part of a borderless table). | 4.641497 | 4.535552 | 1.023359 |
with tempfile.SpooledTemporaryFile(buffer_size, mode='wb+') as tf:
pickler = pickle.Pickler(tf)
for record in records:
pickler.dump(record)
def record_iter():
tf.seek(0)
unpickler = pickle.Unpickler(tf)
while True:
try:
... | def _record_buffer(records, buffer_size=DEFAULT_BUFFER_SIZE) | Buffer for transform functions which require multiple passes through data.
Value returned by context manager is a function which returns an iterator
through records. | 2.450219 | 2.653841 | 0.923273 |
logging.info(
"Applying _dashes_cleanup: converting any of '{}' to '-'.".format(prune_chars))
translation_table = {ord(c): '-' for c in prune_chars}
for record in records:
record.seq = Seq(str(record.seq).translate(translation_table),
record.seq.alphabet)
... | def dashes_cleanup(records, prune_chars='.:?~') | Take an alignment and convert any undesirable characters such as ? or ~ to
-. | 4.36041 | 3.779189 | 1.153795 |
logging.info('Applying _deduplicate_sequences generator: '
'removing any duplicate records with identical sequences.')
checksum_sequences = collections.defaultdict(list)
for record in records:
checksum = seguid(record.seq)
sequences = checksum_sequences[checksum]
... | def deduplicate_sequences(records, out_file) | Remove any duplicate records with identical sequences, keep the first
instance seen and discard additional occurences. | 4.720343 | 4.183456 | 1.128336 |
logging.info('Applying _deduplicate_taxa generator: ' + \
'removing any duplicate records with identical IDs.')
taxa = set()
for record in records:
# Default to full ID, split if | is found.
taxid = record.id
if '|' in record.id:
try:
... | def deduplicate_taxa(records) | Remove any duplicate records with identical IDs, keep the first
instance seen and discard additional occurences. | 5.125939 | 4.70483 | 1.089506 |
logging.info('Applying _first_name_capture generator: '
'making sure ID only contains the first whitespace-delimited '
'word.')
whitespace = re.compile(r'\s+')
for record in records:
if whitespace.search(record.description):
yield SeqRecord(record.s... | def first_name_capture(records) | Take only the first whitespace-delimited word as the name of the sequence.
Essentially removes any extra text from the sequence's description. | 7.451004 | 5.564649 | 1.338989 |
ids = set(i.strip() for i in handle)
for record in records:
if record.id.strip() in ids:
yield record | def include_from_file(records, handle) | Filter the records, keeping only sequences whose ID is contained in the
handle. | 4.092854 | 3.799107 | 1.07732 |
# Check arguments
if end <= start:
raise ValueError("start of slice must precede end ({0} !> {1})".format(
end, start))
for sequence in sequences:
seq = sequence.seq
start_gap = gap_char * start
end_gap = gap_char * (len(seq) - end)
seq = Seq(start_g... | def isolate_region(sequences, start, end, gap_char='-') | Replace regions before and after start:end with gap chars | 3.597214 | 3.567507 | 1.008327 |
for record in records:
# Generate a set of indices to remove
drop = set(i for slice in slices
for i in range(*slice.indices(len(record))))
keep = [i not in drop for i in range(len(record))]
record.seq = Seq(''.join(itertools.compress(record.seq, keep)), record... | def drop_columns(records, slices) | Drop all columns present in ``slices`` from records | 4.177508 | 4.250261 | 0.982883 |
with _record_buffer(records) as r:
try:
record = next(i for i in r() if i.id == record_id)
except StopIteration:
raise ValueError("Record with id {0} not found.".format(record_id))
new_slices = _update_slices(record, slices)
for record in multi_cut_seque... | def cut_sequences_relative(records, slices, record_id) | Cuts records to slices, indexed by non-gap positions in record_id | 3.944307 | 4.109336 | 0.95984 |
for record in records:
record_indices = list(range(len(record)))
keep_indices = reduce(lambda i, s: i - frozenset(record_indices[s]),
slices, frozenset(record_indices))
seq = ''.join(b if i in keep_indices else '-'
for i, b in enumerat... | def multi_mask_sequences(records, slices) | Replace characters sliced by slices with gap characters. | 4.049739 | 3.75843 | 1.077508 |
for record in records:
if not all(c == '-' for c in str(record.seq)):
yield record | def prune_empty(records) | Remove any sequences which are entirely gaps ('-') | 4.948414 | 3.071051 | 1.61131 |
# Copy the annotations over
for k, v in list(old_record.annotations.items()):
# Trim if appropriate
if isinstance(v, (tuple, list)) and len(v) == len(old_record):
assert len(v) == len(old_record)
v = v[::-1]
new_record.annotations[k] = v
# Letter annotat... | def _reverse_annotations(old_record, new_record) | Copy annotations form old_record to new_record, reversing any
lists / tuples / strings. | 3.212094 | 2.846264 | 1.12853 |
logging.info('Applying _reverse_sequences generator: '
'reversing the order of sites in sequences.')
for record in records:
rev_record = SeqRecord(record.seq[::-1], id=record.id,
name=record.name,
description=record.desc... | def reverse_sequences(records) | Reverse the order of sites in sequences. | 4.559299 | 3.663043 | 1.244675 |
logging.info('Applying _reverse_complement_sequences generator: '
'transforming sequences into reverse complements.')
for record in records:
rev_record = SeqRecord(record.seq.reverse_complement(),
id=record.id, name=record.name,
... | def reverse_complement_sequences(records) | Transform sequences into reverse complements. | 4.253955 | 3.854671 | 1.103585 |
logging.info('Applying _ungap_sequences generator: removing all gap characters')
for record in records:
yield ungap_all(record, gap_chars) | def ungap_sequences(records, gap_chars=GAP_TABLE) | Remove gaps from sequences, given an alignment. | 9.277992 | 9.744833 | 0.952094 |
old_id = record.id
record.id = new_id
# At least for FASTA, record ID starts the description
record.description = re.sub('^' + re.escape(old_id), new_id, record.description)
return record | def _update_id(record, new_id) | Update a record id to new_id, also modifying the ID in record.description | 5.970239 | 5.121632 | 1.165691 |
logging.info('Applying _name_append_suffix generator: '
'Appending suffix ' + suffix + ' to all '
'sequence IDs.')
for record in records:
new_id = record.id + suffix
_update_id(record, new_id)
yield record | def name_append_suffix(records, suffix) | Given a set of sequences, append a suffix for each sequence's name. | 5.679056 | 5.800223 | 0.97911 |
logging.info('Applying _name_insert_prefix generator: '
'Inserting prefix ' + prefix + ' for all '
'sequence IDs.')
for record in records:
new_id = prefix + record.id
_update_id(record, new_id)
yield record | def name_insert_prefix(records, prefix) | Given a set of sequences, insert a prefix for each sequence's name. | 6.3369 | 6.079336 | 1.042367 |
logging.info('Applying _name_include generator: '
'including only IDs matching ' + filter_regex +
' in results.')
regex = re.compile(filter_regex)
for record in records:
if regex.search(record.id) or regex.search(record.description):
yield record | def name_include(records, filter_regex) | Given a set of sequences, filter out any sequences with names
that do not match the specified regular expression. Ignore case. | 5.466459 | 5.653746 | 0.966874 |
regex = re.compile(search_regex)
for record in records:
maybe_id = record.description.split(None, 1)[0]
if maybe_id == record.id:
record.description = regex.sub(replace_pattern, record.description)
record.id = record.description.split(None, 1)[0]
else:
... | def name_replace(records, search_regex, replace_pattern) | Given a set of sequences, replace all occurrences of search_regex
with replace_pattern. Ignore case.
If the ID and the first word of the description match, assume the
description is FASTA-like and apply the transform to the entire
description, then set the ID from the first word. If the ID and
the ... | 2.097433 | 2.003291 | 1.046994 |
regex = re.compile(filter_regex)
for record in records:
if regex.search(str(record.seq)):
yield record | def seq_include(records, filter_regex) | Filter any sequences who's seq does not match the filter. Ignore case. | 2.480295 | 2.409734 | 1.029282 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.