def handle(self, *args, **options): project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('sample_list'): indiv_id_list = [] for line in open(options.get('sample_list')): if line.strip() == "" or line.startswith('#'): continue indiv_id_list.append(line.strip()) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('vcf'): vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('ped'): fam_file = open(options.get('ped')) sample_management.update_project_from_fam(project, fam_file)
def handle(self, *args, **options): if len(args)==0 or options['vcf'] is None and options['ped'] is None and options['xls'] is None: print '\n\nPlease enter a VCF file (--vcf), OR IDEALLY A PED or XLS file (using --ped or --xls), and a project ID (first positional argument).' print 'For example: python manage.py add_individuals_to_project myProjectId --ped myPed.ped\n' sys.exit() project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('sample_list'): if options.get('case_review'): raise ValueError("--case-review not supported for sample list") indiv_id_list = [] for line in open(options.get('sample_list')): if line.strip() == "" or line.startswith('#'): continue indiv_id_list.append(line.strip()) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('vcf'): if options.get('case_review'): raise ValueError("--case-review not supported for vcf") vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('ped'): in_case_review = options.get('case_review') fam_file = options.get('ped') fam_stuff.validate_fam_file(open(fam_file)) individual_details = sample_management.update_project_from_fam(project, open(fam_file), in_case_review=in_case_review) for j in individual_details: print("Adding %s: %s" % (j['indiv_id'], j)) if options.get('xls'): in_case_review = options.get('case_review') xls_file = options.get('xls') title_row, xl_rows = parse_xl_workbook(xls_file) temp_ped_filename = 'temp.ped' write_xl_rows_to_ped(temp_ped_filename, xl_rows) fam_stuff.validate_fam_file(open(temp_ped_filename)) individual_details = sample_management.update_project_from_fam(project, open(temp_ped_filename), in_case_review=in_case_review) #for j in individual_details: # print("Adding %s: %s" % (j['indiv_id'], j))
def handle(self, *args, **options): if len(args)==0 or options['vcf'] is None and options['ped'] is None and options['xls'] is None: print '\n\nPlease enter a VCF file (--vcf), OR IDEALLY A PED or XLS file (using --ped or --xls), and a project ID (first positional argument).' print 'For example: python manage.py add_individuals_to_project myProjectId --ped myPed.ped\n' sys.exit() project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('sample_list'): if options.get('case_review'): raise ValueError("--case-review not supported for sample list") indiv_id_list = [] for line in open(options.get('sample_list')): if line.strip() == "" or line.startswith('#'): continue indiv_id_list.append(line.strip()) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('vcf'): if options.get('case_review'): raise ValueError("--case-review not supported for vcf") vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('ped'): in_case_review = options.get('case_review') fam_file = options.get('ped') fam_stuff.validate_fam_file(open(fam_file)) individual_details = sample_management.update_project_from_fam(project, open(fam_file), in_case_review=in_case_review) for j in individual_details: print("Adding %s: %s" % (j['indiv_id'], j)) if options.get('xls'): in_case_review = options.get('case_review') xls_file = options.get('xls') title_row, xl_rows = parse_xl_workbook(xls_file) temp_ped_filename = 'temp.ped' write_xl_rows_to_ped(temp_ped_filename, xl_rows) fam_stuff.validate_fam_file(open(temp_ped_filename)) individual_details = sample_management.update_project_from_fam(project, open(temp_ped_filename), in_case_review=in_case_review)
def handle(self, *args, **options): if len(args)==0 or options['vcf'] is None and options['ped'] is None: print '\n\nPlease enter a VCF file (--vcf), OR IDEALLY A PED file (--ped), and a project ID (first positional argument).' print 'For example: python manage.py add_individuals_to_project myProjectId --ped myPed.ped\n' print 'If you also wish to create patients in phenotips, please use the --create_phenotips_patients\n' sys.exit() project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('sample_list'): indiv_id_list = [] for line in open(options.get('sample_list')): if line.strip() == "" or line.startswith('#'): continue indiv_id_list.append(line.strip()) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('vcf'): vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('ped'): fam_file = open(options.get('ped')) individual_details = sample_management.update_project_from_fam(project, fam_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(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 handle(self, *args, **options): if (options['vcf'] is None and options['ped'] is None) or len(args)==0: print '\n\nPlease enter a VCF file (--vcf) or a PED file (--ped), and a project ID (first positional argument)' print 'for example: python manage.py add_individuals_to_project myProjectId --ped myPed.ped\n' print 'If you also wish to create patients in phenotips, please use the --create_phenotips_patients,--phenotips_username, --phenotips_password to do so. ALL of them are REQUIRED.\n' sys.exit() if options['create_phenotips_patients'] is not None and (options['phenotips_username'] is None or options['phenotips_password'] is None): print '\n\nplease note if you use the --create_phenotips_patients option, both --phenotips_username and --phenotips_password options are REQUIRED.\n\n' sys.exit() project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('sample_list'): indiv_id_list = [] for line in open(options.get('sample_list')): if line.strip() == "" or line.startswith('#'): continue indiv_id_list.append(line.strip()) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('vcf'): vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) self.__add_individuals_to_phenotips(indiv_id_list) sample_management.add_indiv_ids_to_project(project, indiv_id_list) if options.get('ped'): fam_file = open(options.get('ped')) sample_management.update_project_from_fam(project, fam_file)
def handle(self, *args, **options): ''' Handles populating Phenotips. Currently favors PED file for richer set of information (vs VCF) to create patients ''' if len(args)==0 or options['vcf'] is None and options['ped'] is None: print '\n\nAdds a series of patients to Phenotips.\n' print 'Please enter a VCF file (--vcf), OR IDEALLY A PED file (--ped), and a project ID (first positional argument).' print 'For example: python manage.py add_individuals_to_phenotips myProjectId --ped myPed.ped\n' sys.exit() project_id = args[0] project = Project.objects.get(project_id=project_id) if options.get('vcf') and not os.path.exists(options.get('vcf')): print '\n\nError: the VCF file you entered does not exist or is invalid\n\n' sys.exit() if options.get('ped') and not os.path.exists(options.get('ped')): print '\n\nError: the PED file you entered does not exist or is invalid\n\n' sys.exit() indiv_id_list=None if options.get('vcf'): vcf_path = options.get('vcf') if vcf_path.endswith('.gz'): vcf = gzip.open(vcf_path) else: vcf = open(vcf_path) indiv_id_list = vcf_stuff.get_ids_from_vcf(vcf) individual_details=None if options.get('ped'): fam_file = open(options.get('ped')) individual_details = sample_management.update_project_from_fam(project, fam_file) if individual_details is not None: add_individuals_to_phenotips_from_ped(individual_details,project_id) else: if indiv_id_list is not None: add_individuals_to_phenotips_from_vcf(indiv_id_list,project_id) else: print '\n\nWARNING: No information was found in VCF to create patients with\n' sys.exit()
def handle(self, *args, **options): project = Project.objects.get(project_id=options.get('project_id')) fam_file = open(options.get('fam_file')) sample_management.update_project_from_fam(project, fam_file)
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)