def perform_hotspot(self): self.project_config = config_mongo.get_project_config() hotspot_file = self.project_config['hotspot_file'] hotspot_dir = self.project_config['hotspot_dir'] output_dir = hotspot_dir + "/hotspot_output" if os.path.isdir(output_dir): self.__log_hotspot_files_already_exist() else: bash.make_dir(output_dir) ref_fasta = self.project_config['ref_fasta'] bed_file = self.project_config['project_bed'] tvc_params = self.project_config['tvc_params'] bam_files = sampleinfo_mongo.get_bam_files() # HOTSPOT ALL OF THE BAM FILES self.__hotspot_bam_files(bam_files, hotspot_file, output_dir, ref_fasta, bed_file, tvc_params) # Delete the filter files all_files = glob(output_dir+"/*") for vcf in all_files: if "filtered.vcf" in vcf: bash.remove_file(vcf)
def __init__(self): self.project_config = config_mongo.get_project_config() self.logger = Logger.get_logger() self.output_files_dir = '%s/output_files' % self.project_config['output_dir'] if 'output_files_dir' not in self.project_config or not os.path.isdir(self.project_config['output_files_dir']): bash.make_dir(self.output_files_dir) config_mongo.change_config_field('output_files_dir', self.output_files_dir) else: self.output_files_dir = self.project_config['output_files_dir']
def reconcile_hotspot_and_database(self, hotspot_file): self.project_config = config_mongo.get_project_config() client, db = mongo.get_connection() vcf_reader = vcf.Reader(open(hotspot_file, 'r')) for rec in vcf_reader: chrom, pos, ref, alt = int(rec.CHROM.strip("chr")), int(rec.POS), rec.REF, [str(alt) for alt in rec.ALT] if not hotspot_mongo.is_hotspot(chrom, pos, ref, alt, db): self.__reconcile(chrom, pos, ref, alt, db) client.close()
def __init__(self): """ This init method is different in that it will create the annotation_dir config parameter if it doesn't already exist. This is not necessarily the most elegant way to do this, but it works. :return: """ self.project_config = config_mongo.get_project_config() self.logger = Logger.get_logger() # Creates the annotation_dir if needed and loads it into the config file self.annotations_dir = '%s/annotations' % self.project_config['output_dir'] if 'annotation_dir' not in self.project_config or not\ os.path.isdir(self.project_config['annotation_dir']): bash.make_dir(self.annotations_dir) config_mongo.change_config_field('annotation_dir', self.annotations_dir) else: self.annotations_dir = self.project_config['annotation_dir']
def main(self, args): """ This is the main function that runs Variant manager according to the arguments that were passed in by the user. :param args: These are the args as parsed by the parser at the bottom of this script. :return: None """ # This sets the project name for several different modules to use. self.args = args varman2.set_project_name(args['project_name']) # Checks the arguments given to make sure that they can be processed correctly. self.__argcheck(args) # Setting up the project config file self.__setup_project_analysis(self.args) self.project_config = config_mongo.get_project_config() # SETTING UP LOGGING Logger.create_logger(self.project_config['log_file'], 'a') self.logger = Logger.get_logger() # This executes the correct argument specified by the user argexecute = ArgExecutor(self.args) if self.args['which'] == 'add': argexecute.add() elif self.args['which'] == 'delete': argexecute.delete() elif self.args['which'] == 'load': argexecute.load_variants() elif self.args['which'] == 'hotspot': argexecute.hotspot() elif self.args['which'] == 'stats': argexecute.stats() elif self.args['which'] == 'output': argexecute.output() elif self.args['which'] == 'nothing': argexecute.nothing()
def save_annotations(self, annovar_vcf): self.__log_saving_annotations() self.project_config = config_mongo.get_project_config() client, db = mongo.get_connection() with open(annovar_vcf, "r") as annov_in: line = annov_in.readline() if not line.startswith("#CHROM"): while line.startswith('##'): line = annov_in.readline() header = line.strip().strip("#").split("\t") for line in annov_in: chrom, pos, ref, alt, annotations = self.__process_annovar_line(line, header) annotate_mongo.save_annotation(chrom, pos, ref, alt, annotations, db) client.close()
def save_annotations(self, annovar_vcf): """ This will save the annotations of a sample in the database. :param annovar_vcf: :return: """ self.__log_saving_annotations() self.project_config = config_mongo.get_project_config() client, db = mongo.get_connection() with open(annovar_vcf, "r") as annov_in: line = annov_in.readline() if not line.startswith("#CHROM"): while line.startswith('##'): # this reads through the junk lines line = annov_in.readline() header = line.strip().strip("#").split("\t") for line in annov_in: line = line.strip() if line != "": chrom, pos, ref, alt, annotations = self.__process_annovar_line(line, header) annotate_mongo.save_annotation(chrom, pos, ref, alt, annotations, db) else: header = line.strip().strip("#").split("\t") for line in annov_in: line = line.strip() if line != "": chrom, pos, ref, alt, annotations = self.__process_annovar_line(line, header) annotate_mongo.save_annotation(chrom, pos, ref, alt, annotations, db) client.close()
def __init__(self): self.project_config = config_mongo.get_project_config() self.logger = Logger.get_logger()
def __init__(self, var_type): self.project_config = config_mongo.get_project_config() self.logger = Logger.get_logger() self.variant_type = var_type self.affected_dict = sampleinfo_mongo.get_affected_dict()