def handle(self, *args, **options): project_id = args[0] project = Project.objects.get(project_id=project_id) vcf_file_path = os.path.abspath(args[1]) vcf_file = VCFFile.objects.get_or_create(file_path=vcf_file_path)[0] if options.get('clear'): for individual in project.individual_set.all(): individual.vcf_files.clear() if options.get('indiv_id'): individual = Individual.objects.get( project=project, indiv_id=options.get('indiv_id') ) sample_management.add_vcf_file_to_individual(individual, vcf_file) else: sample_management.add_vcf_file_to_project(project, vcf_file) if options.get('load'): print("Loading VCF into project store") xbrowse_controls.load_project(project_id, vcf_files=[vcf_file_path]) print("Loading VCF datastore") xbrowse_controls.load_project_datastore(project_id, vcf_files=[vcf_file_path])
def handle(self, *args, **options): project_id = args[0] project = Project.objects.get(project_id=project_id) vcf_file_path = os.path.abspath(args[1]) vcf_file = VCFFile.objects.get_or_create(file_path=vcf_file_path)[0] if options.get('clear'): for individual in project.individual_set.all(): individual.vcf_files.clear() if options.get('indiv_id'): individual = Individual.objects.get( project=project, indiv_id=options.get('indiv_id')) sample_management.add_vcf_file_to_individual(individual, vcf_file) else: sample_management.add_vcf_file_to_project(project, vcf_file) if options.get('load'): print("Loading VCF into project store") xbrowse_controls.load_project(project_id, vcf_files=[vcf_file_path]) print("Loading VCF datastore") xbrowse_controls.load_project_datastore(project_id, vcf_files=[vcf_file_path])
def transfer_project(self, from_project_id, destination_project_id): print("From: " + from_project_id) print("To: " + destination_project_id) from_project = Project.objects.get(project_id=from_project_id) destination_project = Project.objects.get(project_id=destination_project_id) # Make sure individuals are the same indivs_missing_from_dest_project = (set( [i.indiv_id for i in Individual.objects.filter(project=from_project)]) - set( [i.indiv_id for i in Individual.objects.filter(project=destination_project)])) if indivs_missing_from_dest_project: raise Exception("Individuals missing from dest project: " + str(indivs_missing_from_dest_project)) # update VCFs vcfs = from_project.families_by_vcf().keys() for vcf_file_path in vcfs: vcf_file = VCFFile.objects.get_or_create(file_path=os.path.abspath(vcf_file_path))[0] sample_management.add_vcf_file_to_project(destination_project, vcf_file) print("Added %s to project %s" % (vcf_file, destination_project.project_id)) families_db = get_datastore()._db projects_db = get_project_datastore()._db print("==========") print("Checking 'from' Projects and Families:") if not check_that_exists(projects_db.projects, {'project_id': from_project_id}, not_more_than_one=True): raise ValueError("There needs to be 1 project db in %(from_project_id)s" % locals()) if not check_that_exists(families_db.families, {'project_id': from_project_id}, not_more_than_one=False): raise ValueError("There needs to be atleast 1 family db in %(from_project_id)s" % locals()) print("==========") print("Make Updates:") datestamp = datetime.now().strftime("%Y-%m-%d") if check_that_exists(projects_db.projects, {'project_id': destination_project_id}, not_more_than_one=True): result = update(projects_db.projects, {'project_id': destination_project_id}, {'project_id': destination_project_id+'_previous', 'version': datestamp}) if check_that_exists(families_db.families, {'project_id': destination_project_id}, not_more_than_one=False): result = update(families_db.families, {'project_id': destination_project_id}, {'project_id': destination_project_id+'_previous', 'version': datestamp}) result = update(projects_db.projects, {'project_id': from_project_id}, {'project_id': destination_project_id, 'version': '2'}) result = update(families_db.families, {'project_id': from_project_id}, {'project_id': destination_project_id, 'version': '2'}) print("==========") print("Checking Projects:") if not check_that_exists(projects_db.projects, {'project_id': destination_project_id}, not_more_than_one=True): raise ValueError("After: There needs to be 1 project db in %(destination_project_id)s" % locals()) if not check_that_exists(families_db.families, {'project_id': destination_project_id}, not_more_than_one=False): raise ValueError("After: There needs to be atleast 1 family db in %(destination_project_id)s" % locals()) update_family_analysis_status(destination_project_id) print("Data transfer finished.") i = raw_input("Delete the 'from' project: %s? [Y/n] " % from_project_id) if i.strip() == 'Y': sample_management.delete_project(from_project_id) print("Project %s deleted" % from_project_id) else: print("Project not deleted")
def handle(self, *args, **options): project_id = args[0] project = Project.objects.get(project_id=project_id) project_dir = os.path.abspath(args[1]) project_yaml_file = os.path.join(project_dir, 'project.yaml') project_spec = yaml.load(open(project_yaml_file)) # load in sample IDs that we'll use for the project sample_id_file = os.path.join(project_dir, project_spec['sample_id_list']) sample_ids = [l.strip('\n') for l in open(sample_id_file)] sample_ids = [slugify(s, separator='_') for s in sample_ids] sample_management.add_indiv_ids_to_project(project, sample_ids) # set meta info project.project_name = project_spec['project_name'] project.save() # nicknames if 'nicknames' in project_spec: # todo pass # load individuals if 'ped_files' in project_spec: for relative_path in project_spec['ped_files']: ped_file_path = os.path.join(project_dir, relative_path) sample_management.update_project_from_fam( project, open(ped_file_path)) # todo: add awesome-slugify to above # set VCF files if 'vcf_files' in project_spec: for relative_path in project_spec['vcf_files']: vcf_file_path = os.path.join(project_dir, relative_path) # todo: this should be a fn somewhere that add_vcf_to_project uses too vcf_file = VCFFile.objects.get_or_create( file_path=vcf_file_path)[0] sample_management.add_vcf_file_to_project(project, vcf_file)
def handle(self, *args, **options): project_id = args[0] project = Project.objects.get(project_id=project_id) project_dir = os.path.abspath(args[1]) project_yaml_file = os.path.join(project_dir, 'project.yaml') project_spec = yaml.load(open(project_yaml_file)) # load in sample IDs that we'll use for the project sample_id_file = os.path.join(project_dir, project_spec['sample_id_list']) sample_ids = [l.strip('\n') for l in open(sample_id_file)] sample_ids = [slugify.slugify(s) for s in sample_ids] sample_management.add_indiv_ids_to_project(project, sample_ids) # set meta info project.project_name = project_spec['project_name'] project.save() # nicknames if 'nicknames' in project_spec: # todo pass # load individuals if 'ped_files' in project_spec: for relative_path in project_spec['ped_files']: ped_file_path = os.path.join(project_dir, relative_path) sample_management.update_project_from_fam(project, open(ped_file_path)) # todo: add awesome-slugify to above # set VCF files if 'vcf_files' in project_spec: for relative_path in project_spec['vcf_files']: vcf_file_path = os.path.join(project_dir, relative_path) # todo: this should be a fn somewhere that add_vcf_to_project uses too vcf_file = VCFFile.objects.get_or_create(file_path=vcf_file_path)[0] sample_management.add_vcf_file_to_project(project, vcf_file)
def transfer_project(self, from_project_id, destination_project_id): print("From: " + from_project_id) print("To: " + destination_project_id) from_project = Project.objects.get(project_id=from_project_id) destination_project = Project.objects.get( project_id=destination_project_id) # Make sure individuals are the same indivs_missing_from_dest_project = (set([ i.indiv_id for i in Individual.objects.filter(project=from_project) ]) - set([ i.indiv_id for i in Individual.objects.filter(project=destination_project) ])) if indivs_missing_from_dest_project: raise Exception("Individuals missing from dest project: " + str(indivs_missing_from_dest_project)) # update VCFs vcfs = from_project.families_by_vcf().keys() for vcf_file_path in vcfs: vcf_file = VCFFile.objects.get_or_create( file_path=os.path.abspath(vcf_file_path))[0] sample_management.add_vcf_file_to_project(destination_project, vcf_file) print("Added %s to project %s" % (vcf_file, destination_project.project_id)) families_db = get_datastore(from_project_id)._db projects_db = get_project_datastore(from_project_id)._db print("==========") print("Checking Projects:") check_that_exists(projects_db.projects, {'project_id': from_project_id}, not_more_than_one=True) check_that_exists(projects_db.projects, {'project_id': destination_project_id}, not_more_than_one=True) print("==========") print("Checking Families:") check_that_exists(families_db.families, {'project_id': from_project_id}, not_more_than_one=False) check_that_exists(families_db.families, {'project_id': destination_project_id}, not_more_than_one=False) print("==========") print("Make Updates:") result = update( projects_db.projects, {'project_id': destination_project_id}, { 'project_id': destination_project_id + '_previous1', 'version': '1' }) result = update(projects_db.projects, {'project_id': from_project_id}, { 'project_id': destination_project_id, 'version': '2' }) result = update( families_db.families, {'project_id': destination_project_id}, { 'project_id': destination_project_id + '_previous1', 'version': '1' }) result = update(families_db.families, {'project_id': from_project_id}, { 'project_id': destination_project_id, 'version': '2' }) print("==========") print("Checking Projects:") check_that_exists(projects_db.projects, {'project_id': destination_project_id}, not_more_than_one=True) print("==========") print("Checking Families:") check_that_exists(families_db.families, {'project_id': destination_project_id}, not_more_than_one=False) update_family_analysis_status(destination_project_id) print("Data transfer finished.") i = raw_input("Delete the 'from' project: %s? [Y/n] " % from_project_id) if i.strip() == 'Y': sample_management.delete_project(from_project_id) print("Project %s deleted" % from_project_id) else: print("Project not deleted")
def handle(self, *args, **options): if len(args) < 2: print("Usage: ./manage.py load_project_dir <project_id> <project_path>") print("") sys.exit(1) project_id = args[0] try: project = Project.objects.get(project_id=project_id) except Project.DoesNotExist: print("\nError:") print("\nNo project could be found with id '%s'" % project_id) print("") print("Please use the add_project command first to add this project before loading it.") print("") sys.exit(1) project_dir = os.path.abspath(args[1]) project_yaml_file = os.path.join(project_dir, 'project.yaml') project_spec = yaml.load(open(project_yaml_file)) # load in sample IDs that we'll use for the project sample_id_file = os.path.join(project_dir, project_spec['sample_id_list']) sample_ids = [l.strip('\n') for l in open(sample_id_file)] sample_ids = [slugify(s, separator='_') for s in sample_ids] sample_management.add_indiv_ids_to_project(project, sample_ids) # set meta info project.project_name = project_spec['project_name'] project.save() # nicknames if 'nicknames' in project_spec: # todo pass # load individuals if 'ped_files' in project_spec: for relative_path in project_spec['ped_files']: ped_file_path = os.path.join(project_dir, relative_path) sample_management.update_project_from_fam(project, open(ped_file_path)) # todo: add awesome-slugify to above # set VCF files if 'vcf_files' in project_spec: for relative_path in project_spec['vcf_files']: vcf_file_path = os.path.join(project_dir, relative_path) # todo: this should be a fn somewhere that add_vcf_to_project uses too vcf_file = VCFFile.objects.get_or_create(file_path=vcf_file_path)[0] sample_management.add_vcf_file_to_project(project, vcf_file) if 'breakpoint_files' in project_spec: for relative_path in project_spec['breakpoint_files']: breakpoint_file = BreakpointFile() breakpoint_file.project = project breakpoint_file.file_path = os.path.join(project_dir, relative_path) breakpoint_file.save() print("Adding breakpoint file: %s" % breakpoint_file.file_path)