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] print('delete_data: %s' % bool(options['delete_data'])) sample_management.delete_project(project_id, delete_data=bool(options.delete_data))
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): project_id = args[0] sample_management.delete_project(project_id)