コード例 #1
0
ファイル: dataops.py プロジェクト: v-makarenko/vtoolsmq
    def command(self):
        from qtools.constants.job import JOB_ID_PROCESS_ASSAY
        from qtools.messages.sequence import ProcessSequenceGroupMessage

        app = self.load_wsgi_app()
        mgr = create_manager(app.config)

        if len(self.args) < 3:
            raise ValueError, self.usage

        infile = open(self.args[-3], 'r')
        mode = self.args[-2].lower()

        #read in liens
        lines = [l for l in infile]
        infile.close()

        assay_line_dict = defaultdict(lambda: defaultdict(lambda: None))
        for line in lines:
            toks = self.__split_line(line)
            name = self.__assay_name(toks)
            if not name:
                continue
            comp = self.__assay_component(toks)
            seq = self.__assay_sequence(toks)
            assay_line_dict[name][comp] = seq

        Owner = Session.query(Person).filter_by(name_code=u'NielsK').first()

        for k, v in sorted(assay_line_dict.items()):
            sg = SequenceGroup(name=k,
                               owner_id=Owner.id,
                               gene=v['gene'],
                               kit_type = SequenceGroup.CHEMISTRY_TYPE_TAQMAN,
                               type = {'red': SequenceGroup.ASSAY_TYPE_RED,
                                       'cnv': SequenceGroup.ASSAY_TYPE_CNV,
                                       'snp': SequenceGroup.ASSAY_TYPE_SNP,
                                       'gex': SequenceGroup.ASSAY_TYPE_GEX,
                                       'abs': SequenceGroup.ASSAY_TYPE_ABS}[mode],
                               notes = mode + ' Content Project assay design. ' + \
                                       'Imported from %s' % os.path.basename(self.args[-3]),
                               status = v['status'],
                               analyzed = False)
            fps = Sequence(sequence=v['for'],
                           strand='+')
            rps = Sequence(sequence=v['rev'],
                           strand='+')
            if v['taq']:
                ps = Sequence(sequence=v['taq'],
                              strand='+')

            sg.forward_primers.append(SequenceGroupComponent(
                                        sequence=fps,
                                        role=SequenceGroupComponent.FORWARD_PRIMER,
                                        barcode_label='%s_FP1' % k[:12],
                                        primary=True,
                                        order=0))
            sg.reverse_primers.append(SequenceGroupComponent(
                                        sequence=rps,
                                        role=SequenceGroupComponent.REVERSE_PRIMER,
                                        barcode_label='%s_RP1' % k[:12],
                                        primary=True,
                                        order=0))
            if v['taq']:
                sg.probes.append(SequenceGroupComponent(
                                            sequence=ps,
                                            role=SequenceGroupComponent.PROBE,
                                            barcode_label='%s_P1FM' % k[:11],
                                            primary=True,
                                            order=0,
                                            dye=v['dye'],
                                            quencher='IABkFQ'))
            
            print "Committing %s..." % k
            Session.add(sg)
            Session.commit()
            job_queue = mgr.jobqueue()

            job = job_queue.add(JOB_ID_PROCESS_ASSAY, ProcessSequenceGroupMessage(sg.id))
            sg.pending_job_id = job.id
            Session.commit()