コード例 #1
0
    def buildBetas(self, weight_db_logic, name):
        output_path = os.path.join(self.output_folder, name)
        if os.path.exists(output_path):
            logging.info(
                "%s already exists, delete it if you want it to be done again",
                output_path)
            return

        logging.info("Building beta for %s and %s", name, self.weight_db_path)
        input_path = os.path.join(self.gwas_folder, name)
        file_format = GWASUtilities.GWASFileFormat.fileFormatFromArgs(
            input_path, self.args)

        scheme = MethodGuessing.chooseGWASProcessingScheme(
            file_format, weight_db_logic, self.args, input_path)

        callback = GWASUtilities.GWASWeightDBFilteredBetaLineCollector(
            file_format, scheme, weight_db_logic)
        dosage_loader = GWASUtilities.GWASDosageFileLoader(
            input_path, self.compressed, self.args.separator,
            self.args.skip_until_header, callback)
        result_sets = dosage_loader.load()

        # The following check is sort of redundant, as it exists in "saveSetsToCompressedFile".
        # It exists merely to provide different login
        if len(result_sets):
            KeyedDataSet.KeyedDataSetFileUtilities.saveSetsToCompressedFile(
                output_path, result_sets, "rsid")
        else:
            logging.info(
                "No snps from the tissue model found in the GWAS file")
コード例 #2
0
ファイル: M03_betas.py プロジェクト: NHLBI-BCB/MetaXcan
    def buildBetas(self, weight_db_logic, name):
        output_path = os.path.join(self.output_folder, name)
        if not ".gz" in output_path:
            output_path += ".gz"
        if os.path.exists(output_path):
            logging.info(
                "%s already exists, delete it if you want it to be done again",
                output_path)
            return

        logging.info("Building beta for %s and %s", name, self.weight_db_path)
        input_path = os.path.join(self.gwas_folder, name)
        file_format = GWASUtilities.GWASFileFormat.fileFormatFromArgs(
            input_path, self.args)

        scheme = MethodGuessing.chooseGWASProcessingScheme(
            self.args, input_path)
        callback = MethodGuessing.chooseGWASCallback(file_format, scheme,
                                                     weight_db_logic)
        if not weight_db_logic:
            GWASUtilities.loadGWASAndStream(input_path, output_path,
                                            self.compressed_gwas,
                                            self.args.separator,
                                            self.args.skip_until_header,
                                            callback)
        else:
            dosage_loader = GWASUtilities.GWASDosageFileLoader(
                input_path, self.compressed_gwas, self.args.separator,
                self.args.skip_until_header, callback)
            results, column_order = dosage_loader.load()

            # The following check is sort of redundant, as it exists in "saveSetsToCompressedFile".
            # It exists merely to provide different logging
            if len(results):

                def do_output(file, results, column_order):
                    file.write("\t".join(column_order) + "\n")
                    first = results[column_order[0]]
                    n = len(first)
                    for i in xrange(0, n):
                        line_comps = [str(results[c][i]) for c in column_order]
                        line = "%s\n" % "\t".join(line_comps)
                        file.write(line)

                with gzip.open(output_path, "wb") as file:
                    do_output(file, results, column_order)
            else:
                logging.info(
                    "No snps from the tissue model found in the GWAS file")
        logging.info("Successfully ran GWAS input processing")
コード例 #3
0
ファイル: M03_betas.py プロジェクト: xtmgah/MetaXcan
    def buildBetas(self, weight_db_logic, name):
        output_path = os.path.join(self.output_folder, name)
        if os.path.exists(output_path):
            logging.info("%s already exists, delete it if you want it to be done again", output_path)
            return

        logging.info("Building beta for %s and %s", name, self.weight_db_path)
        input_path = os.path.join(self.gwas_folder, name)
        file_format = GWASUtilities.GWASFileFormat.fileFormatFromArgs(input_path, self.args)

        scheme = MethodGuessing.chooseGWASProcessingScheme(file_format, weight_db_logic, self.args, input_path)

        callback = GWASUtilities.GWASWeightDBFilteredBetaLineCollector(file_format, scheme, weight_db_logic)
        dosage_loader = GWASUtilities.GWASDosageFileLoader(input_path, self.compressed, self.args.separator, callback)
        result_sets = dosage_loader.load()

        # The following check is sort of redundant, as it exists in "saveSetsToCompressedFile".
        # It exists merely to provide different login
        if len(result_sets):
            KeyedDataSet.KeyedDataSetFileUtilities.saveSetsToCompressedFile(output_path, result_sets, "rsid")
        else:
            logging.info("No snps from the tissue model found in the GWAS file")
コード例 #4
0
ファイル: M03_betas.py プロジェクト: hakyimlab/MetaXcan
    def buildBetas(self, weight_db_logic, name):
        output_path = os.path.join(self.output_folder, name)
        if not ".gz" in output_path:
            output_path += ".gz"
        if os.path.exists(output_path):
            logging.info("%s already exists, delete it if you want it to be done again", output_path)
            return

        logging.info("Building beta for %s and %s", name, self.weight_db_path if self.weight_db_path else "no database")
        input_path = os.path.join(self.gwas_folder, name)
        file_format = GWASUtilities.GWASFileFormat.fileFormatFromArgs(input_path, self.args)

        scheme = MethodGuessing.chooseGWASProcessingScheme(self.args, input_path)
        callback = MethodGuessing.chooseGWASCallback(file_format, scheme, weight_db_logic)
        if not weight_db_logic:
            GWASUtilities.loadGWASAndStream(input_path, output_path, self.compressed_gwas, self.args.separator, self.args.skip_until_header, callback)
        else:
            dosage_loader = GWASUtilities.GWASDosageFileLoader(input_path, self.compressed_gwas, self.args.separator, self.args.skip_until_header, callback)
            results, column_order = dosage_loader.load()

            # The following check is sort of redundant, as it exists in "saveSetsToCompressedFile".
            # It exists merely to provide different logging
            if len(results):
                def do_output(file, results, column_order):
                    file.write("\t".join(column_order)+"\n")
                    first = results[column_order[0]]
                    n = len(first)
                    for i in xrange(0,n):
                        line_comps = [str(results[c][i]) for c in column_order]
                        line = "%s\n" % "\t".join(line_comps)
                        file.write(line)

                with gzip.open(output_path, "wb") as file:
                    do_output(file, results, column_order)
            else:
                logging.info("No snps from the tissue model found in the GWAS file")
        logging.info("Successfully ran GWAS input processing")