Пример #1
0
 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
Пример #2
0
    def match(self, sample_id):
        """Match a genotype fingerprint against all the samples."""
        with codecs.open(self.db.reference, 'r') as rs_stream:
            result = compare_sample(self.db, sample_id, rs_stream)

        if result.get('confirmed_at'):
            result['confirmed_at'] = stringify_date(result['confirmed_at'])
        return result
Пример #3
0
 def start(self, cust_id, case_id, seq_type=None, gene_list=None,
           mip_config=None):
     """Start a new analysis."""
     case_obj = self.api.start(cust_id, case_id, seq_type=seq_type,
                               gene_list=gene_list, mip_config=mip_config)
     data = {'cust_id': cust_id, 'case_id': case_id,
             'analyzed_at': stringify_date(case_obj.analyzed_at),
             'type': seq_type}
     return data
Пример #4
0
    def get(self, cust_id, case_id, seq_type=None):
        """Return data on an analysis."""
        case_obj = self._get_case(cust_id, case_id, seq_type)
        id_mapping = self._map_sample_ids(case_obj.ped.individuals)

        analysis_type = 'WGS' if case_obj.is_wgs else 'EXO'
        analysis_data = {
            'analyzed_at': stringify_date(case_obj.analyzed_at),
            'is_complete': case_obj.is_complete,
            'ready_vcf': case_obj.ready_vcf,
            'analysis_type': analysis_type,
            'id_mapping': id_mapping,
            'chanjo_output': dict(case_obj.chanjo_sample_outputs()),
        }

        if case_obj.is_complete:
            finished_at = modification_date(case_obj.sampleinfo_path)
            analysis_data['finished_at'] = stringify_date(finished_at)

        return analysis_data
Пример #5
0
    def status(self, case_obj):
        """Check the status of an (existing) analysis.

        Args:
            case_obj (Family): initialized case class object
        """
        logger.debug('load MIP family')
        payload = {'status': analysis_status(case_obj)}
        if payload['status'] == 'finished':
            finish_date = modification_date(case_obj.sampleinfo_path)
            payload['finished_at'] = stringify_date(finish_date)
        return payload
Пример #6
0
    def __json__(self):
        """
        Converts all the properties of the object into a dict for use in json.
        You can define the following in your class

        _json_eager_load:
            list of which child classes need to be eagerly loaded. This applies
            to one-to-many relationships defined in SQLAlchemy classes.

        _base_blacklist:
            top level blacklist list of which properties not to include in JSON

        _json_blacklist:
            blacklist list of which properties not to include in JSON

        :param request: Pyramid Request object
        :type request: <Request>
        :return: dictionary ready to be jsonified
        :rtype: <dict>
        """

        props = {}

        # grab the json_eager_load set, if it exists
        # use set for easy 'in' lookups
        json_eager_load = set(getattr(self, '_json_eager_load', []))
        # now load the property if it exists
        # (does this issue too many SQL statements?)
        for prop in json_eager_load:
            getattr(self, prop, None)

        # we make a copy because the dict will change if the database
        # is updated / flushed
        options = self.__dict__.copy()

        # setup the blacklist
        # use set for easy 'in' lookups
        blacklist = set(getattr(self, '_base_blacklist', []))
        # extend the base blacklist with the json blacklist
        blacklist.update(getattr(self, '_json_blacklist', []))

        for key in options:
            # skip blacklisted, private and SQLAlchemy properties
            if key in blacklist or key.startswith(('__', '_sa_')):
                continue

            # format and date/datetime/time properties to isoformat
            obj = getattr(self, key)
            if isinstance(obj, (datetime, date, time)):
                props[key] = stringify_date(obj)  # .isoformat()
            else:
                # get the class property value
                attr = getattr(self, key)
                # let see if we need to eagerly load it
                if key in json_eager_load:
                    # this is for SQLAlchemy foreign key fields that
                    # indicate with one-to-many relationships
                    if not hasattr(attr, 'pk') and attr:
                        # jsonify all child objects
                        attr = [x.__json__() for x in attr]
                else:
                    # convert all non integer strings to string or if
                    # string conversion is not possible, convert it to
                    # Unicode
                    if attr and not isinstance(attr, (int, float)):
                        try:
                            attr = str(attr)
                        except UnicodeEncodeError:
                            attr = unicode(attr)  # .encode('utf-8')

                props[key] = attr

        return props