diff --git a/conf/base.config b/conf/base.config index 0c50eb7..c439223 100644 --- a/conf/base.config +++ b/conf/base.config @@ -1,7 +1,7 @@ process { - conda = "/ssu/gassu/conda_envs/tdbsumstat" - container = "ghcr.io/bruno-ariano/tdbsumstat:1.0" - //conda = "/software/cardinal_analysis/ht/conda_envs/tdbsumstat" + //conda = "/ssu/gassu/conda_envs/tdbsumstat" + //container = "ghcr.io/bruno-ariano/tdbsumstat:1.0" + conda = "/software/cardinal_analysis/ht/conda_envs/tdbsumstat" // conda = "${projectDir}/pipeline_environment.yml" // memory errors which should be retried. otherwise error out diff --git a/modules/ingestion/main.nf b/modules/ingestion/main.nf index dd6fbbb..9381311 100644 --- a/modules/ingestion/main.nf +++ b/modules/ingestion/main.nf @@ -22,14 +22,14 @@ process INGEST_DATA { script: def qc = params.qc ? "--qc" : "" def pvar_file = params.pvar_file ? "--pvar-file ${params.pvar_file}" : "" - def pvar_file = params.permuted ? "--permuted" : "" + def permuted = params.permuted ? "--permuted" : "" """ tdbsumstat ingest \ --uri-path TileDB_${params.tiledb_name}\ --file-path ${list_files} \ --mapping-file ${mapping_file} \ --type-sumstat ${params.type_sumstat} \ - --mac ${params.mac} ${qc} ${pvar_file} ${params.permuted} + --mac ${params.mac} ${qc} ${pvar_file} ${permuted} # Rename the metadata parts directory to include the list_files name for uniqueness if [ -d "TileDB_${params.tiledb_name}_metadata_parts" ]; then mv "TileDB_${params.tiledb_name}_metadata_parts" "TileDB_${params.tiledb_name}_metadata_parts_${list_files.name}" diff --git a/tdbsumstat/cli/ingestion.py b/tdbsumstat/cli/ingestion.py index d6a75d3..14400e5 100755 --- a/tdbsumstat/cli/ingestion.py +++ b/tdbsumstat/cli/ingestion.py @@ -76,7 +76,7 @@ def ingest(uri_path:str, chunk_pl = pl.read_csv(file,separator=sep,low_memory=True ,null_values="NA") harmonized_object.harmonize(sumstat = chunk_pl, trait = trait, cell = cell, gene = gene, pheno_var = pheno_var, n = n, n_cases = n_cases, - n_controls = n_controls, mac = mac, permuted = permuted) + n_controls = n_controls, mac = mac) #Performing QC using GWASLAB if qc: harmonized_object.qc_sumstat(file_path = file) diff --git a/tdbsumstat/utils/harmonize_ingest.py b/tdbsumstat/utils/harmonize_ingest.py index 35468a9..ccb8943 100755 --- a/tdbsumstat/utils/harmonize_ingest.py +++ b/tdbsumstat/utils/harmonize_ingest.py @@ -22,7 +22,7 @@ class HarmonizationError(Exception): class Harmonize: - def __init__(self, mapping_file: str, uri: str, type_sumstat: str, pvar_file: str, type_trait: str, mac: int, permuted: False): + def __init__(self, mapping_file: str, uri: str, type_sumstat: str, pvar_file: str, type_trait: str, mac: int, permuted: bool): self.mapping_file = mapping_file self.uri = uri self.pvar_file = pvar_file @@ -33,6 +33,7 @@ def __init__(self, mapping_file: str, uri: str, type_sumstat: str, pvar_file: st self.dimension_tiledb = [] self.mac = mac self.permuted = permuted + print(self.permuted) def create_mapping(self): df = pd.read_csv(self.mapping_file, header=None, names=["key", "value"]) @@ -271,24 +272,25 @@ def harmonize(self, (10 ** (-pl.col("LOG10P"))).alias("P") ) - #Calculate p-value from z-score - self.chunk_pl = self.chunk_pl.drop('P') - if self.permuted==False: - self.chunk_pl = self.chunk_pl.with_columns( - (pl.col("BETA") / pl.col("SE")).pow(2).map_batches( - lambda x: pl.Series(stats.chi2.sf(x.to_numpy(), df=1)), - return_dtype=pl.Float64 - ).alias('P') - ) - else: + + if self.permuted: self.chunk_pl = self.chunk_pl.with_columns( ( pl.col("BETA").pow(2) / pl.col("P").map_batches( lambda x: pl.Series(stats.chi2.isf(x.to_numpy(), df=1)) ) - ).sqrt().alias("SE") -) + ).sqrt().alias("SE")) + + else: + #Calculate p-value from z-score + self.chunk_pl = self.chunk_pl.drop('P') + self.chunk_pl = self.chunk_pl.with_columns( + (pl.col("BETA") / pl.col("SE")).pow(2).map_batches( + lambda x: pl.Series(stats.chi2.sf(x.to_numpy(), df=1)), + return_dtype=pl.Float64 + ).alias('P') + ) def qc_sumstat(self, file_path:str): directory = self.uri + "_logs"