Beispiel #1
0
	def execute(self):

		project = dict(
			id=self.project_id,
			assembly=self.args.assembly or DEFAULT_ASSEMBLY,
			files=self.variants_files)

		self.projects = [init_project_files(project)]

		self.case_conf_builder.add_value("projects", self.projects)

		self._wok_run(MUTATIONS_FLOW_NAME)
Beispiel #2
0
	def execute(self):

		# Gather scan paths from arguments

		scan_paths = []

		for scan_path in self.args.paths:
			if not os.path.isabs(scan_path):
				scan_path = os.path.join(os.getcwd(), scan_path)

			if not os.path.exists(scan_path):
				self.log.error("Path not found: {}".format(scan_path))
				exit(-1)

			scan_paths += [scan_path]

		# Gather includes and excludes from options

		includes = []

		if self.args.include is not None:
			for inc in self.args.include:
				includes += ["^{0}$".format(re.escape(inc))]
		if self.args.include_regex is not None:
			for inc_regex in self.args.include_regex:
				includes += [inc_regex]
		if self.args.include_from is not None:
			for file in self.args.include_from:
				with open(file, "r") as f:
					for line in f:
						line = line.strip()
						if line.startswith("#") or len(line) == 0:
							continue
						includes += ["^{0}$".format(re.escape(line))]

		if len(includes) == 0:
			includes = ["^.*$"]

		excludes = []

		if self.args.exclude is not None:
			for exc in self.args.exclude:
				excludes += ["^{0}$".format(re.escape(exc))]
		if self.args.exclude_regex is not None:
			for exc_regex in self.args.exclude_regex:
				excludes += [exc_regex]
		if self.args.exclude_from is not None:
			for file in self.args.exclude_from:
				with open(file, "r") as f:
					for line in f:
						line = line.strip()
						if line.startswith("#") or len(line) == 0:
							continue
						excludes += ["^{0}$".format(re.escape(line))]

		# compile regular expressions

		includes = [re.compile(inc) for inc in includes]
		excludes = [re.compile(exc) for exc in excludes]

		# scan paths

		self.projects = []
		project_ids = set()
		file_object = {}

		self.log.info("Looking for data projects ...")

		for scan_path in scan_paths:
			for path, project in list_projects(self.log, scan_path):
				if "id" not in project:
					self.log.warn("Discarding project missing 'id': {0}".format(path))
					continue
				if "files" not in project:
					self.log.warn("Discarding project missing 'files': {0}".format(path))
					continue

				project["id"] = normalize_id(project["id"])
				project_id = project["id"]
				if "name" in project:
					project_name = ": " + project["name"]
				else:
					project_name = ""

				if match_id(project_id, includes) and not match_id(project_id, excludes):
					if project_id in project_ids:
						self.log.error("Duplicated project id at {0}".format(path))
						exit(-1)

					self.log.info("  {0}{1} (included)".format(project_id, project_name))

					project = init_project_files(project, os.path.dirname(path), file_object)
					self.projects += [project]
				else:
					self.log.info("  {0}{1} (excluded)".format(project_id, project_name))

		# Create the wok engine and the workflow instance
		
		self.case_conf_builder.add_value("projects", self.projects)

		self._wok_run(MUTATIONS_FLOW_NAME, container="{}-{}".format(self.user_id, self.workspace))
