Skip to content

Commit eb073be

Browse files
authored
Merge pull request #72 from CAnBioNet/fix-percent-inclusion
Fix percent inclusion column from subsample analysis always being 100%
2 parents ddf1c7a + 5ce6c2d commit eb073be

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

reconstruction/analyze_subsample_results.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def getArgs():
3333
dataZip = ZipFile(args.dataFile)
3434
nameList = dataZip.namelist()
3535
subsampleIndices = sorted({int(name.split("/")[0]) for name in nameList})
36-
neededArrays = {arrayName: [] for arrayName in ["correlationCoefficients", "combinedCorrelationPValues", "correctedCorrelationPValues"]}
36+
neededArrays = {arrayName: [] for arrayName in ["correlationCoefficients", "combinedCorrelationPValues", "correctedCorrelationPValues", "edges"]}
3737
for index in subsampleIndices:
3838
for arrayName, arrayList in neededArrays.items():
3939
fileName = "{}/{}".format(index, arrayName)
@@ -76,6 +76,7 @@ def getArgs():
7676
rVals = xarray.concat(dataArrays["correlationCoefficients"], dim="subsample")
7777
combinedPVals = xarray.concat(dataArrays["combinedCorrelationPValues"], dim="subsample")
7878
correctedPVals = xarray.concat(dataArrays["correctedCorrelationPValues"], dim="subsample")
79+
edges = xarray.concat(dataArrays["edges"], dim="subsample")
7980

8081
if args.singlecell:
8182
nodeDims = ["measurableAndCellType1", "measurableAndCellType2"]
@@ -85,9 +86,11 @@ def getArgs():
8586
combinedPValMedians = combinedPVals.median(dim="subsample")
8687
correctedPValMedians = correctedPVals.median(dim="subsample")
8788

88-
combinedData = rVals.mean(dim="metatreatment")
89-
percentInclusions = combinedData.count(dim="subsample") / combinedData.sizes["subsample"]
89+
edgeIncluded = edges != 0
90+
subsampleAxis = edgeIncluded.get_axis_num("subsample")
91+
percentInclusions = xarray.apply_ufunc(numpy.count_nonzero, edgeIncluded, input_core_dims=[edgeIncluded.dims], output_core_dims=[nodeDims], kwargs=dict(axis=subsampleAxis)) / edgeIncluded.sizes["subsample"]
9092

93+
combinedData = rVals.mean(dim="metatreatment")
9194
medians = combinedData.median(dim="subsample")
9295
maxs = combinedData.max(dim="subsample")
9396
mins = combinedData.min(dim="subsample")

0 commit comments

Comments
 (0)