Esempio n. 1
0
def create_sample(session, metadata):
    study, new = funcs.get_or_create(
        session, Study, name=metadata['study_name'])

    if new:
        logger.info('Created new study "{}"'.format(study.name))
        session.commit()

    sample, new = funcs.get_or_create(
        session, Sample, name=metadata['sample_name'], study=study)
    if new:
        logger.info('Created new sample "{}"'.format(sample.name))
        for key, value in metadata.items():
            if key not in REQUIRED_FIELDS:
                session.add(SampleMetadata(
                    sample=sample,
                    key=key,
                    value=value
                ))

        subject, new = funcs.get_or_create(
            session, Subject, study=study,
            identifier=metadata['subject'])
        sample.subject = subject
        session.commit()
    else:
        logger.error(
            'Sample "{}" already exists'.format(metadata['sample_name']))
        return
    return sample
Esempio n. 2
0
def run_import(session, args, remaps=None):
    v_germlines = VGermlines(args.v_germlines)
    j_germlines = JGermlines(args.j_germlines, args.upstream_of_cdr3,
                             args.anchor_len, args.min_anchor_len)

    study, new = funcs.get_or_create(session, Study, name=args.study_name)

    if new:
        logger.info('Created new study "{}"'.format(study.name))
        session.commit()

    sample, new = funcs.get_or_create(session,
                                      Sample,
                                      name=args.sample_name,
                                      study=study)
    if new:
        sample.date = args.date
        logger.info('Created new sample "{}"'.format(sample.name))
        for key in ('subset', 'tissue', 'disease', 'lab', 'experimenter',
                    'ig_class', 'v_primer', 'j_primer'):
            setattr(sample, key, vars(args).get(key, None))
        subject, new = funcs.get_or_create(session,
                                           Subject,
                                           study=study,
                                           identifier=args.subject)
        sample.subject = subject
        session.commit()
    else:
        loger.error('Sample "{}" already exists'.format(args.sample_name))
        return

    with open(args.input_file) as fh:
        read_file(session, fh, sample, v_germlines, j_germlines, args, remaps)
Esempio n. 3
0
    def _setup_sample(self, meta):
        self._sync_lock.acquire()
        self._session.commit()
        study, new = funcs.get_or_create(self._session,
                                         Study,
                                         name=meta['study_name'])

        if new:
            self.info('\tCreated new study "{}"'.format(study.name))
            self._session.commit()

        name = meta['sample_name']
        sample, new = funcs.get_or_create(self._session,
                                          Sample,
                                          name=name,
                                          study=study)
        if new:
            sample.date = meta['date']
            self.info('\tCreated new sample "{}"'.format(sample.name))
            for key in ('subset', 'tissue', 'disease', 'lab', 'experimenter',
                        'ig_class', 'v_primer', 'j_primer'):
                setattr(sample, key, meta.get(key, None))
            subject, new = funcs.get_or_create(self._session,
                                               Subject,
                                               study=study,
                                               identifier=meta['subject'])
            sample.subject = subject

        self._session.commit()
        self._sync_lock.release()

        return study, sample
Esempio n. 4
0
def setup_sample(session, meta):
    study, new = funcs.get_or_create(session, Study, name=meta['study_name'])

    if new:
        logger.info('Created new study "{}"'.format(study.name))
        session.commit()

    name = meta['sample_name']
    sample, new = funcs.get_or_create(session, Sample, name=name, study=study)

    if new:
        subject, new = funcs.get_or_create(session,
                                           Subject,
                                           study=study,
                                           identifier=meta['subject'])
        sample.subject = subject

        for key, value in meta.items():
            if key not in REQUIRED_FIELDS:
                session.add(SampleMetadata(sample=sample, key=key,
                                           value=value))

    session.commit()
    return sample
def setup_sample(session, meta):
    study, new = funcs.get_or_create(session, Study, name=meta['study_name'])

    if new:
        logger.info('Created new study "{}"'.format(study.name))
        session.commit()

    name = meta['sample_name']
    sample, new = funcs.get_or_create(session, Sample, name=name, study=study)

    if new:
        subject, new = funcs.get_or_create(
            session, Subject, study=study,
            identifier=meta['subject'])
        sample.subject = subject

        for key, value in meta.items():
            if key not in REQUIRED_FIELDS:
                session.add(SampleMetadata(
                    sample=sample, key=key, value=value
                ))

    session.commit()
    return sample