コード例 #1
0
ファイル: api.py プロジェクト: CGHQ/moneypenny
    def post(self):
        """Add new spof results to the database."""
        read_count = request.form['read_count']
        flowcell_id = request.form['flowcell_id']
        sample_id = request.form['sample_id']
        fastq_files = request.form.getlist('fastq_files')
        trimmed_at_str = request.form.get('trimmed_at')
        completed_at_str = request.form.get('completed_at')
        if trimmed_at_str:
            trimmed_at = dateify(trimmed_at_str)
        else:
            trimmed_at = None
        if completed_at_str:
            completed_at = dateify(completed_at_str)
        else:
            completed_at = None

        flowcell_obj = Flowcell.query.filter_by(flowcell_id=flowcell_id).one()
        sample_obj = Sample.query.filter_by(lims_id=sample_id).one()

        logger.debug('create Spof record')

        filters = dict(flowcell=flowcell_obj, sample=sample_obj,
                       read_count=read_count, trimmed_at=trimmed_at,
                       completed_at=completed_at)
        spof_obj, was_created = utils.get_or_create(Spof, **filters)

        logger.debug('create related FASTQ file objects')
        for fastq_file in fastq_files:
            utils.add_fastq_file(fastq_file, sample_obj, spof_obj)

        db.session.commit()
        new_spof = Spof.query.filter_by(flowcell=flowcell_obj,
                                        sample=sample_obj).one()
        return new_spof.to_json()
コード例 #2
0
def test_dateify():
    regular_date_str = '2015-02-17T19:31:24'
    regular_date = dateify(regular_date_str)
    assert regular_date.year == 2015
    assert regular_date.month == 2
    assert regular_date.day == 17
    assert regular_date.hour == 19
    assert regular_date.minute == 31
    assert regular_date.second == 24
コード例 #3
0
 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__()
コード例 #4
0
ファイル: api.py プロジェクト: CGHQ/moneypenny
    def post(self):
        """Register a new upload to Scout."""
        cust_id = request.form['cust_id']
        case_id = request.form['case_id']
        uploaded_at = request.form['uploaded_at']

        analysis_obj = utils.latest_analysis(cust_id, case_id)
        upload_date = dateify(uploaded_at)
        upload_obj = Upload(uploaded_at=upload_date, analysis=analysis_obj)
        utils.commit(upload_obj)
        return upload_obj.to_json()
コード例 #5
0
    def add_analysis(self, cust_id, case_id, analysis_type, analyzed_at):
        """Add an Analysis to the database."""
        logger.debug('fetch related case')
        case_obj = self._get_case(cust_id, case_id)
        logger.debug('create new Analysis record')
        analyzed_date = dateify(analyzed_at)
        analysis_obj = Analysis(case=case_obj, type=analysis_type,
                                started_at=analyzed_date)

        logger.debug('commit to database')
        self.add_commit(analysis_obj)
コード例 #6
0
ファイル: api.py プロジェクト: CGHQ/moneypenny
 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()
コード例 #7
0
ファイル: api.py プロジェクト: CGHQ/moneypenny
 def post(self):
     """Add an Analysis to the database."""
     cust_id = request.form['cust_id']
     case_id = request.form['case_id']
     analysis_type = request.form['analysis_type']
     analyzed_at = request.form['analyzed_at']
     logger.debug('fetch related case')
     case_obj = utils.get_case(cust_id, case_id)
     logger.debug('create new Analysis record')
     analyzed_date = dateify(analyzed_at)
     analysis_obj = Analysis(case=case_obj, type=analysis_type,
                             started_at=analyzed_date)
     logger.debug('commit to database')
     utils.commit(analysis_obj)
     new_analysis = Analysis.query.filter_by(case=case_obj,
                                             started_at=analyzed_date).one()
     return new_analysis.to_json()
