Search is not available for this dataset
text
stringlengths
75
104k
def setup(self, database): """Setup connection to database.""" self.db = database self.hgnc_collection = database.hgnc_gene self.user_collection = database.user self.whitelist_collection = database.whitelist self.institute_collection = database.institute self.even...
def index(context, update): """Create indexes for the database""" LOG.info("Running scout index") adapter = context.obj['adapter'] if update: adapter.update_indexes() else: adapter.load_indexes()
def database(context, institute_name, user_name, user_mail, api_key): """Setup a scout database.""" LOG.info("Running scout setup database") # Fetch the omim information api_key = api_key or context.obj.get('omim_api_key') if not api_key: LOG.warning("Please provide a omim api key with --ap...
def demo(context): """Setup a scout demo instance. This instance will be populated with a case, a gene panel and some variants. """ LOG.info("Running scout setup demo") institute_name = context.obj['institute_name'] user_name = context.obj['user_name'] user_mail = context.obj['user_mail']...
def setup(context, institute, user_mail, user_name): """ Setup scout instances. """ context.obj['institute_name'] = institute context.obj['user_name'] = user_name context.obj['user_mail'] = user_mail if context.invoked_subcommand == 'demo': # Update context.obj settings here ...
def institutes(context, institute_id, json): """Show all institutes in the database""" LOG.info("Running scout view institutes") adapter = context.obj['adapter'] if institute_id: institute_objs = [] institute_obj = adapter.institute(institute_id) if not institute_obj: ...
def parse_genetic_models(models_info, case_id): """Parse the genetic models entry of a vcf Args: models_info(str): The raw vcf information case_id(str) Returns: genetic_models(list) """ genetic_models = [] if models_info: for family_info in models_info.split(',...
def panels(context, institute): """Show all gene panels in the database""" LOG.info("Running scout view panels") adapter = context.obj['adapter'] panel_objs = adapter.gene_panels(institute_id=institute) if panel_objs.count() == 0: LOG.info("No panels found") context.abort() clic...
def add_institute(self, institute_obj): """Add a institute to the database Args: institute_obj(Institute) """ internal_id = institute_obj['internal_id'] display_name = institute_obj['internal_id'] # Check if institute already exists if self.i...
def update_institute(self, internal_id, sanger_recipient=None, coverage_cutoff=None, frequency_cutoff=None, display_name=None, remove_sanger=None, phenotype_groups=None, group_abbreviations=None, add_groups=None): """Update the information for an institute ...
def institute(self, institute_id): """Featch a single institute from the backend Args: institute_id(str) Returns: Institute object """ LOG.debug("Fetch institute {}".format(institute_id)) institute_obj = self.institute_collection....
def institutes(self, institute_ids=None): """Fetch all institutes. Args: institute_ids(list(str)) Returns: res(pymongo.Cursor) """ query = {} if institute_ids: query['_id'] = {'$in': institute_ids} LOG.debug("F...
def match_date(date): """Check if a string is a valid date Args: date(str) Returns: bool """ date_pattern = re.compile("^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])") if re.match(date_pattern, date): return True return False
def get_date(date, date_format = None): """Return a datetime object if there is a valid date Raise exception if date is not valid Return todays date if no date where added Args: date(str) date_format(str) Returns: date_obj(datetime.datetime) ...
def hpo_genes(context, hpo_term): """Export a list of genes based on hpo terms""" LOG.info("Running scout export hpo_genes") adapter = context.obj['adapter'] header = ["#Gene_id\tCount"] if not hpo_term: LOG.warning("Please use at least one hpo term") context.abort() for l...
def parse_genes(transcripts): """Parse transcript information and get the gene information from there. Use hgnc_id as identifier for genes and ensembl transcript id to identify transcripts Args: transcripts(iterable(dict)) Returns: genes (list(dict)): A list with dictionaries th...
def parse_rank_score(rank_score_entry, case_id): """Parse the rank score Args: rank_score_entry(str): The raw rank score entry case_id(str) Returns: rank_score(float) """ rank_score = None if rank_score_entry: for family_info in rank_score_en...
def user(context, institute_id, user_name, user_mail, admin): """Add a user to the database.""" adapter = context.obj['adapter'] institutes = [] for institute in institute_id: institute_obj = adapter.institute(institute_id=institute) if not institute_obj: LOG.warning("Insti...
def parse_transcripts(raw_transcripts, allele=None): """Parse transcript information from VCF variants Args: raw_transcripts(iterable(dict)): An iterable with raw transcript information Yields: transcript(dict) A dictionary with transcript informat...
def check_connection(host='localhost', port=27017, username=None, password=None, authdb=None, max_delay=1): """Check if a connection could be made to the mongo process specified Args: host(str) port(int) username(str) password(str) authdb (str): data...
def init_app(self, app): """Initialize from flask""" uri = app.config.get("MONGO_URI", None) db_name = app.config.get("MONGO_DBNAME", 'scout') try: client = get_connection( host = app.config.get("MONGO_HOST", 'localhost'), por...
def institutes(): """Display a list of all user institutes.""" institute_objs = user_institutes(store, current_user) institutes = [] for ins_obj in institute_objs: sanger_recipients = [] for user_mail in ins_obj.get('sanger_recipients',[]): user_obj = store.user(user_mail) ...
def load_delivery_report(adapter: MongoAdapter, report_path: str, case_id: str, update: bool = False): """ Load a delivery report into a case in the database If the report already exists the function will exit. If the user want to l...
def build_transcript(transcript, build='37'): """Build a transcript object These represents the transcripts that are parsed from the VCF, not the transcript definitions that are collected from ensembl. Args: transcript(dict): Parsed transcript information Returns: ...
def update_user(self, user_obj): """Update an existing user. Args: user_obj(dict) Returns: updated_user(dict) """ LOG.info("Updating user %s", user_obj['_id']) updated_user = self.user_collection.find_one_...
def add_user(self, user_obj): """Add a user object to the database Args: user_obj(scout.models.User): A dictionary with user information Returns: user_info(dict): a copy of what was inserted """ LOG.info("Adding user %s to the dat...
def users(self, institute=None): """Return all users from the database Args: institute(str): A institute_id Returns: res(pymongo.Cursor): A cursor with users """ query = {} if institute: LOG.info("Fetch...
def user(self, email): """Fetch a user from the database. Args: email(str) Returns: user_obj(dict) """ LOG.info("Fetching user %s", email) user_obj = self.user_collection.find_one({'_id': email}) return us...
def delete_user(self, email): """Delete a user from the database Args: email(str) Returns: user_obj(dict) """ LOG.info("Deleting user %s", email) user_obj = self.user_collection.delete_one({'_id': email}) ret...
def build_compound(compound): """Build a compound Args: compound(dict) Returns: compound_obj(dict) dict( # This must be the document_id for this variant variant = str, # required=True # This is the variant id display_name = str, # required ...
def remote_static(): """Stream *large* static files with special requirements.""" file_path = request.args.get('file') range_header = request.headers.get('Range', None) if not range_header and file_path.endswith('.bam'): return abort(500) new_resp = send_file_partial(file_path) return ...
def pileup(): """Visualize BAM alignments.""" vcf_file = request.args.get('vcf') bam_files = request.args.getlist('bam') bai_files = request.args.getlist('bai') samples = request.args.getlist('sample') alignments = [{'bam': bam, 'bai': bai, 'sample': sample} for bam, bai, sampl...
def igv(): """Visualize BAM alignments using igv.js (https://github.com/igvteam/igv.js)""" chrom = request.args.get('contig') if chrom == 'MT': chrom = 'M' start = request.args.get('start') stop = request.args.get('stop') locus = "chr{0}:{1}-{2}".format(chrom,start,stop) LOG.debug(...
def build_disease_term(disease_info, alias_genes={}): """Build a disease phenotype object Args: disease_info(dict): Dictionary with phenotype information alias_genes(dict): { <alias_symbol>: { 'true': hgnc_id or None, ...
def load_exons(adapter, exon_lines, build='37', ensembl_genes=None): """Load all the exons Transcript information is from ensembl. Check that the transcript that the exon belongs to exists in the database Args: adapter(MongoAdapter) exon_lines(iterable): iterable with ensembl exon ...
def parse_variant(variant, case, variant_type='clinical', rank_results_header=None, vep_header=None, individual_positions=None, category=None): """Return a parsed variant Get all the necessary information to build a variant object Args: variant(cyvcf2.Variant)...
def compounds(context, case_id): """ Update all compounds for a case """ adapter = context.obj['adapter'] LOG.info("Running scout update compounds") # Check if the case exists case_obj = adapter.case(case_id) if not case_obj: LOG.warning("Case %s could not be found", case_id...
def add_gene_links(gene_obj, build=37): """Update a gene object with links Args: gene_obj(dict) build(int) Returns: gene_obj(dict): gene_obj updated with many links """ try: build = int(build) except ValueError: build = 37 # Add links that use the hg...
def hgnc(ctx, hgnc_symbol, hgnc_id, build): """ Query the hgnc aliases """ adapter = ctx.obj['adapter'] if not (hgnc_symbol or hgnc_id): log.warning("Please provide a hgnc symbol or hgnc id") ctx.abort() if hgnc_id: result = adapter.hgnc_gene(hgnc_id, build=build) ...
def parse_hgnc_line(line, header): """Parse an hgnc formated line Args: line(list): A list with hgnc gene info header(list): A list with the header info Returns: hgnc_info(dict): A dictionary with the relevant info """ hgnc_gene = {} line = line.rstr...
def parse_hgnc_genes(lines): """Parse lines with hgnc formated genes This is designed to take a dump with genes from HGNC. This is downloaded from: ftp://ftp.ebi.ac.uk/pub/databases/genenames/new/tsv/hgnc_complete_set.txt Args: lines(iterable(str)): An iterable with HGN...
def create_submission(self, user_id, institute_id): """Create an open clinvar submission for a user and an institute Args: user_id(str): a user ID institute_id(str): an institute ID returns: submission(obj): an open clinvar submission object...
def delete_submission(self, submission_id): """Deletes a Clinvar submission object, along with all associated clinvar objects (variants and casedata) Args: submission_id(str): the ID of the submission to be deleted Returns: deleted_objects(int): the numb...
def get_open_clinvar_submission(self, user_id, institute_id): """Retrieve the database id of an open clinvar submission for a user and institute, if none is available then create a new submission and return it Args: user_id(str): a user ID institute_id(str)...
def update_clinvar_id(self, clinvar_id, submission_id ): """saves an official clinvar submission ID in a clinvar submission object Args: clinvar_id(str): a string with a format: SUB[0-9]. It is obtained from clinvar portal when starting a new submission submission_id...
def get_clinvar_id(self, submission_id): """Returns the official Clinvar submission ID for a submission object Args: submission_id(str): submission_id(str) : id of the submission Returns: clinvar_subm_id(str): a string with a format: SUB[0-9]. It is obta...
def add_to_submission(self, submission_id, submission_objects): """Adds submission_objects to clinvar collection and update the coresponding submission object with their id Args: submission_id(str) : id of the submission to be updated submission_objects(tuple): a tup...
def update_clinvar_submission_status(self, user_id, submission_id, status): """Set a clinvar submission ID to 'closed' Args: submission_id(str): the ID of the clinvar submission to close Return updated_submission(obj): the submission object with a 'close...
def clinvar_submissions(self, user_id, institute_id): """Collect all open and closed clinvar submission created by a user for an institute Args: user_id(str): a user ID institute_id(str): an institute ID Returns: submissions(list): a list...
def clinvar_objs(self, submission_id, key_id): """Collects a list of objects from the clinvar collection (variants of case data) as specified by the key_id in the clinvar submission Args: submission_id(str): the _id key of a clinvar submission key_id(str) : either 'v...
def delete_clinvar_object(self, object_id, object_type, submission_id): """Remove a variant object from clinvar database and update the relative submission object Args: object_id(str) : the id of an object to remove from clinvar_collection database collection (a variant of a case) ...
def case_to_clinVars(self, case_id): """Get all variants included in clinvar submissions for a case Args: case_id(str): a case _id Returns: submission_variants(dict): keys are variant ids and values are variant submission objects """ query = dict(case_i...
def parse_hpo_phenotype(hpo_line): """Parse hpo phenotype Args: hpo_line(str): A iterable with hpo phenotype lines Yields: hpo_info(dict) """ hpo_line = hpo_line.rstrip().split('\t') hpo_info = {} hpo_info['hpo_id'] = hpo_line[0] hpo_info['descri...
def parse_hpo_gene(hpo_line): """Parse hpo gene information Args: hpo_line(str): A iterable with hpo phenotype lines Yields: hpo_info(dict) """ if not len(hpo_line) > 3: return {} hpo_line = hpo_line.rstrip().split('\t') hpo_info = {} hpo...
def parse_hpo_disease(hpo_line): """Parse hpo disease line Args: hpo_line(str) """ hpo_line = hpo_line.rstrip().split('\t') hpo_info = {} disease = hpo_line[0].split(':') hpo_info['source'] = disease[0] hpo_info['disease_nr'] = int(disease[1]) hpo_info['hgnc...
def parse_hpo_phenotypes(hpo_lines): """Parse hpo phenotypes Group the genes that a phenotype is associated to in 'genes' Args: hpo_lines(iterable(str)): A file handle to the hpo phenotypes file Returns: hpo_terms(dict): A dictionary with hpo_ids as keys and terms as v...
def parse_hpo_diseases(hpo_lines): """Parse hpo disease phenotypes Args: hpo_lines(iterable(str)) Returns: diseases(dict): A dictionary with mim numbers as keys """ diseases = {} LOG.info("Parsing hpo diseases...") for index, line in enumerate(hp...
def parse_hpo_to_genes(hpo_lines): """Parse the map from hpo term to hgnc symbol Args: lines(iterable(str)): Yields: hpo_to_gene(dict): A dictionary with information on how a term map to a hgnc symbol """ for line in hpo_lines: if line.startswith('#') or len(line) <...
def parse_hpo_genes(hpo_lines): """Parse HPO gene information Args: hpo_lines(iterable(str)) Returns: diseases(dict): A dictionary with hgnc symbols as keys """ LOG.info("Parsing HPO genes ...") genes = {} for index, line in enumerate(hpo_lines):...
def get_incomplete_penetrance_genes(hpo_lines): """Get a set with all genes that have incomplete penetrance according to HPO Args: hpo_lines(iterable(str)) Returns: incomplete_penetrance_genes(set): A set with the hgnc symbols of all genes...
def parse_hpo_obo(hpo_lines): """Parse a .obo formated hpo line""" term = {} for line in hpo_lines: if len(line) == 0: continue line = line.rstrip() # New term starts with [Term] if line == '[Term]': if term: yield term term...
def genes(): """Render seach box for genes.""" query = request.args.get('query', '') if '|' in query: hgnc_id = int(query.split(' | ', 1)[0]) return redirect(url_for('.gene', hgnc_id=hgnc_id)) gene_q = store.all_genes().limit(20) return dict(genes=gene_q)
def gene(hgnc_id=None, hgnc_symbol=None): """Render information about a gene.""" if hgnc_symbol: query = store.hgnc_genes(hgnc_symbol) if query.count() == 1: hgnc_id = query.first()['hgnc_id'] else: return redirect(url_for('.genes', query=hgnc_symbol)) try: ...
def api_genes(): """Return JSON data about genes.""" query = request.args.get('query') json_out = controllers.genes_to_json(store, query) return jsonify(json_out)
def check_panels(adapter, panels, default_panels=None): """Make sure that the gene panels exist in the database Also check if the default panels are defined in gene panels Args: adapter(MongoAdapter) panels(list(str)): A list with panel names Returns: pa...
def load_region(adapter, case_id, hgnc_id=None, chrom=None, start=None, end=None): """Load all variants in a region defined by a HGNC id Args: adapter (MongoAdapter) case_id (str): Case id hgnc_id (int): If all variants from a gene should be uploaded chrom (str): If variants fro...
def load_scout(adapter, config, ped=None, update=False): """Load a new case from a Scout config. Args: adapter(MongoAdapter) config(dict): loading info ped(Iterable(str)): Pedigree ingformation update(bool): If existing case should be updated """ log...
def templated(template=None): """Template decorator. Ref: http://flask.pocoo.org/docs/patterns/viewdecorators/ """ def decorator(f): @wraps(f) def decorated_function(*args, **kwargs): template_name = template if template_name is None: template_nam...
def institute_and_case(store, institute_id, case_name=None): """Fetch insitiute and case objects.""" institute_obj = store.institute(institute_id) if institute_obj is None and institute_id != 'favicon.ico': flash("Can't find institute: {}".format(institute_id), 'warning') return abort(404) ...
def user_institutes(store, login_user): """Preprocess institute objects.""" if login_user.is_admin: institutes = store.institutes() else: institutes = [store.institute(inst_id) for inst_id in login_user.institutes] return institutes
def get_hgnc_id(gene_info, adapter): """Get the hgnc id for a gene The proprity order will be 1. if there is a hgnc id this one will be choosen 2. if the hgnc symbol matches a genes proper hgnc symbol 3. if the symbol ony matches aliases on several genes one will be choos...
def panel(context, panel, version, update_date, update_version): """ Update a panel in the database """ adapter = context.obj['adapter'] # Check that the panel exists panel_obj = adapter.gene_panel(panel, version=version) if not panel_obj: LOG.warning("Panel %s (version %s) could n...
def diseases(context, api_key): """ Update disease terms in mongo database. """ adapter = context.obj['adapter'] # Fetch the omim information api_key = api_key or context.obj.get('omim_api_key') if not api_key: LOG.warning("Please provide a omim api key to load the omim gene pan...
def load_hpo(adapter, disease_lines, hpo_disease_lines=None, hpo_lines=None, hpo_gene_lines=None): """Load the hpo terms and hpo diseases into database Args: adapter(MongoAdapter) disease_lines(iterable(str)): These are the omim genemap2 information hpo_lines(iterable(str)) ...
def load_hpo_terms(adapter, hpo_lines=None, hpo_gene_lines=None, alias_genes=None): """Load the hpo terms into the database Parse the hpo lines, build the objects and add them to the database Args: adapter(MongoAdapter) hpo_lines(iterable(str)) hpo_gene_lines(iterable(str))...
def load_disease_terms(adapter, genemap_lines, genes=None, hpo_disease_lines=None): """Load the omim phenotypes into the database Parse the phenotypes from genemap2.txt and find the associated hpo terms from ALL_SOURCES_ALL_FREQUENCIES_diseases_to_genes_to_phenotypes.txt. Args: adapter(Mon...
def parse_frequencies(variant, transcripts): """Add the frequencies to a variant Frequencies are parsed either directly from keys in info fieds or from the transcripts is they are annotated there. Args: variant(cyvcf2.Variant): A parsed vcf variant transcripts(iterable(dict)): Parsed t...
def parse_frequency(variant, info_key): """Parse any frequency from the info dict Args: variant(cyvcf2.Variant) info_key(str) Returns: frequency(float): or None if frequency does not exist """ raw_annotation = variant.INFO.get(info_key) raw_annotation = None if raw_anno...
def parse_sv_frequencies(variant): """Parsing of some custom sv frequencies These are very specific at the moment, this will hopefully get better over time when the field of structural variants is more developed. Args: variant(cyvcf2.Variant) Returns: sv_frequencies(dict) ...
def users(context): """Show all users in the database""" LOG.info("Running scout view users") adapter = context.obj['adapter'] user_objs = adapter.users() if user_objs.count() == 0: LOG.info("No users found") context.abort() click.echo("#name\temail\troles\tinstitutes") for...
def load_case(adapter, case_obj, update=False): """Load a case into the database If the case already exists the function will exit. If the user want to load a case that is already in the database 'update' has to be 'True' Args: adapter (MongoAdapter): connection to the database cas...
def build_hgnc_gene(gene_info, build='37'): """Build a hgnc_gene object Args: gene_info(dict): Gene information Returns: gene_obj(dict) { '_id': ObjectId(), # This is the hgnc id, required: 'hgnc_id': int, ...
def load_panel(self, parsed_panel): """Load a gene panel based on the info sent A panel object is built and integrity checks are made. The panel object is then loaded into the database. Args: path(str): Path to panel file institute(str): Name of institute that ow...
def load_omim_panel(self, api_key, institute=None): """Create and load the OMIM-AUTO panel""" existing_panel = self.gene_panel(panel_id='OMIM-AUTO') if not existing_panel: LOG.warning("OMIM-AUTO does not exists in database") LOG.info('Creating a first version') ...
def compare_mim_panels(self, existing_panel, new_panel): """Check if the latest version of OMIM differs from the most recent in database Return all genes that where not in the previous version. Args: existing_panel(dict) new_panel(dict) Returns: n...
def update_mim_version(self, new_genes, new_panel, old_version): """Set the correct version for each gene Loop over the genes in the new panel Args: new_genes(set(str)): Set with the new gene symbols new_panel(dict) """ LOG.info('Updating versions for ne...
def add_gene_panel(self, panel_obj): """Add a gene panel to the database Args: panel_obj(dict) """ panel_name = panel_obj['panel_name'] panel_version = panel_obj['version'] display_name = panel_obj.get('display_name', panel_name) if self.gene...
def panel(self, panel_id): """Fetch a gene panel by '_id'. Args: panel_id (str, ObjectId): str or ObjectId of document ObjectId Returns: dict: panel object or `None` if panel not found """ if not isinstance(panel_id, ObjectId): panel_id = Obj...
def delete_panel(self, panel_obj): """Delete a panel by '_id'. Args: panel_obj(dict) Returns: res(pymongo.DeleteResult) """ res = self.panel_collection.delete_one({'_id': panel_obj['_id']}) LOG.warning("Deleting panel %s, version %s" % (panel_obj...
def gene_panel(self, panel_id, version=None): """Fetch a gene panel. If no panel is sent return all panels Args: panel_id (str): unique id for the panel version (str): version of the panel. If 'None' latest version will be returned Returns: gene_pan...
def gene_panels(self, panel_id=None, institute_id=None, version=None): """Return all gene panels If panel_id return all versions of panels by that panel name Args: panel_id(str) Returns: cursor(pymongo.cursor) """ query = {} if panel_id:...
def gene_to_panels(self, case_obj): """Fetch all gene panels and group them by gene Args: case_obj(scout.models.Case) Returns: gene_dict(dict): A dictionary with gene as keys and a set of panel names as value """ ...
def update_panel(self, panel_obj, version=None, date_obj=None): """Replace a existing gene panel with a new one Keeps the object id Args: panel_obj(dict) version(float) date_obj(datetime.datetime) Returns: updated_panel(dict) """...
def add_pending(self, panel_obj, hgnc_gene, action, info=None): """Add a pending action to a gene panel Store the pending actions in panel.pending Args: panel_obj(dict): The panel that is about to be updated hgnc_gene(dict) action(str): choices=['add','delet...
def apply_pending(self, panel_obj, version): """Apply the pending changes to an existing gene panel or create a new version of the same panel. Args: panel_obj(dict): panel in database to update version(double): panel version to update Returns: inserted_id(st...
def clinical_symbols(self, case_obj): """Return all the clinical gene symbols for a case.""" panel_ids = [panel['panel_id'] for panel in case_obj['panels']] query = self.panel_collection.aggregate([ {'$match': {'_id': {'$in': panel_ids}}}, {'$unwind': '$genes'}, ...
def cases(context, case_id, institute, reruns, finished, causatives, research_requested, is_research, status, json): """Interact with cases existing in the database.""" adapter = context.obj['adapter'] models = [] if case_id: case_obj = adapter.case(case_id=case_id) if case_ob...
def emit(self, record): """Emit a record. Format the record and send it to the specified addressees. """ try: import smtplib try: from email.utils import formatdate except ImportError: formatdate = self.date_time ...
def indexes(self, collection=None): """Return a list with the current indexes Skip the mandatory _id_ indexes Args: collection(str) Returns: indexes(list) """ indexes = [] for collection_name in self.collections...
def load_indexes(self): """Add the proper indexes to the scout instance. All indexes are specified in scout/constants/indexes.py If this method is utilised when new indexes are defined those should be added """ for collection_name in INDEXES: existing_indexes = sel...