Beispiel #3
0
def run(type):
	if type not in [COHORT_ANALYSIS, SINGLE_TUMOR_ANALYSIS]:
		abort(400)

	if request.method == "GET":
		form = dict(
			ofm_genes_threshold=ONCODRIVEFM_GENES_THRESHOLD,
			ofm_pathways_threshold=ONCODRIVEFM_PATHWAYS_THRESHOLD,
			oclust_genes_threshold=ONCODRIVECLUST_MUTATIONS_THRESHOLD)

		return render_template("analysis.html", type=type, form=form)

	if current_app.wok.cases_count(current_user) >= current_app.config.get("LIMIT_NUM_CASES", 100):
		flash("""There is a limit on the number of simultaneous analysis that can be managed.
		You must remove finished analysis before running new ones.""", "error")
		return redirect(url_for("cases.index"))

	mutations_file = request.files['mutations_file']
	file_name = os.path.basename(mutations_file.filename)

	project_id = request.form['project_name']
	if len(project_id) == 0:
		project_id = os.path.splitext(file_name)[0]

	project_id = unique_project_id(normalize_id(project_id))

	'''
	if not current_user.validated:
		flash("""You can not run an analysis with your data until you are completely registered.
		Please check your email and follow the instructions to validate this account.""", "error")
		flash("Meanwhile you can play with the included examples.")
		return redirect(url_for("examples"))
	'''

	cb = ConfigBuilder()
	cb.add_value("user_id", current_user.nick)
	cb.add_value("workspace", DEFAULT_WORKSPACE)
	cb.add_value("project.id", project_id)

	#case_name = "-".join([current_user.nick, project_id])
	#cb.add_value("wok.instance.name", case_name)

	results_path, project_path, project_temp_path = get_paths(project_id)

	if not current_user.is_anonymous():
		cb.add_value("website.user_id", current_user.nick)

	if type == SINGLE_TUMOR_ANALYSIS: #request.form.get("variants_only") == "1":
		cb.add_value("variants_only", True)
		cb.add_value("skip_oncodrivefm", True)
		cb.add_value("skip_oncodriveclust", True)

	try:
		threshold = request.form["ofm_genes_threshold"]
		if re.match(r"^[1-9]\d*%?$", threshold):
			cb.add_value(ONCODRIVEFM_GENES_THRESHOLD_KEY, threshold)
	except:
		if type == COHORT_ANALYSIS:
			current_app.logger.warn("[{}] Wrong form input: {}={}".format(
				current_user.nick, "ofm_genes_threshold", request.form.get("ofm_genes_threshold")))

	try:
		threshold = request.form["ofm_pathways_threshold"]
		if re.match(r"^[1-9]\d*%?$", threshold):
			cb.add_value(ONCODRIVEFM_PATHWAYS_THRESHOLD_KEY, threshold)
	except:
		if type == COHORT_ANALYSIS:
			current_app.logger.warn("[{}] Wrong form input: {}={}".format(
				current_user.nick, "ofm_pathways_threshold", reuqest.form.get("ofm_pathways_threshold")))

	try:
		threshold = int(request.form["oclust_genes_threshold"])
		if threshold >= 1:
			cb.add_value(ONCODRIVECLUST_GENES_THRESHOLD_KEY, threshold)
	except:
		if type == COHORT_ANALYSIS:
			current_app.logger.warn("[{}] Wrong form input: {}={}".format(
				current_user.nick, "oclust_genes_threshold", request.form.get("oclust_genes_threshold")))

	genes_filter_enabled = request.form.get('genes_filter_enabled') == "1"
	cb.add_value(ONCODRIVEFM_FILTER_ENABLED_KEY, genes_filter_enabled)
	cb.add_value(ONCODRIVECLUST_FILTER_ENABLED_KEY, genes_filter_enabled)
	if genes_filter_enabled:
		try:
			genes_filter_file = request.files['genes_filter_file']
			genes_filter_file_path = os.path.join(project_temp_path, "genes-filter.txt")
			genes_filter_file.save(genes_filter_file_path)
			if os.path.getsize(genes_filter_file_path) != 0:
				cb.add_value(ONCODRIVEFM_GENES_FILTER_KEY, genes_filter_file_path)
				cb.add_value(ONCODRIVECLUST_GENES_FILTER_KEY, genes_filter_file_path)
		except:
			current_app.logger.exception("Error retrieving genes filter from form")

	assembly = request.form.get("assembly", DEFAULT_ASSEMBLY).lower()

	project = dict(
		id=project_id,
		assembly=assembly,
		files=[file_name])

	projects = [init_project_files(project, check_paths=False)]
	cb.add_value("projects", projects)

	properties = dict(
		analysis_type=type,
		path=os.path.relpath(project_path, results_path))

	current_app.logger.info("[{}] Starting analysis {} ...".format(current_user.nick, project_id))

	case = current_app.wok.create_case(current_user, project_id, cb, PROJECT_NAME, MUTATIONS_FLOW_NAME,
									   properties=properties, start=False)

	engine_case = current_app.wok.engine.case(case.engine_name)

	#TODO use a background thread
	upload_files(current_app.logger, case.engine_name, engine_case.storages, projects, streams=[mutations_file.stream])

	current_app.logger.info("[{}] Analysis {} started on case {}...".format(
							current_user.nick, project_id, case.engine_name))

	engine_case.start()

	return redirect(url_for("cases.index", highlight=case.id))
Beispiel #4
0
def run(type):
	if type not in [COHORT_ANALYSIS, SINGLE_TUMOR_ANALYSIS]:
		abort(400)

	if current_app.wok.cases_count(current_user) >= current_app.config.get("LIMIT_NUM_CASES", 100):
		flash("""There is a limit on the number of simultaneous analysis that can be managed.
		You must remove finished analysis before running new ones.""", "error")
		return redirect(url_for("cases.index"))

	cb = ConfigBuilder()
	cb.add_value("user_id", current_user.nick)
	cb.add_value("workspace", DEFAULT_WORKSPACE)

	if not current_user.is_anonymous():
		cb.add_value("website.user_id", current_user.nick)

	conf = get_project_conf()

	if type == COHORT_ANALYSIS:
		project_id = "cohort-example"
		mutations_path = get_examples_path(conf, "meduloblastoma_cohort_tier1.muts")
	elif type == SINGLE_TUMOR_ANALYSIS:
		project_id = "single-tumor-example"
		mutations_path = get_examples_path(conf, "pat4_crc.muts")
		cb.add_value("variants_only", True)
		cb.add_value("skip_oncodrivefm", True)
		cb.add_value("skip_oncodriveclust", True)

	project_id = unique_project_id(project_id)

	cb.add_value("project.id", project_id)

	results_path, project_path, project_temp_path = get_paths(project_id, conf=conf)

	assembly = "hg19"

	project = dict(
		id=project_id,
		assembly=assembly,
		files=[mutations_path])
	projects = [init_project_files(project)]
	cb.add_value("projects", projects)

	properties = dict(
		analysis_type=type,
		path=os.path.relpath(project_path, results_path),
		data_file=mutations_path)

	current_app.logger.info("[{}] Starting example {} ...".format(current_user.nick, project_id))

	case = current_app.wok.create_case(current_user, project_id, cb, PROJECT_NAME, MUTATIONS_FLOW_NAME,
									   properties=properties, start=False)

	engine_case = current_app.wok.engine.case(case.engine_name)

	#TODO use a background thread
	upload_files(current_app.logger, case.engine_name, engine_case.storages, projects)

	current_app.logger.info("[{}] Example {} started on case {}...".format(
								current_user.nick, project_id, case.engine_name))

	engine_case.start()

	return redirect(url_for("cases.index", highlight=case.id))