コード例 #8
0
 def add_genotyping(self, sample_id, started_at, matches, mismatches,
                    unknowns, is_failed=False, deviation=None,
                    dev_category=None):
     """Add genotyping record to database."""
     started_date = dateify(started_at)
     sample_obj = self.db.query(Sample).filter_by(lims_id=sample_id).one()
     analysis_obj = (self.db.query(Analysis)
                         .filter_by(case=sample_obj.case,
                                    started_at=started_date)).one()
     genotyping_obj = Genotyping(sample=sample_obj, matches=matches,
                                 mismatches=mismatches, unknowns=unknowns,
                                 is_failed=is_failed,
                                 deviation_category=dev_category,
                                 deviation_no=deviation,
                                 analysis=analysis_obj)
     self.db.add(genotyping_obj)
     self.db.save()
     return genotyping_obj.__json__()
コード例 #9
0
ファイル: spofs.py プロジェクト: CGHQ/cghq
def post_symlink_spof(demux_root, flowcell_id, sample_id, reason='analysis'):
    """Assemble/symlink files for a sample flowcell directory.

    Args:
        demux_root (str): root path to demux folder
        sample_id (str): globally unique sample id
        flowcell_id (str): flowcell id
    """
    logger.debug('gather information from LIMS')
    sample_res = glue.get('lims', 'samples', sample_id)
    analysis_type = sample_res.json['analysis_type']
    case_id = sample_res.json['family_id']
    cust_id = sample_res.json['customer']

    logger.debug('gather information from status db')
    spof_res = glue.get('moneypenny', 'spofs', flowcell_id, sample_id)
    demux_folder = spof_res.json['flowcell']['demux_folder']
    demuxed_at = dateify(spof_res.json['flowcell']['demuxed_at']).date()
    spof_dir = build_sampledir(demux_root, demux_folder, sample_id)
    fastq_paths = [spof_dir.joinpath(fq_file['file_name'])
                   for fq_file in spof_res.json['fastq_files']]

    logger.debug("symlink FASTQ files for %s/%s", sample_id, flowcell_id)
    payload = {'cust_id': cust_id, 'case_id': case_id,
               'analysis_type': analysis_type, 'fastq_paths': fastq_paths,
               'demuxed_at': demuxed_at.strftime('%y%m%d')}
    symlink_res = glue.post('assemble', 'spofs', 'prepare', flowcell_id,
                            sample_id, data=payload)

    for fastq_path, symlink_path in symlink_res.json['symlinks']:
        fastq_file = path(fastq_path).basename()
        data = {'fastq_file': fastq_file, 'symlink': symlink_path,
                'flowcell_id': flowcell_id, 'reason': reason}
        glue.post('moneypenny', 'symlinks', data=data)

    return symlink_res.json
コード例 #10
0
ファイル: api.py プロジェクト: CGHQ/moneypenny
    def post(self):
        """Add genotyping record to database."""
        started_at = request.form['started_at']
        sample_id = request.form['sample_id']
        matches = request.form['matches']
        mismatches = request.form['mismatches']
        unknowns = request.form['unknowns']
        is_failed = True if request.form.get('is_failed') else False
        dev_category = request.form.get('dev_category')
        deviation = request.form.get('deviation')

        started_date = dateify(started_at)
        sample_obj = Sample.query.filter_by(lims_id=sample_id).one()
        analysis_obj = Analysis.query.filter_by(case=sample_obj.case,
                                                started_at=started_date).one()
        genotyping_obj = Genotyping(sample=sample_obj, matches=matches,
                                    mismatches=mismatches, unknowns=unknowns,
                                    is_failed=is_failed,
                                    deviation_category=dev_category,
                                    deviation_no=deviation,
                                    analysis=analysis_obj)
        utils.commit(genotyping_obj)
        new_genotyping = Genotyping.query.filter_by(sample=sample_obj).one()
        return new_genotyping.to_json()
コード例 #11
0
 def add_upload(self, cust_id, case_id, uploaded_at=None):
     """Register a new upload to Scout."""
     analysis_obj = self._find_analysis(cust_id, case_id)
     upload_date = dateify(uploaded_at)
     upload_obj = Upload(uploaded_at=upload_date, analysis=analysis_obj)
     self.add_commit(upload_obj)