本文整理汇总了Python中ngi_pipeline.database.classes.CharonSession.project_get_samples方法的典型用法代码示例。如果您正苦于以下问题:Python CharonSession.project_get_samples方法的具体用法?Python CharonSession.project_get_samples怎么用?Python CharonSession.project_get_samples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ngi_pipeline.database.classes.CharonSession
的用法示例。
在下文中一共展示了CharonSession.project_get_samples方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recreate_project_from_db
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def recreate_project_from_db(analysis_top_dir, project_name, project_id):
project_dir = os.path.join(analysis_top_dir, "DATA", project_name)
project_obj = NGIProject(name=project_name,
dirname=project_name,
project_id=project_id,
base_path=analysis_top_dir)
charon_session = CharonSession()
try:
samples_dict = charon_session.project_get_samples(project_id)["samples"]
except CharonError as e:
raise RuntimeError("Could not access samples for project {}: {}".format(project_id, e))
for sample in samples_dict:
sample_id = sample.get("sampleid")
sample_dir = os.path.join(project_dir, sample_id)
sample_obj = project_obj.add_sample(name=sample_id, dirname=sample_id)
sample_obj.status = sample.get("status", "unknown")
try:
libpreps_dict = charon_session.sample_get_libpreps(project_id, sample_id)["libpreps"]
except CharonError as e:
raise RuntimeError("Could not access libpreps for project {} / sample {}: {}".format(project_id,sample_id, e))
for libprep in libpreps_dict:
libprep_id = libprep.get("libprepid")
libprep_obj = sample_obj.add_libprep(name=libprep_id, dirname=libprep_id)
libprep_obj.status = libprep.get("status", "unknown")
try:
seqruns_dict = charon_session.libprep_get_seqruns(project_id, sample_id, libprep_id)["seqruns"]
except CharonError as e:
raise RuntimeError("Could not access seqruns for project {} / sample {} / "
"libprep {}: {}".format(project_id, sample_id, libprep_id, e))
for seqrun in seqruns_dict:
# e.g. 140528_D00415_0049_BC423WACXX
seqrun_id = seqrun.get("seqrunid")
seqrun_obj = libprep_obj.add_seqrun(name=seqrun_id, dirname=seqrun_id)
seqrun_obj.status = seqrun.get("status", "unknown")
return project_obj
示例2: fetch_charon
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def fetch_charon(context, project, threshold, all_samples):
"""
Will fetch samples of the specified project from Charon and print the concordance
"""
try:
# get result from charon
charon_session = CharonSession()
result = charon_session.project_get_samples(project)
samples = {}
for sample in result.get('samples'):
sample_id = sample.get('sampleid')
concordance = float(sample.get('genotype_concordance'))
status = sample.get('genotype_status')
# exclude samples which were not yet checked
if status is not None:
samples[sample_id] = (concordance, status)
# print output
if not all_samples and samples:
print 'Samples below threshold: {}%'.format(threshold)
for sample in sorted(samples.keys()):
concordance, status = samples[sample]
# if --all, we don't care about threshold
if all_samples or concordance <= threshold:
# do not print 0%
if concordance != 0:
print '{} {}% {}'.format(sample, concordance, status)
except Exception, e:
log.error("Can't fetch Charon. Error says: {}".format(str(e)))
示例3: reset_charon_records_by_name
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def reset_charon_records_by_name(project_id, restrict_to_samples=None,
restrict_to_libpreps=None, restrict_to_seqruns=None):
if not restrict_to_samples: restrict_to_samples = []
if not restrict_to_libpreps: restrict_to_libpreps = []
if not restrict_to_seqruns: restrict_to_seqruns = []
charon_session = CharonSession()
LOG.info("Resetting Charon record for project {}".format(project_id))
charon_session.project_reset(projectid=project_id)
LOG.info("Charon record for project {} reset".format(project_id))
for sample in charon_session.project_get_samples(projectid=project_id).get('samples', []):
sample_id = sample['sampleid']
if restrict_to_samples and sample_id not in restrict_to_samples:
LOG.info("Skipping project/sample {}/{}: not in list of samples to use "
"({})".format(project_id, sample_id, ", ".join(restrict_to_samples)))
continue
LOG.info("Resetting Charon record for project/sample {}/{}".format(project_id,
sample_id))
charon_session.sample_reset(projectid=project_id, sampleid=sample_id)
LOG.info("Charon record for project/sample {}/{} reset".format(project_id,
sample_id))
for libprep in charon_session.sample_get_libpreps(projectid=project_id,
sampleid=sample_id).get('libpreps', []):
libprep_id = libprep['libprepid']
if restrict_to_libpreps and libprep_id not in restrict_to_libpreps:
LOG.info("Skipping project/sample/libprep {}/{}/{}: not in list "
"of libpreps to use ({})".format(project_id, sample_id,
libprep_id, ", ".join(restrict_to_libpreps)))
continue
LOG.info("Resetting Charon record for project/sample"
"libprep {}/{}/{}".format(project_id, sample_id, libprep_id))
charon_session.libprep_reset(projectid=project_id, sampleid=sample_id,
libprepid=libprep_id)
LOG.info("Charon record for project/sample/libprep {}/{}/{} "
"reset".format(project_id, sample_id, libprep_id))
for seqrun in charon_session.libprep_get_seqruns(projectid=project_id,
sampleid=sample_id,
libprepid=libprep_id).get('seqruns', []):
seqrun_id = seqrun['seqrunid']
if restrict_to_seqruns and seqrun_id not in restrict_to_seqruns:
LOG.info("Skipping project/sample/libprep/seqrun {}/{}/{}/{}: "
"not in list of seqruns to use ({})".format(project_id,
sample_id,
libprep_id,
seqrun_id,
", ".join(restrict_to_seqruns)))
continue
LOG.info("Resetting Charon record for project/sample/libprep/"
"seqrun {}/{}/{}/{}".format(project_id, sample_id,
libprep_id, seqrun_id))
charon_session.seqrun_reset(projectid=project_id, sampleid=sample_id,
libprepid=libprep_id, seqrunid=seqrun_id)
LOG.info("Charon record for project/sample/libprep/seqrun "
"{}/{}/{}/{} reset".format(project_id, sample_id,
libprep_id, seqrun_id))
示例4: get_samples_from_charon
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def get_samples_from_charon(self, delivery_status='STAGED'):
"""Takes as input a delivery status and return all samples with that delivery status
"""
charon_session = CharonSession()
result = charon_session.project_get_samples(self.projectid)
samples = result.get('samples')
if samples is None:
raise AssertionError('CharonSession returned no results for project {}'.format(self.projectid))
samples_of_interest = []
for sample in samples:
sample_id = sample.get('sampleid')
charon_delivery_status = sample.get('delivery_status')
if charon_delivery_status == delivery_status or delivery_status is None:
samples_of_interest.append(sample_id)
return samples_of_interest
示例5: main
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def main(project):
charon_session = CharonSession()
samples = charon_session.project_get_samples(project)
for sample in samples["samples"]:
charon_session.sample_update(project, sample["sampleid"],
analysis_status= "TO_ANALYZE",
genotype_status=None,
total_autosomal_coverage="0",
total_sequenced_reads="0")
for sample_prep in charon_session.sample_get_libpreps(project, sample["sampleid"])['libpreps']:
seqruns = charon_session.libprep_get_seqruns(project, sample["sampleid"], sample_prep["libprepid"])['seqruns']
for seqrun in seqruns:
charon_session.seqrun_update(project, sample["sampleid"], sample_prep["libprepid"], seqrun["seqrunid"],
mean_autosomal_coverage = "0",
alignment_status = "NOT_RUNNING")
示例6: CharonSession
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
# 2. check sample in charon: if analysis status != ANALISED: skip
charon_config = {
"charon": {
"charon_base_url": "http://charon-dev.scilifelab.se/",
"charon_api_token": "2540c9f62332421289442ebeda0a1601",
}
}
charon_session = CharonSession(config=charon_config)
# genotype_data = {'P4257': {
# 'P4257_1004': {},
# 'P4257_1003': {},
# 'P4257_1002': {},
# 'P4257_1001': {},
# }}
for project_id in genotype_data:
samples = charon_session.project_get_samples(project_id)
samples = samples.get("samples")
for sample in samples:
analysis_status = sample.get("analysis_status")
genotype_status = sample.get("genotype_status")
print(analysis_status)
if analysis_status == "ANALYSED":
# if Genotype Status != 'AVAILABLE':
if not genotype_status != "AVAILABLE":
print("run gatk")
# run gatk genotyping & change status to available
print(sample.get("genotype_status", "bla"))
# todo: 4. run the concordance script
示例7: project_summarize
# 需要导入模块: from ngi_pipeline.database.classes import CharonSession [as 别名]
# 或者: from ngi_pipeline.database.classes.CharonSession import project_get_samples [as 别名]
def project_summarize(projects, verbosity=0):
if type(verbosity) is not int or verbosity < 0:
print_stderr('Invalid verbosity level ("{}"); must be a positive '
'integer; falling back to 0')
verbosity = 0
update_charon_with_local_jobs_status(quiet=True) # Don't send mails
charon_session = CharonSession()
projects_list = []
for project in projects:
try:
project = os.path.basename(locate_project(project))
except ValueError as e:
print_stderr("Skipping project: {}".format(e))
continue
print_stderr('Gathering information for project "{}"...'.format(project))
project_dict = {}
try:
project = charon_session.project_get(project)
except CharonError as e:
print_stderr('Project "{}" not found in Charon; skipping ({})'.format(project, e), file=sys.stderr)
continue
project_dict['name'] = project['name']
project_dict['id'] = project['projectid']
project_dict['status'] = project['status']
samples_list = project_dict['samples'] = []
for sample in charon_session.project_get_samples(project['projectid']).get('samples', []):
sample_dict = {}
sample_dict['id'] = sample['sampleid']
sample_dict['analysis_status'] = sample['analysis_status']
sample_dict['coverage'] = sample['total_autosomal_coverage']
libpreps_list = sample_dict['libpreps'] = []
samples_list.append(sample_dict)
for libprep in charon_session.sample_get_libpreps(project['projectid'],
sample['sampleid']).get('libpreps', []):
libprep_dict = {}
libprep_dict['id'] = libprep['libprepid']
libprep_dict['qc'] = libprep['qc']
seqruns_list = libprep_dict['seqruns'] = []
libpreps_list.append(libprep_dict)
for seqrun in charon_session.libprep_get_seqruns(project['projectid'],
sample['sampleid'],
libprep['libprepid']).get('seqruns', []):
seqrun_dict = {}
seqrun_dict['id'] = seqrun['seqrunid']
seqrun_dict['alignment_status'] = seqrun['alignment_status']
seqrun_dict['coverage'] = seqrun['mean_autosomal_coverage']
if seqrun.get('total_reads'):
seqrun_dict['total_reads'] = seqrun['total_reads']
seqruns_list.append(seqrun_dict)
projects_list.append(project_dict)
if verbosity in (0, 1):
projects_status_list = []
#projects_by_status = collections.defaultdict(dict)
#samples_by_status = collections.defaultdict(set)
#libpreps_by_status = collections.defaultdict(set)
#seqruns_by_status = collections.defaultdict(set)
for project_dict in projects_list:
project_status_dict = {}
project_status_dict['name'] = "{} ({})".format(project_dict['name'], project_dict['id'])
project_status_dict['status'] = project_dict['status']
samples_by_status = project_status_dict['samples_by_status'] = collections.defaultdict(set)
libpreps_by_status = project_status_dict['libpreps_by_status'] = collections.defaultdict(set)
seqruns_by_status = project_status_dict['seqruns_by_status'] = collections.defaultdict(set)
for sample_dict in project_dict.get('samples', []):
#samples_by_status[sample_dict['analysis_status']].add(sample_dict['id'])
sample_status = sample_dict['analysis_status']
libpreps = sample_dict.get('libpreps')
if libpreps:
if not any([libprep["seqruns"] for libprep in libpreps]):
sample_status = "NO_SEQRUNS"
else:
for libprep_dict in libpreps:
libpreps_by_status[libprep_dict['qc']].add(libprep_dict['id'])
for seqrun_dict in libprep_dict.get('seqruns', []):
seqruns_by_status[seqrun_dict['alignment_status']].add(seqrun_dict['id'])
else:
sample_status = "NO_LIBPREPS"
samples_by_status[sample_status].add(sample_dict['id'])
projects_status_list.append(project_status_dict)
print_items = (("Samples", "samples_by_status"),
("Libpreps", "libpreps_by_status"),
("Seqruns", "seqruns_by_status"),)
for project_dict in projects_status_list:
print_stderr("\nProject\n-------")
print_stderr(" Name: {:>40}".format(project_dict['name']))
print_stderr(" Status: {:>40}".format(project_dict['status']))
for name, dict_key in print_items:
status_dict = project_dict[dict_key]
print_stderr("{}\n{}".format(name, "-"*len(name)))
total_items = sum(map(len, status_dict.values()))
# Sort by analysis value
for status, item_set in sorted(status_dict.iteritems(), key=lambda key_value: key_value[0]):
num_items = len(item_set)
percent = (100.00 * num_items) / total_items
print_stderr(" Status: {:<20} ({:>3}/{:<3}) ({:>6.2f}%)".format(status,
num_items,
#.........这里部分代码省略.........