Esempio n. 1
0
    def get_or_create(self, model, **filters):
        """Get or create a record in the database.

        Args:
            session (Session): initialized database session
            model (class): SQLAlchemy model for a table
            filters (kwargs): filters to match records

        Returns:
            class, bool: model and weather it was created or not
        """
        query = self.session.query(model).filter_by(**filters)
        instance = query.first()
        if instance:
            return instance, False
        else:
            try:
                params = {key: value for key, value in iteritems(filters)
                          if not isinstance(value, ClauseElement)}
                instance = model(**params)
                self.add(instance)
                self.save()
                return instance, True
            except IntegrityError as exception:
                self.session.rollback()
                raise exception
Esempio n. 2
0
File: api.py Progetto: CGHQ/cghq
def services():
    """Return registered services to interact with."""
    services_dict = {}
    for key, value in iteritems(current_app.config):
        if key.endswith('_HOST'):
            service_id = key.split('_')[0].lower()
            services_dict[service_id] = value
    return jsonify(services=services_dict)
 def scout_config(self, cust_id, case_id, seq_type=None):
     """Build Scout config for a case/analysis."""
     case_obj = self._get_case(cust_id, case_id, seq_type=seq_type)
     scout_data = case_obj.scout_config_clinical()
     for list_key, gene_list in iteritems(scout_data['gene_lists']):
         if gene_list['date']:
             gene_list['date'] = stringify_date(gene_list['date'])
     return scout_data
 def update_analysis(self, cust_id, case_id, **kwargs):
     """Update info for an existing analysis."""
     analysis_obj = self._find_analysis(cust_id, case_id)
     for field, value in iteritems(kwargs):
         if field == 'finished_at':
             analysis_obj.finished_at = dateify(value)
         else:
             setattr(analysis_obj, field, value)
     self.db.save()
     return analysis_obj.__json__()
Esempio n. 5
0
 def put(self, cust_id, case_id):
     """Update info for an existing analysis."""
     analysis_obj = utils.latest_analysis(cust_id, case_id)
     for field, value in iteritems(request.form):
         if field == 'finished_at':
             analysis_obj.finished_at = dateify(value)
         elif field == 'was_successful':
             value = False if value.lower() == 'false' else True
             analysis_obj.was_successful = value
         else:
             setattr(analysis_obj, field, value)
     db.session.commit()
     return analysis_obj.to_json()
Esempio n. 6
0
def post_coverage(cust_id, case_id):
    """Load coverage for all samples in a case."""
    analysis_res = glue.get("analyze", "analyses", cust_id, case_id)
    samples = []
    for sample_id, bed_file in iteritems(analysis_res.json["chanjo_output"]):
        sample_res = glue.get("lims", "samples", sample_id)
        # use customer sample id
        alt_id = sample_res.json["name"]
        load_payload = {"bed_file": bed_file, "sample_id": alt_id, "group_id": case_id}
        glue.post("chanjo", "samples", data=load_payload)
        samples.append(sample_res.json)

    return samples
    def _external_ped(self, ped_individuals):
        id_mapping = self._map_sample_ids(ped_individuals)

        external_individuals = {}
        for individual_id, individual in iteritems(ped_individuals):
            external_id = id_mapping.get(individual_id)
            individual.individual_id = external_id
            individual.mother = id_mapping.get(individual.mother, '0')
            individual.father = id_mapping.get(individual.father, '0')
            # all individuals in the pedigree have been sequenced
            individual.consultand = 'Yes'
            external_individuals[external_id] = individual

        return external_individuals
Esempio n. 8
0
File: api.py Progetto: CGHQ/uscout
    def post(self):
        """Load a case into Scout."""
        variant_threshold = request.form.get('variant_threshold', 5000)
        variant_type = request.form.get('variant_type', 'clinical')
        vcf_config = (request.form.get('vcf_config') or
                      current_app.config['SCOUT_VCF_CONFIG'])

        mongo_info = current_app.config['SCOUT_MONGODB_SETTINGS']
        mongo_auth = {}
        for key, value in iteritems(mongo_info):
            if key == 'db':
                mongo_auth['mongo_db'] = value
            else:
                mongo_auth[key] = value

        scout_config_path = request.form['scout_config']
        scout_config = ConfigParser(scout_config_path)
        load_mongo_db(scout_config, vcf_config, variant_type=variant_type,
                      variant_number_threshold=variant_threshold, **mongo_auth)
        return jsonify(success=True)
    def load_case(
        self, scout_config_path, variant_type="clinical", vcf_config=None, variant_threshold=5000, mongo_auth=None
    ):
        """Load a case into Scout."""
        vcf_config = vcf_config or self.config["scout"]["vcf_config"]

        if mongo_auth is None:
            # adapt to scout input
            mongo_info = self.config["scout"]["auth"]
            mongo_auth = {}
            for key, value in iteritems(mongo_info):
                if key == "db":
                    mongo_auth["mongo_db"] = value
                else:
                    mongo_auth[key] = value
        scout_config = ConfigParser(scout_config_path)
        vcf = load_mongo_db(
            scout_config,
            vcf_config,
            variant_type=variant_type,
            variant_number_threshold=variant_threshold,
            **mongo_auth
        )
        return vcf
Esempio n. 10
0
 def _map_sample_ids(self, ped_individuals):
     """Map between internal and external sample ids."""
     id_mapping = {ind_id: (ind.extra_info.get('display_name') or ind_id)
                   for ind_id, ind in iteritems(ped_individuals)}
     return id_mapping
Esempio n. 11
0
File: glue.py Progetto: CGHQ/cghq
 def init_app(self, app):
     """Initialize Flask plugin."""
     self.hosts = {key.split('_')[0].lower(): value
                   for key, value in iteritems(app.config)
                   if key.endswith('_HOST')}