biopipen 0.21.0__py3-none-any.whl → 0.34.26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biopipen/__init__.py +1 -1
- biopipen/core/config.toml +28 -0
- biopipen/core/filters.py +79 -4
- biopipen/core/proc.py +12 -3
- biopipen/core/testing.py +75 -3
- biopipen/ns/bam.py +148 -6
- biopipen/ns/bed.py +75 -0
- biopipen/ns/cellranger.py +186 -0
- biopipen/ns/cellranger_pipeline.py +126 -0
- biopipen/ns/cnv.py +19 -3
- biopipen/ns/cnvkit.py +1 -1
- biopipen/ns/cnvkit_pipeline.py +20 -12
- biopipen/ns/delim.py +34 -35
- biopipen/ns/gene.py +68 -23
- biopipen/ns/gsea.py +63 -37
- biopipen/ns/misc.py +39 -14
- biopipen/ns/plot.py +304 -1
- biopipen/ns/protein.py +183 -0
- biopipen/ns/regulatory.py +290 -0
- biopipen/ns/rnaseq.py +142 -5
- biopipen/ns/scrna.py +2053 -473
- biopipen/ns/scrna_metabolic_landscape.py +228 -382
- biopipen/ns/snp.py +659 -0
- biopipen/ns/stats.py +484 -0
- biopipen/ns/tcr.py +683 -98
- biopipen/ns/vcf.py +236 -2
- biopipen/ns/web.py +97 -6
- biopipen/reports/bam/CNVpytor.svelte +4 -9
- biopipen/reports/cellranger/CellRangerCount.svelte +18 -0
- biopipen/reports/cellranger/CellRangerSummary.svelte +16 -0
- biopipen/reports/cellranger/CellRangerVdj.svelte +18 -0
- biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
- biopipen/reports/common.svelte +15 -0
- biopipen/reports/protein/ProdigySummary.svelte +16 -0
- biopipen/reports/scrna/CellsDistribution.svelte +4 -39
- biopipen/reports/scrna/DimPlots.svelte +1 -1
- biopipen/reports/scrna/MarkersFinder.svelte +6 -126
- biopipen/reports/scrna/MetaMarkers.svelte +3 -75
- biopipen/reports/scrna/RadarPlots.svelte +4 -20
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +61 -22
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +88 -82
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +70 -10
- biopipen/reports/snp/PlinkCallRate.svelte +24 -0
- biopipen/reports/snp/PlinkFreq.svelte +18 -0
- biopipen/reports/snp/PlinkHWE.svelte +18 -0
- biopipen/reports/snp/PlinkHet.svelte +18 -0
- biopipen/reports/snp/PlinkIBD.svelte +18 -0
- biopipen/reports/tcr/CDR3AAPhyschem.svelte +19 -66
- biopipen/reports/tcr/ClonalStats.svelte +16 -0
- biopipen/reports/tcr/CloneResidency.svelte +3 -93
- biopipen/reports/tcr/Immunarch.svelte +4 -155
- biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
- biopipen/reports/tcr/TESSA.svelte +11 -28
- biopipen/reports/utils/misc.liq +22 -7
- biopipen/scripts/bam/BamMerge.py +11 -15
- biopipen/scripts/bam/BamSampling.py +90 -0
- biopipen/scripts/bam/BamSort.py +141 -0
- biopipen/scripts/bam/BamSplitChroms.py +10 -10
- biopipen/scripts/bam/BamSubsetByBed.py +38 -0
- biopipen/scripts/bam/CNAClinic.R +41 -5
- biopipen/scripts/bam/CNVpytor.py +153 -54
- biopipen/scripts/bam/ControlFREEC.py +13 -14
- biopipen/scripts/bam/SamtoolsView.py +33 -0
- biopipen/scripts/bed/Bed2Vcf.py +5 -5
- biopipen/scripts/bed/BedConsensus.py +5 -5
- biopipen/scripts/bed/BedLiftOver.sh +6 -4
- biopipen/scripts/bed/BedtoolsIntersect.py +54 -0
- biopipen/scripts/bed/BedtoolsMakeWindows.py +47 -0
- biopipen/scripts/bed/BedtoolsMerge.py +4 -4
- biopipen/scripts/cellranger/CellRangerCount.py +138 -0
- biopipen/scripts/cellranger/CellRangerSummary.R +181 -0
- biopipen/scripts/cellranger/CellRangerVdj.py +112 -0
- biopipen/scripts/cnv/AneuploidyScore.R +55 -20
- biopipen/scripts/cnv/AneuploidyScoreSummary.R +221 -163
- biopipen/scripts/cnv/TMADScore.R +25 -9
- biopipen/scripts/cnv/TMADScoreSummary.R +57 -86
- biopipen/scripts/cnvkit/CNVkitAccess.py +7 -6
- biopipen/scripts/cnvkit/CNVkitAutobin.py +26 -18
- biopipen/scripts/cnvkit/CNVkitBatch.py +6 -6
- biopipen/scripts/cnvkit/CNVkitCall.py +3 -3
- biopipen/scripts/cnvkit/CNVkitCoverage.py +4 -3
- biopipen/scripts/cnvkit/CNVkitDiagram.py +5 -5
- biopipen/scripts/cnvkit/CNVkitFix.py +3 -3
- biopipen/scripts/cnvkit/CNVkitGuessBaits.py +12 -8
- biopipen/scripts/cnvkit/CNVkitHeatmap.py +5 -5
- biopipen/scripts/cnvkit/CNVkitReference.py +6 -5
- biopipen/scripts/cnvkit/CNVkitScatter.py +5 -5
- biopipen/scripts/cnvkit/CNVkitSegment.py +5 -5
- biopipen/scripts/cnvkit/guess_baits.py +166 -93
- biopipen/scripts/delim/RowsBinder.R +1 -1
- biopipen/scripts/delim/SampleInfo.R +116 -118
- biopipen/scripts/gene/GeneNameConversion.R +67 -0
- biopipen/scripts/gene/GenePromoters.R +61 -0
- biopipen/scripts/gsea/Enrichr.R +5 -5
- biopipen/scripts/gsea/FGSEA.R +184 -50
- biopipen/scripts/gsea/GSEA.R +2 -2
- biopipen/scripts/gsea/PreRank.R +5 -5
- biopipen/scripts/misc/Config2File.py +2 -2
- biopipen/scripts/misc/Plot.R +80 -0
- biopipen/scripts/misc/Shell.sh +15 -0
- biopipen/scripts/misc/Str2File.py +2 -2
- biopipen/scripts/plot/Heatmap.R +3 -3
- biopipen/scripts/plot/Manhattan.R +147 -0
- biopipen/scripts/plot/QQPlot.R +146 -0
- biopipen/scripts/plot/ROC.R +88 -0
- biopipen/scripts/plot/Scatter.R +112 -0
- biopipen/scripts/plot/VennDiagram.R +5 -9
- biopipen/scripts/protein/MMCIF2PDB.py +33 -0
- biopipen/scripts/protein/PDB2Fasta.py +60 -0
- biopipen/scripts/protein/Prodigy.py +119 -0
- biopipen/scripts/protein/ProdigySummary.R +140 -0
- biopipen/scripts/protein/RMSD.py +178 -0
- biopipen/scripts/regulatory/MotifAffinityTest.R +102 -0
- biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +127 -0
- biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +104 -0
- biopipen/scripts/regulatory/MotifScan.py +159 -0
- biopipen/scripts/regulatory/VariantMotifPlot.R +78 -0
- biopipen/scripts/regulatory/motifs-common.R +324 -0
- biopipen/scripts/rnaseq/Simulation-ESCO.R +180 -0
- biopipen/scripts/rnaseq/Simulation-RUVcorr.R +45 -0
- biopipen/scripts/rnaseq/Simulation.R +21 -0
- biopipen/scripts/rnaseq/UnitConversion.R +325 -54
- biopipen/scripts/scrna/AnnData2Seurat.R +40 -0
- biopipen/scripts/scrna/CCPlotR-patch.R +161 -0
- biopipen/scripts/scrna/CellCellCommunication.py +150 -0
- biopipen/scripts/scrna/CellCellCommunicationPlots.R +93 -0
- biopipen/scripts/scrna/CellSNPLite.py +30 -0
- biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +185 -0
- biopipen/scripts/scrna/CellTypeAnnotation-direct.R +68 -31
- biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +27 -22
- biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +28 -20
- biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +48 -25
- biopipen/scripts/scrna/CellTypeAnnotation.R +37 -1
- biopipen/scripts/scrna/CellsDistribution.R +456 -167
- biopipen/scripts/scrna/DimPlots.R +1 -1
- biopipen/scripts/scrna/ExprImputation-alra.R +109 -0
- biopipen/scripts/scrna/ExprImputation-rmagic.R +256 -0
- biopipen/scripts/scrna/{ExprImpution-scimpute.R → ExprImputation-scimpute.R} +8 -5
- biopipen/scripts/scrna/ExprImputation.R +7 -0
- biopipen/scripts/scrna/LoomTo10X.R +51 -0
- biopipen/scripts/scrna/MQuad.py +25 -0
- biopipen/scripts/scrna/MarkersFinder.R +679 -400
- biopipen/scripts/scrna/MetaMarkers.R +265 -161
- biopipen/scripts/scrna/ModuleScoreCalculator.R +66 -11
- biopipen/scripts/scrna/PseudoBulkDEG.R +678 -0
- biopipen/scripts/scrna/RadarPlots.R +355 -134
- biopipen/scripts/scrna/ScFGSEA.R +298 -100
- biopipen/scripts/scrna/ScSimulation.R +65 -0
- biopipen/scripts/scrna/ScVelo.py +617 -0
- biopipen/scripts/scrna/Seurat2AnnData.R +7 -0
- biopipen/scripts/scrna/SeuratClusterStats-clustree.R +87 -0
- biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +36 -30
- biopipen/scripts/scrna/SeuratClusterStats-features.R +138 -187
- biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +81 -0
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +78 -89
- biopipen/scripts/scrna/SeuratClusterStats.R +47 -10
- biopipen/scripts/scrna/SeuratClustering.R +36 -233
- biopipen/scripts/scrna/SeuratLoading.R +2 -2
- biopipen/scripts/scrna/SeuratMap2Ref.R +84 -113
- biopipen/scripts/scrna/SeuratMetadataMutater.R +16 -6
- biopipen/scripts/scrna/SeuratPreparing.R +223 -173
- biopipen/scripts/scrna/SeuratSubClustering.R +64 -0
- biopipen/scripts/scrna/SeuratTo10X.R +27 -0
- biopipen/scripts/scrna/Slingshot.R +65 -0
- biopipen/scripts/scrna/Subset10X.R +2 -2
- biopipen/scripts/scrna/TopExpressingGenes.R +169 -135
- biopipen/scripts/scrna/celltypist-wrapper.py +195 -0
- biopipen/scripts/scrna/scvelo_paga.py +313 -0
- biopipen/scripts/scrna/seurat_anndata_conversion.py +98 -0
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +447 -82
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +348 -241
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +188 -166
- biopipen/scripts/snp/MatrixEQTL.R +217 -0
- biopipen/scripts/snp/Plink2GTMat.py +148 -0
- biopipen/scripts/snp/PlinkCallRate.R +199 -0
- biopipen/scripts/snp/PlinkFilter.py +100 -0
- biopipen/scripts/snp/PlinkFreq.R +291 -0
- biopipen/scripts/snp/PlinkFromVcf.py +81 -0
- biopipen/scripts/snp/PlinkHWE.R +85 -0
- biopipen/scripts/snp/PlinkHet.R +96 -0
- biopipen/scripts/snp/PlinkIBD.R +196 -0
- biopipen/scripts/snp/PlinkSimulation.py +124 -0
- biopipen/scripts/snp/PlinkUpdateName.py +124 -0
- biopipen/scripts/stats/ChowTest.R +146 -0
- biopipen/scripts/stats/DiffCoexpr.R +152 -0
- biopipen/scripts/stats/LiquidAssoc.R +135 -0
- biopipen/scripts/stats/Mediation.R +108 -0
- biopipen/scripts/stats/MetaPvalue.R +130 -0
- biopipen/scripts/stats/MetaPvalue1.R +74 -0
- biopipen/scripts/tcgamaf/Maf2Vcf.py +2 -2
- biopipen/scripts/tcgamaf/MafAddChr.py +2 -2
- biopipen/scripts/tcr/Attach2Seurat.R +3 -2
- biopipen/scripts/tcr/CDR3AAPhyschem.R +211 -143
- biopipen/scripts/tcr/CDR3Clustering.R +343 -0
- biopipen/scripts/tcr/ClonalStats.R +526 -0
- biopipen/scripts/tcr/CloneResidency.R +255 -131
- biopipen/scripts/tcr/CloneSizeQQPlot.R +4 -4
- biopipen/scripts/tcr/GIANA/GIANA.py +1356 -797
- biopipen/scripts/tcr/GIANA/GIANA4.py +1362 -789
- biopipen/scripts/tcr/GIANA/query.py +164 -162
- biopipen/scripts/tcr/Immunarch-basic.R +31 -9
- biopipen/scripts/tcr/Immunarch-clonality.R +25 -5
- biopipen/scripts/tcr/Immunarch-diversity.R +352 -134
- biopipen/scripts/tcr/Immunarch-geneusage.R +45 -5
- biopipen/scripts/tcr/Immunarch-kmer.R +68 -8
- biopipen/scripts/tcr/Immunarch-overlap.R +84 -4
- biopipen/scripts/tcr/Immunarch-spectratyping.R +35 -6
- biopipen/scripts/tcr/Immunarch-tracking.R +38 -6
- biopipen/scripts/tcr/Immunarch-vjjunc.R +165 -0
- biopipen/scripts/tcr/Immunarch.R +63 -11
- biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
- biopipen/scripts/tcr/ImmunarchFilter.R +4 -4
- biopipen/scripts/tcr/ImmunarchLoading.R +38 -29
- biopipen/scripts/tcr/SampleDiversity.R +1 -1
- biopipen/scripts/tcr/ScRepCombiningExpression.R +40 -0
- biopipen/scripts/tcr/ScRepLoading.R +166 -0
- biopipen/scripts/tcr/TCRClusterStats.R +176 -22
- biopipen/scripts/tcr/TCRDock.py +110 -0
- biopipen/scripts/tcr/TESSA.R +102 -118
- biopipen/scripts/tcr/VJUsage.R +5 -5
- biopipen/scripts/tcr/immunarch-patched.R +142 -0
- biopipen/scripts/tcr/vdjtools-patch.sh +1 -1
- biopipen/scripts/vcf/BcftoolsAnnotate.py +91 -0
- biopipen/scripts/vcf/BcftoolsFilter.py +90 -0
- biopipen/scripts/vcf/BcftoolsMerge.py +31 -0
- biopipen/scripts/vcf/BcftoolsSort.py +113 -0
- biopipen/scripts/vcf/BcftoolsView.py +73 -0
- biopipen/scripts/vcf/TruvariBench.sh +14 -7
- biopipen/scripts/vcf/TruvariBenchSummary.R +16 -13
- biopipen/scripts/vcf/TruvariConsistency.R +1 -1
- biopipen/scripts/vcf/Vcf2Bed.py +2 -2
- biopipen/scripts/vcf/VcfAnno.py +11 -11
- biopipen/scripts/vcf/VcfDownSample.sh +22 -10
- biopipen/scripts/vcf/VcfFilter.py +5 -5
- biopipen/scripts/vcf/VcfFix.py +7 -7
- biopipen/scripts/vcf/VcfFix_utils.py +13 -4
- biopipen/scripts/vcf/VcfIndex.py +3 -3
- biopipen/scripts/vcf/VcfIntersect.py +3 -3
- biopipen/scripts/vcf/VcfLiftOver.sh +5 -0
- biopipen/scripts/vcf/VcfSplitSamples.py +4 -4
- biopipen/scripts/vcf/bcftools_utils.py +52 -0
- biopipen/scripts/web/Download.py +8 -4
- biopipen/scripts/web/DownloadList.py +5 -5
- biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
- biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
- biopipen/scripts/web/gcloud_common.py +49 -0
- biopipen/utils/gene.py +108 -60
- biopipen/utils/misc.py +146 -20
- biopipen/utils/reference.py +64 -20
- biopipen/utils/reporter.py +177 -0
- biopipen/utils/vcf.py +1 -1
- biopipen-0.34.26.dist-info/METADATA +27 -0
- biopipen-0.34.26.dist-info/RECORD +292 -0
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/WHEEL +1 -1
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/entry_points.txt +6 -2
- biopipen/ns/bcftools.py +0 -111
- biopipen/ns/scrna_basic.py +0 -255
- biopipen/reports/delim/SampleInfo.svelte +0 -36
- biopipen/reports/scrna/GeneExpressionInvistigation.svelte +0 -32
- biopipen/reports/scrna/ScFGSEA.svelte +0 -35
- biopipen/reports/scrna/SeuratClusterStats.svelte +0 -82
- biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -20
- biopipen/reports/scrna/SeuratPreparing.svelte +0 -38
- biopipen/reports/scrna/TopExpressingGenes.svelte +0 -55
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -31
- biopipen/reports/utils/gsea.liq +0 -110
- biopipen/scripts/bcftools/BcftoolsAnnotate.py +0 -42
- biopipen/scripts/bcftools/BcftoolsFilter.py +0 -79
- biopipen/scripts/bcftools/BcftoolsSort.py +0 -19
- biopipen/scripts/gene/GeneNameConversion.py +0 -66
- biopipen/scripts/scrna/ExprImpution-alra.R +0 -32
- biopipen/scripts/scrna/ExprImpution-rmagic.R +0 -29
- biopipen/scripts/scrna/ExprImpution.R +0 -7
- biopipen/scripts/scrna/GeneExpressionInvistigation.R +0 -132
- biopipen/scripts/scrna/Write10X.R +0 -11
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -150
- biopipen/scripts/tcr/TCRClustering.R +0 -280
- biopipen/utils/common_docstrs.py +0 -61
- biopipen/utils/gene.R +0 -49
- biopipen/utils/gsea.R +0 -193
- biopipen/utils/io.R +0 -20
- biopipen/utils/misc.R +0 -114
- biopipen/utils/mutate_helpers.R +0 -433
- biopipen/utils/plot.R +0 -173
- biopipen/utils/rnaseq.R +0 -48
- biopipen/utils/single_cell.R +0 -115
- biopipen-0.21.0.dist-info/METADATA +0 -22
- biopipen-0.21.0.dist-info/RECORD +0 -218
|
@@ -1,67 +1,93 @@
|
|
|
1
|
-
source("{{biopipen_dir}}/utils/gsea.R")
|
|
2
|
-
source("{{biopipen_dir}}/utils/plot.R")
|
|
3
|
-
|
|
4
1
|
library(gtools)
|
|
5
|
-
library(
|
|
6
|
-
library(ggprism)
|
|
2
|
+
library(rlang)
|
|
7
3
|
library(Matrix)
|
|
8
4
|
library(sparseMatrixStats)
|
|
9
5
|
library(Seurat)
|
|
6
|
+
library(tidyseurat)
|
|
7
|
+
library(biopipen.utils)
|
|
10
8
|
|
|
11
9
|
sobjfile <- {{ in.sobjfile | r }}
|
|
12
10
|
outdir <- {{ out.outdir | r }}
|
|
11
|
+
joboutdir <- {{ job.outdir | r }}
|
|
13
12
|
gmtfile <- {{ envs.gmtfile | r }}
|
|
14
13
|
select_pcs <- {{ envs.select_pcs | r }}
|
|
15
14
|
ncores <- {{ envs.ncores | r }}
|
|
16
15
|
pathway_pval_cutoff <- {{ envs.pathway_pval_cutoff | r }}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!is.null(grouping_prefix) && nchar(grouping_prefix) > 0) {
|
|
24
|
-
grouping_prefix = paste0(grouping_prefix, "_")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!is.null(subsetting_prefix) && nchar(subsetting_prefix) > 0) {
|
|
28
|
-
subsetting_prefix = paste0(subsetting_prefix, "_")
|
|
29
|
-
}
|
|
16
|
+
subset_by <- {{ envs.subset_by | r }}
|
|
17
|
+
group_by <- {{ envs.group_by | r }}
|
|
18
|
+
fgsea_args <- {{ envs.fgsea_args | r }}
|
|
19
|
+
plots <- {{ envs.plots | r }}
|
|
20
|
+
cases <- {{ envs.cases | r }}
|
|
30
21
|
|
|
31
22
|
set.seed(8525)
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
pathways
|
|
39
|
-
}
|
|
24
|
+
log <- get_logger()
|
|
25
|
+
reporter <- get_reporter()
|
|
26
|
+
|
|
27
|
+
log$info("Loading Seurat object ...")
|
|
28
|
+
sobj <- read_obj(sobjfile)
|
|
40
29
|
|
|
41
|
-
|
|
30
|
+
defaults <- list(
|
|
31
|
+
subset_by = subset_by,
|
|
32
|
+
group_by = group_by,
|
|
33
|
+
fgsea_args = fgsea_args,
|
|
34
|
+
plots = plots,
|
|
35
|
+
select_pcs = select_pcs,
|
|
36
|
+
pathway_pval_cutoff = pathway_pval_cutoff
|
|
37
|
+
)
|
|
38
|
+
log$info("Expanding cases ...")
|
|
39
|
+
default_case <- subset_by %||% "DEFAULT"
|
|
40
|
+
cases <- expand_cases(
|
|
41
|
+
cases,
|
|
42
|
+
defaults,
|
|
43
|
+
function(name, case) {
|
|
44
|
+
if (is.null(case$group_by)) {
|
|
45
|
+
stop("'group_by' is required in case: ", name)
|
|
46
|
+
}
|
|
47
|
+
stats::setNames(list(case), name)
|
|
48
|
+
},
|
|
49
|
+
default_case = default_case)
|
|
50
|
+
|
|
51
|
+
log$info("Loading metabolic pathways ...")
|
|
52
|
+
pathways <- ParseGMT(gmtfile)
|
|
53
|
+
pathway_names <- names(pathways)
|
|
42
54
|
metabolics <- unique(as.vector(unname(unlist(pathways))))
|
|
43
|
-
sobj <- readRDS(sobjfile)
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (is.null(
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
|
|
57
|
+
do_subset <- function(object, caseinfo, subset_by, subset_val, group_by, plots, select_pcs, pathway_pval_cutoff) {
|
|
58
|
+
if (!is.null(subset_by)) {
|
|
59
|
+
log$info("- Handling subset: {subset_by} = {subset_val} ...")
|
|
60
|
+
object <- tryCatch(
|
|
61
|
+
filter(object, !!sym(subset_by) == subset_val & !is.na(!!sym(group_by))),
|
|
62
|
+
error = function(e) NULL
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
if (!is.null(subset_by)) {
|
|
66
|
+
h1 <- paste0(subset_by, ": ", subset_val)
|
|
67
|
+
h2 <- group_by
|
|
68
|
+
odir <- file.path(caseinfo$prefix, slugify(paste0(subset_by, "_", subset_val)))
|
|
69
|
+
} else if (length(cases) > 1) {
|
|
70
|
+
h1 <- "No Subsetting"
|
|
71
|
+
h2 <- group_by
|
|
72
|
+
odir <- file.path(caseinfo$prefix, "No_Subsetting")
|
|
50
73
|
} else {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
74
|
+
h1 <- group_by
|
|
75
|
+
h2 <- "#"
|
|
76
|
+
odir <- caseinfo$prefix
|
|
77
|
+
}
|
|
78
|
+
if (is.null(object) || ncol(object) < 5) {
|
|
79
|
+
msg <- paste0(" ! skipped. Subset has less than 5 cells: ", subset_by, " = ", subset_val)
|
|
80
|
+
log$warn(msg)
|
|
81
|
+
reporter$add(list(kind = "error", content = msg), h1 = h1, h2 = h2)
|
|
82
|
+
return(NULL)
|
|
54
83
|
}
|
|
55
|
-
dir.create(subset_dir, showWarnings = FALSE)
|
|
56
84
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
all_groups = as.character(metabolic_obj@meta.data[[grouping]])
|
|
62
|
-
groups <- unique(all_groups)
|
|
85
|
+
dir.create(odir, showWarnings = FALSE)
|
|
86
|
+
|
|
87
|
+
features <- intersect(rownames(object), metabolics)
|
|
88
|
+
groups <- unique(as.character(object@meta.data[[group_by]]))
|
|
63
89
|
|
|
64
|
-
enrich_data_df <-
|
|
90
|
+
enrich_data_df <- NULL
|
|
65
91
|
pc_plotdata <- data.frame(
|
|
66
92
|
x = numeric(),
|
|
67
93
|
y = numeric(),
|
|
@@ -70,11 +96,18 @@ do_one_subset <- function(s, subset_col, subset_prefix) {
|
|
|
70
96
|
)
|
|
71
97
|
|
|
72
98
|
for (group in groups) {
|
|
73
|
-
|
|
74
|
-
each_metabolic_obj <-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
log$info(" {group_by}: {group} ...")
|
|
100
|
+
each_metabolic_obj <- subset(object, subset = !!sym(group_by) == group)
|
|
101
|
+
if (ncol(each_metabolic_obj) < 5) {
|
|
102
|
+
log$warn(" ! skipped. Group has less than 5 cells: {group}")
|
|
103
|
+
next()
|
|
104
|
+
}
|
|
105
|
+
each_metabolic_exprs <- GetAssayData(each_metabolic_obj)[features, , drop = FALSE]
|
|
106
|
+
each_metabolic_exprs <- each_metabolic_exprs[rowSums(each_metabolic_exprs) > 0, , drop=FALSE]
|
|
107
|
+
if (ncol(each_metabolic_obj) < 5) {
|
|
108
|
+
log$warn(" ! skipped. Group has less than 5 active cells: {group}")
|
|
109
|
+
next()
|
|
110
|
+
}
|
|
78
111
|
x <- each_metabolic_exprs
|
|
79
112
|
ntop <- nrow(x)
|
|
80
113
|
rv <- rowVars(x)
|
|
@@ -96,147 +129,136 @@ do_one_subset <- function(s, subset_col, subset_prefix) {
|
|
|
96
129
|
pc_plotdata <- rbind(pc_plotdata, tmp_plotdata)
|
|
97
130
|
|
|
98
131
|
####
|
|
99
|
-
pre_rank_matrix <- as.matrix(rowSums(abs(pca$rotation[, 1:selected_pcs, drop=FALSE])))
|
|
100
|
-
pre_rank_matrix <- as.list(as.data.frame(t(pre_rank_matrix)))
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
# get the result
|
|
116
|
-
enrich_data_df <- rbind(
|
|
117
|
-
enrich_data_df,
|
|
118
|
-
data.frame(x = group, y = gsea_result$pathway, NES = gsea_result$NES, PVAL = gsea_result$pval)
|
|
119
|
-
)
|
|
132
|
+
pre_rank_matrix <- as.matrix(rowSums(abs(pca$rotation[, 1:selected_pcs, drop = FALSE])))
|
|
133
|
+
pre_rank_matrix <- unlist(as.list(as.data.frame(t(pre_rank_matrix))))
|
|
134
|
+
|
|
135
|
+
fgsea_args <- fgsea_args %||% list()
|
|
136
|
+
fgsea_args$ranks <- pre_rank_matrix
|
|
137
|
+
fgsea_args$genesets <- pathways
|
|
138
|
+
fgsea_args$nproc <- fgsea_args$nproc %||% ncores
|
|
139
|
+
|
|
140
|
+
tmp <- do_call(RunGSEA, fgsea_args)
|
|
141
|
+
tmp[[group_by]] <- group
|
|
142
|
+
|
|
143
|
+
if (is.null(enrich_data_df)) {
|
|
144
|
+
enrich_data_df <- tmp
|
|
145
|
+
} else {
|
|
146
|
+
enrich_data_df <- rbind(enrich_data_df, tmp)
|
|
147
|
+
}
|
|
120
148
|
}
|
|
121
149
|
|
|
122
150
|
# remove pvalue < 0.01 pathways
|
|
123
|
-
min_pval <- by(enrich_data_df$
|
|
151
|
+
min_pval <- by(enrich_data_df$pval, enrich_data_df$pathway, FUN = min)
|
|
124
152
|
select_pathways <- names(min_pval)[(min_pval <= pathway_pval_cutoff)]
|
|
125
|
-
select_enrich_data_df <- enrich_data_df[enrich_data_df$
|
|
153
|
+
select_enrich_data_df <- enrich_data_df[enrich_data_df$pathway %in% select_pathways, ]
|
|
126
154
|
# converto pvalue to -log10
|
|
127
|
-
pvals <- select_enrich_data_df$
|
|
155
|
+
pvals <- select_enrich_data_df$pval
|
|
128
156
|
pvals[pvals <= 0] <- 1e-10
|
|
129
|
-
select_enrich_data_df$
|
|
157
|
+
select_enrich_data_df$pval <- -log10(pvals)
|
|
130
158
|
|
|
131
159
|
# sort
|
|
132
|
-
pathway_pv_sum <- by(select_enrich_data_df$
|
|
160
|
+
pathway_pv_sum <- by(select_enrich_data_df$pval, select_enrich_data_df$pathway, FUN = sum)
|
|
133
161
|
pathway_order <- names(pathway_pv_sum)[order(pathway_pv_sum, decreasing = T)]
|
|
134
162
|
########################### top 10
|
|
135
163
|
pathway_order <- pathway_order[1:10]
|
|
136
|
-
select_enrich_data_df <- select_enrich_data_df[select_enrich_data_df$
|
|
164
|
+
select_enrich_data_df <- select_enrich_data_df[select_enrich_data_df$pathway %in% pathway_order, ]
|
|
137
165
|
########################################
|
|
138
|
-
select_enrich_data_df
|
|
139
|
-
select_enrich_data_df$
|
|
140
|
-
|
|
141
|
-
## buble plot
|
|
142
|
-
select_enrich_data_df$x = sapply(select_enrich_data_df$x, function(x) { paste0(grouping_prefix, x) })
|
|
143
|
-
bubblefile = file.path(subset_dir, "pathway_heterogeneity.png")
|
|
144
|
-
bub_devpars = list() # bubble_devpars
|
|
145
|
-
if (is.null(bub_devpars$res)) {
|
|
146
|
-
bub_devpars$res = 100
|
|
147
|
-
}
|
|
148
|
-
if (is.null(bub_devpars$width)) {
|
|
149
|
-
bub_devpars$width = 300 +
|
|
150
|
-
max(nchar(as.character(select_enrich_data_df$y))) * 8 +
|
|
151
|
-
length(unique(select_enrich_data_df$x)) * 25
|
|
152
|
-
}
|
|
153
|
-
if (is.null(bub_devpars$height)) {
|
|
154
|
-
bub_devpars$height = 400 +
|
|
155
|
-
max(nchar(unique(select_enrich_data_df$x))) * 8 +
|
|
156
|
-
length(unique(select_enrich_data_df$y)) * 25
|
|
157
|
-
}
|
|
158
|
-
bub_devpars$height = max(bub_devpars$height, 480)
|
|
159
|
-
# For debug purposes
|
|
166
|
+
select_enrich_data_df[[group_by]] <- factor(select_enrich_data_df[[group_by]], levels = gtools::mixedsort(groups))
|
|
167
|
+
select_enrich_data_df$pathway <- factor(select_enrich_data_df$pathway, levels = pathway_order)
|
|
168
|
+
|
|
160
169
|
write.table(
|
|
161
|
-
select_enrich_data_df,
|
|
162
|
-
file.path(
|
|
163
|
-
sep="\t",
|
|
164
|
-
quote=
|
|
165
|
-
row.names=
|
|
170
|
+
as.data.frame(select_enrich_data_df),
|
|
171
|
+
file = file.path(odir, "pathway_heterogeneity.txt"),
|
|
172
|
+
sep = "\t",
|
|
173
|
+
quote = FALSE,
|
|
174
|
+
row.names = FALSE
|
|
166
175
|
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
+
|
|
177
|
+
for (plot in names(plots)) {
|
|
178
|
+
plotargs <- plots[[plot]]
|
|
179
|
+
plotargs$devpars <- plotargs$devpars %||% list()
|
|
180
|
+
plotargs$devpars$res <- plotargs$devpars$res %||% 100
|
|
181
|
+
|
|
182
|
+
if (plotargs$plot_type == "dot") {
|
|
183
|
+
plotargs$x <- plotargs$x %||% group_by
|
|
184
|
+
plotargs$y <- plotargs$y %||% "pathway"
|
|
185
|
+
plotargs$fill_by <- plotargs$fill_by %||% "NES"
|
|
186
|
+
plotargs$size_by <- plotargs$size_by %||% "pval"
|
|
187
|
+
plotargs$add_bg <- plotargs$add_bg %||% TRUE
|
|
188
|
+
plotargs$x_text_angle <- plotargs$x_text_angle %||% 90
|
|
189
|
+
plotfn <- plotthis::DotPlot
|
|
190
|
+
} else {
|
|
191
|
+
stop("Unknown plot type: ", plotargs$plot_type)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
p <- do_call(plotfn, c(list(select_enrich_data_df), plotargs))
|
|
195
|
+
plotprefix <- file.path(odir, slugify(plot))
|
|
196
|
+
plotargs$devpars$width <- plotargs$devpars$width %||% (attr(p, "width") * plotargs$devpars$res) %||% 800
|
|
197
|
+
plotargs$devpars$height <- plotargs$devpars$height %||% (attr(p, "height") * plotargs$devpars$res) %||% 600
|
|
198
|
+
plotargs$devpars$height <- max(plotargs$devpars$height, plotargs$devpars$width / 1.5)
|
|
199
|
+
png(
|
|
200
|
+
filename = paste0(plotprefix, ".png"),
|
|
201
|
+
width = plotargs$devpars$width,
|
|
202
|
+
height = plotargs$devpars$height,
|
|
203
|
+
res = plotargs$devpars$res
|
|
204
|
+
)
|
|
176
205
|
print(p)
|
|
177
206
|
dev.off()
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
'labs(
|
|
187
|
-
x = NULL, y = NULL, color="NES", size="-log10(pval)"
|
|
188
|
-
)',
|
|
189
|
-
'theme_prism(axis_text_angle = 90)',
|
|
190
|
-
'theme(legend.title = element_text())'
|
|
207
|
+
|
|
208
|
+
reporter$add(
|
|
209
|
+
list(
|
|
210
|
+
name = plot,
|
|
211
|
+
contents = list(
|
|
212
|
+
list(kind = "descr", content = plotargs$descr %||% plot),
|
|
213
|
+
reporter$image(plotprefix, c(), FALSE, kind = "image")
|
|
214
|
+
)
|
|
191
215
|
),
|
|
192
|
-
|
|
193
|
-
|
|
216
|
+
h1 = h1,
|
|
217
|
+
h2 = h2,
|
|
218
|
+
ui = "tabs"
|
|
194
219
|
)
|
|
195
220
|
}
|
|
196
|
-
|
|
197
|
-
## plot variance
|
|
198
|
-
pc_plotdata$group <- factor(pc_plotdata$group, levels = mixedsort(groups))
|
|
199
|
-
p <- ggplot(pc_plotdata) +
|
|
200
|
-
geom_point(aes(x, y, colour = factor(sel)), size = 0.5) +
|
|
201
|
-
scale_color_manual(values = c("gray", "#ff4000")) +
|
|
202
|
-
facet_wrap(~group, scales = "free", ncol = 4) +
|
|
203
|
-
theme_bw() +
|
|
204
|
-
labs(x = "Principal components", y = "Explained variance (%)") +
|
|
205
|
-
theme(
|
|
206
|
-
legend.position = "none", panel.grid.major = element_blank(),
|
|
207
|
-
panel.grid.minor = element_blank(),
|
|
208
|
-
axis.line = element_line(linewidth = 0.2, colour = "black"),
|
|
209
|
-
axis.ticks = element_line(colour = "black", linewidth = 0.2),
|
|
210
|
-
axis.text.x = element_text(colour = "black", size = 6),
|
|
211
|
-
axis.text.y = element_text(colour = "black", size = 6),
|
|
212
|
-
strip.background = element_rect(fill = "white", linewidth = 0.2, colour = NULL),
|
|
213
|
-
strip.text = element_text(size = 6)
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
ggsave(file.path(subset_dir, "PC_variance_plot.pdf"), p, device = "pdf", useDingbats = FALSE)
|
|
217
221
|
}
|
|
218
222
|
|
|
219
|
-
do_one_subset_col <- function(subset_col, subset_prefix) {
|
|
220
|
-
print(paste0("- Handling subset column: ", subset_col, " ..."))
|
|
221
|
-
if (is.null(subset_col)) {
|
|
222
|
-
do_one_subset(NULL, subset_col = NULL, subset_prefix = NULL)
|
|
223
|
-
}
|
|
224
|
-
subsets <- na.omit(unique(sobj@meta.data[[subset_col]]))
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
do_case <- function(casename) {
|
|
225
|
+
log$info("Processing case: {casename} ...")
|
|
226
|
+
case <- cases[[casename]]
|
|
227
|
+
caseinfo <- case_info(casename, outdir, create = TRUE)
|
|
228
|
+
|
|
229
|
+
if (is.null(case$subset_by)) {
|
|
230
|
+
result <- do_subset(
|
|
231
|
+
sobj,
|
|
232
|
+
caseinfo = caseinfo,
|
|
233
|
+
subset_by = NULL,
|
|
234
|
+
subset_val = NULL,
|
|
235
|
+
group_by = case$group_by,
|
|
236
|
+
plots = case$plots,
|
|
237
|
+
select_pcs = case$select_pcs,
|
|
238
|
+
pathway_pval_cutoff = case$pathway_pval_cutoff
|
|
239
|
+
)
|
|
228
240
|
} else {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
stop(paste0("\nmclapply error:", x))
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
241
|
+
sobj_avail <- filter(sobj, !is.na(!!sym(case$subset_by)))
|
|
242
|
+
subsets <- unique(sobj@meta.data[[case$subset_by]])
|
|
235
243
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
lapply(
|
|
245
|
+
subsets,
|
|
246
|
+
function(ss) {
|
|
247
|
+
do_subset(
|
|
248
|
+
sobj_avail,
|
|
249
|
+
caseinfo = caseinfo,
|
|
250
|
+
subset_by = case$subset_by,
|
|
251
|
+
subset_val = ss,
|
|
252
|
+
group_by = case$group_by,
|
|
253
|
+
plots = case$plots,
|
|
254
|
+
select_pcs = case$select_pcs,
|
|
255
|
+
pathway_pval_cutoff = case$pathway_pval_cutoff
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
)
|
|
241
259
|
}
|
|
242
260
|
}
|
|
261
|
+
|
|
262
|
+
sapply(names(cases), do_case)
|
|
263
|
+
|
|
264
|
+
reporter$save(dirname(outdir))
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
library(rlang)
|
|
2
|
+
library(rtracklayer)
|
|
3
|
+
library(MatrixEQTL)
|
|
4
|
+
library(biopipen.utils)
|
|
5
|
+
|
|
6
|
+
snpfile = {{in.geno | r}}
|
|
7
|
+
expfile = {{in.expr | r}}
|
|
8
|
+
covfile = {{in.cov | r}}
|
|
9
|
+
joboutdir = {{job.outdir | r}}
|
|
10
|
+
alleqtl = {{out.alleqtls | r}}
|
|
11
|
+
outfile = {{out.cisqtls | r}}
|
|
12
|
+
|
|
13
|
+
model = {{envs.model | r}}
|
|
14
|
+
pval = {{envs.pval | r}}
|
|
15
|
+
match_samples = {{envs.match_samples | r}}
|
|
16
|
+
transp = {{envs.transp | r}}
|
|
17
|
+
fdr = {{envs.fdr | r}}
|
|
18
|
+
snppos = {{envs.snppos | r}}
|
|
19
|
+
genepos = {{envs.genepos | r}}
|
|
20
|
+
dist = {{envs.dist | r}}
|
|
21
|
+
|
|
22
|
+
transpose_geno = {{envs.transpose_geno | r}}
|
|
23
|
+
transpose_expr = {{envs.transpose_expr | r}}
|
|
24
|
+
transpose_cov = {{envs.transpose_cov | r}}
|
|
25
|
+
|
|
26
|
+
log <- get_logger()
|
|
27
|
+
|
|
28
|
+
arg_match(model, c("modelANOVA", "modelLINEAR", "linear", "anova"))
|
|
29
|
+
if (model == "linear") model = "modelLINEAR"
|
|
30
|
+
if (model == "anova") model = "modelANOVA"
|
|
31
|
+
model = get(model)
|
|
32
|
+
|
|
33
|
+
trans_enabled = !is.null(transp)
|
|
34
|
+
cis_enabled = !is.null(snppos) && !is.null(genepos) && dist > 0
|
|
35
|
+
|
|
36
|
+
# if trans is disabled, all files needed for cis should be provided
|
|
37
|
+
if (!trans_enabled && !cis_enabled) {
|
|
38
|
+
log$warn("Using `envs.transp = 1e-5` since cis-eQTL is disabled.")
|
|
39
|
+
trans_enabled <- TRUE
|
|
40
|
+
transp <- 1e-5
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
transpose_file <- function(file, what) {
|
|
44
|
+
if (is.null(file)) return(NULL)
|
|
45
|
+
log$info("Transposing {what} file ...")
|
|
46
|
+
out <- file.path(joboutdir, paste0(
|
|
47
|
+
tools::file_path_sans_ext(basename(file)),
|
|
48
|
+
".transposed.",
|
|
49
|
+
tools::file_ext(file))
|
|
50
|
+
)
|
|
51
|
+
data <- read.table(file, header=TRUE, stringsAsFactors=FALSE, row.names=1, sep="\t", quote="", check.names=FALSE)
|
|
52
|
+
write.table(t(data), file=out, sep="\t", quote=FALSE, row.names=TRUE, col.names=TRUE)
|
|
53
|
+
out
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (transpose_geno) snpfile = transpose_file(snpfile, "geno")
|
|
57
|
+
if (transpose_expr) expfile = transpose_file(expfile, "expr")
|
|
58
|
+
if (transpose_cov) covfile = transpose_file(covfile, "cov")
|
|
59
|
+
|
|
60
|
+
log$info("Loading SNP data ...")
|
|
61
|
+
snps = SlicedData$new();
|
|
62
|
+
snps$fileDelimiter = "\t"; # the TAB character
|
|
63
|
+
snps$fileOmitCharacters = "NA"; # denote missing values;
|
|
64
|
+
snps$fileSkipRows = 1; # one row of column labels
|
|
65
|
+
snps$fileSkipColumns = 1; # one column of row labels
|
|
66
|
+
snps$fileSliceSize = 10000; # read file in pieces of 2,000 rows
|
|
67
|
+
snps$LoadFile( snpfile );
|
|
68
|
+
|
|
69
|
+
log$info("Loading gene expression data ...")
|
|
70
|
+
gene = SlicedData$new();
|
|
71
|
+
gene$fileDelimiter = "\t"; # the TAB character
|
|
72
|
+
gene$fileOmitCharacters = "NA"; # denote missing values;
|
|
73
|
+
gene$fileSkipRows = 1; # one row of column labels
|
|
74
|
+
gene$fileSkipColumns = 1; # one column of row labels
|
|
75
|
+
gene$fileSliceSize = 10000; # read file in pieces of 2,000 rows
|
|
76
|
+
gene$LoadFile( expfile );
|
|
77
|
+
|
|
78
|
+
cvrt = SlicedData$new();
|
|
79
|
+
if (!is.null(covfile) && file.exists(covfile)) {
|
|
80
|
+
log$info("Loading covariate data ...")
|
|
81
|
+
covmatrix = read.table(covfile, header=TRUE, stringsAsFactors=FALSE, row.names=1, sep="\t", quote="", check.names=FALSE)
|
|
82
|
+
cvrt$CreateFromMatrix( as.matrix(covmatrix) )
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
log$info("Matching samples ...")
|
|
86
|
+
if (match_samples) {
|
|
87
|
+
# let matrixEQTL raise an error if samples do not match
|
|
88
|
+
} else {
|
|
89
|
+
n_sample_snps = snps$nCols()
|
|
90
|
+
n_sample_gene = gene$nCols()
|
|
91
|
+
common_samples = intersect(snps$columnNames, gene$columnNames)
|
|
92
|
+
if (!is.null(covfile)) {
|
|
93
|
+
common_samples = intersect(common_samples, cvrt$columnNames)
|
|
94
|
+
n_sample_cov = cvrt$nCols()
|
|
95
|
+
cvrt = cvrt$ColumnSubsample(match(common_samples, cvrt$columnNames))
|
|
96
|
+
}
|
|
97
|
+
snps = snps$ColumnSubsample(match(common_samples, snps$columnNames))
|
|
98
|
+
gene = gene$ColumnSubsample(match(common_samples, gene$columnNames))
|
|
99
|
+
log$info("- Samples used in SNP data: {n_sample_snps} -> {snps$nCols()}")
|
|
100
|
+
log$info("- Samples used in gene expression data: {n_sample_gene} -> {gene$nCols()}")
|
|
101
|
+
if (!is.null(covfile)) {
|
|
102
|
+
log$info("- Samples used in covariate data: {n_sample_cov} -> {cvrt$nCols()}")
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
log$info("Composing engine parameters ...")
|
|
107
|
+
engine_params = list()
|
|
108
|
+
engine_params$snps = snps
|
|
109
|
+
engine_params$gene = gene
|
|
110
|
+
engine_params$cvrt = cvrt
|
|
111
|
+
engine_params$output_file_name = if(trans_enabled) alleqtl else NULL
|
|
112
|
+
engine_params$pvOutputThreshold = if(trans_enabled) min(transp, 1) else 0
|
|
113
|
+
engine_params$useModel = model
|
|
114
|
+
engine_params$errorCovariance = numeric()
|
|
115
|
+
engine_params$verbose = TRUE
|
|
116
|
+
engine_params$noFDRsaveMemory = !fdr
|
|
117
|
+
|
|
118
|
+
noq = function(s) {
|
|
119
|
+
gsub('^\"|\"$', "", s)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (cis_enabled) {
|
|
123
|
+
log$info("Loading SNP positions ...")
|
|
124
|
+
if (endsWith(snppos, ".bed")) {
|
|
125
|
+
snppos_data = read.table(snppos, header = FALSE, stringsAsFactors = FALSE, sep = "\t")
|
|
126
|
+
snppos_data = data.frame(
|
|
127
|
+
snp = snppos_data$V4,
|
|
128
|
+
chr = snppos_data$V1,
|
|
129
|
+
pos = snppos_data$V3
|
|
130
|
+
)
|
|
131
|
+
} else if (endsWith(snppos, ".gff") || endsWith(snppos, ".gtf")) {
|
|
132
|
+
snppos_data = import(snppos)
|
|
133
|
+
elem_meta = elementMetadata(snppos_data)
|
|
134
|
+
snppos_data = data.frame(
|
|
135
|
+
snp = elem_meta$snp_id %||% elem_meta$rs_id %||% elem_meta$rs,
|
|
136
|
+
chr = as.character(seqnames(snppos_data)),
|
|
137
|
+
pos = start(snppos_data)
|
|
138
|
+
)
|
|
139
|
+
} else if (endsWith(snppos, ".vcf") || endsWith(snppos, ".vcf.gz")) {
|
|
140
|
+
snppos_data = read.table(
|
|
141
|
+
snppos,
|
|
142
|
+
header=FALSE,
|
|
143
|
+
row.names=NULL,
|
|
144
|
+
stringsAsFactors=FALSE,
|
|
145
|
+
check.names=FALSE
|
|
146
|
+
)
|
|
147
|
+
snppos_data = snppos_data[, c(3, 1, 2)]
|
|
148
|
+
colnames(snppos_data) = c("snp", "chr", "pos")
|
|
149
|
+
} else {
|
|
150
|
+
# snp chr pos
|
|
151
|
+
# Snp_01 chr1 721289
|
|
152
|
+
# Snp_02 chr1 752565
|
|
153
|
+
# check if 3rd column of the first line is numeric.
|
|
154
|
+
# if it is, there is no header; otherwise, it is a header.
|
|
155
|
+
header <- is.na(suppressWarnings(as.numeric(strsplit(readLines(snppos, n = 1), "\t")[[1]][3])))
|
|
156
|
+
|
|
157
|
+
snppos_data = read.table(
|
|
158
|
+
snppos,
|
|
159
|
+
sep = "\t",
|
|
160
|
+
header = header,
|
|
161
|
+
row.names = NULL,
|
|
162
|
+
stringsAsFactors = FALSE,
|
|
163
|
+
check.names = FALSE
|
|
164
|
+
)
|
|
165
|
+
colnames(snppos_data) = c("snp", "chr", "pos")
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
log$info("Loading gene positions ...")
|
|
169
|
+
if (endsWith(genepos, ".bed")) {
|
|
170
|
+
genepos_data = read.table(genepos, header = FALSE, stringsAsFactors = FALSE, sep = "\t")
|
|
171
|
+
genepos_data = data.frame(
|
|
172
|
+
geneid = genepos_data$V4,
|
|
173
|
+
chr = genepos_data$V1,
|
|
174
|
+
s1 = genepos_data$V2,
|
|
175
|
+
s2 = genepos_data$V3
|
|
176
|
+
)
|
|
177
|
+
} else if (endsWith(genepos, ".gff") || endsWith(genepos, ".gtf")) {
|
|
178
|
+
genepos_data = import(genepos)
|
|
179
|
+
elem_meta = elementMetadata(genepos_data)
|
|
180
|
+
genepos_data = data.frame(
|
|
181
|
+
geneid = elem_meta$gene_id %||% elem_meta$gene_name,
|
|
182
|
+
chr = as.character(seqnames(genepos_data)),
|
|
183
|
+
s1 = start(genepos_data),
|
|
184
|
+
s2 = end(genepos_data)
|
|
185
|
+
)
|
|
186
|
+
} else {
|
|
187
|
+
parts <- strsplit(readLines(genepos, n = 1), "\t")[[1]]
|
|
188
|
+
header <- is.na(suppressWarnings(as.numeric(parts[3]))) || is.na(suppressWarnings(as.numeric(parts[4])))
|
|
189
|
+
genepos_data = read.table(
|
|
190
|
+
genepos,
|
|
191
|
+
sep = "\t",
|
|
192
|
+
header = header,
|
|
193
|
+
row.names = NULL,
|
|
194
|
+
stringsAsFactors = FALSE,
|
|
195
|
+
check.names = FALSE
|
|
196
|
+
)
|
|
197
|
+
colnames(genepos_data) = c("geneid", "chr", "s1", "s2")
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
log$info("Running MatrixEQTL with cis-eQTLs enabled ...")
|
|
201
|
+
engine_params$output_file_name.cis = outfile
|
|
202
|
+
engine_params$pvOutputThreshold.cis = min(pval, 1)
|
|
203
|
+
engine_params$cisDist = dist
|
|
204
|
+
engine_params$snpspos = snppos_data
|
|
205
|
+
engine_params$genepos = genepos_data
|
|
206
|
+
do_call(Matrix_eQTL_main, engine_params)
|
|
207
|
+
if (!file.exists(alleqtl)) file.create(alleqtl)
|
|
208
|
+
} else {
|
|
209
|
+
log$info("Running MatrixEQTL without cis-eQTLs ...")
|
|
210
|
+
do_call(Matrix_eQTL_engine, engine_params)
|
|
211
|
+
if (!file.exists(outfile)) file.create(outfile)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (pval == 0) {
|
|
215
|
+
if (!file.exists(outfile)) file.create(outfile)
|
|
216
|
+
if (!file.exists(alleqtl)) file.create(alleqtl)
|
|
217
|
+
}
|