Пример #1
0
def gen_report(request):
    try:
        params = json.loads(request.body)
        specimenid = params['specimenid']
        specimen = Specimen.objects.get(specimenid=specimenid)
        if specimen is None:
            return em.create_fail_response('object not exist', em.FAIL)

        specimengates = SpecimenGate.objects.filter(specimenid=specimenid)
        render = PdfReportRender(specimen, specimengates)
        filename = render.render_report()
        createtime = datetime.datetime.now()
        try:
            hisreport = SpecimenReport.objects.get(specimenid=specimenid)
            hisreport.delete()
        except Exception as e:
            logger.exception(e)

        report = SpecimenReport(specimenid=specimenid,
                                specimenreportpath=filename,
                                createtime=createtime)
        report.save()
        logger.info('report file:' + filename)
        return em.create_sucess_response(report.to_json())
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #2
0
def query_gate(request):
    try:
        params = json.loads(request.body)
        specimenid = params['specimenid']
        gates = SpecimenGate.objects.get(specimenid=specimenid)
        result = []
        for gate in gates:
            result.append(gate.to_json())
        return em.create_sucess_response(result)
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #3
0
def query_report(request):
    try:
        params = json.loads(request.body)
        specimenid = params['specimenid']
        report = SpecimenReport.objects.filter(
            specimenid=specimenid).order_by('createtime')[0]
        return em.create_sucess_response({
            'filename': report.specimenreportpath,
            'token': datetime.datetime.now()
        })
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #4
0
def query_specimen_fcsfiles(request):
    try:
        params = json.loads(request.body)
        specimenid = params['specimenid']
        specimen = Specimen.objects.get(specimenid=specimenid)
        querysubdir = specimen.specimendir
        response = {}
        fcsfilenames = [
            filename for filename in os.listdir(get_fcsfiledir(querysubdir))
            if re.search('.fcs$', filename)
        ]
        return em.create_sucess_response({'fcsfilenames': fcsfilenames})
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #5
0
def query_specimen_fcsfile_data(request):
    try:
        params = json.loads(request.body)
        filename = params['filename']
        specimenid = params['specimenid']
        specimen = Specimen.objects.get(specimenid=specimenid)
        if specimen is None:
            logger.error('param vaild')

        querysubdir = specimen.specimendir
        cols = {}
        meta, df = fcsparser.parse(get_fcsfilepath(querysubdir, filename))
        for col in numpy.array(df.columns).tolist():
            cols[col] = df[col].tolist()
        cols['filename'] = filename
        cols['specimenid'] = specimenid
        return em.create_sucess_response(cols)
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #6
0
def cell_stat(request):
    try:
        params = json.loads(request.body)
        filename = params['fcsfilename']
        specimenid = params['specimenid']
        polygons = params['polygongate']
        specimen = Specimen.objects.get(specimenid=specimenid)
        meta, df = fcsparser.parse(
            get_fcsfilepath(specimen.specimendir, filename))
        actual_x = df[SSC_A]
        actual_y = df[PerCP_A]
        gate = Gate()
        gate.load(polygons)
        x = actual_x.values.reshape(actual_x.values.size, 1)
        y = actual_y.values.reshape(actual_y.values.size, 1)
        points = numpy.concatenate((x, y), axis=1)
        result = gate.stat(points)
        result['detail'] = {}
        return em.create_sucess_response(result)
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)
Пример #7
0
def save_spceiment_fcsfile_gate(request):
    try:
        params = json.loads(request.body)
        # delete history gate
        hisgates = SpecimenGate.objects.filter(
            specimenid=params['specimenid'],
            fcsfilename=params['fcsfilename'],
            gatetype=params['gatetype'])
        if hisgates is not None:
            hisgates.delete()
            logger.info("delete history gate success")

        now_time = datetime.datetime.now()
        gate = SpecimenGate(specimenid=params['specimenid'],
                            fcsfilename=params['fcsfilename'],
                            gates=json.dumps(params['gates']),
                            gatetype=params['gatetype'],
                            createtime=now_time,
                            modifytime=now_time)
        gate.save()
        return em.create_sucess_response(gate.to_json())
    except Exception as e:
        logger.exception(e)
        return em.create_fail_response(e, em.FAIL)