Skip to content

Commit

Permalink
better barplot for gene usage
Browse files Browse the repository at this point in the history
  • Loading branch information
PoslavskySV committed Oct 18, 2022
1 parent 3df09bf commit 5b4bdd3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ abstract class CommandPaExportPlotsGeneUsage : CommandPaExportPlotsHeatmapWithGr
if (df.rowsCount() == 0) return

val plot = if (barPlot)
plotBarPlot(df, facetBy)
plotBarPlot(df, facetBy, width, height)
else if (barPlotBySamples)
plotBarPlotBySample(df, facetBy)
plotBarPlotBySample(df, facetBy, width, height)
else
plot(
df,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.milaboratory.miplots.StandardPlots
import com.milaboratory.miplots.toPDF
import com.milaboratory.mixcr.postanalysis.PostanalysisResult
import com.milaboratory.mixcr.postanalysis.SetPreprocessorStat
import jetbrains.letsPlot.ggsize
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.api.rows
Expand Down Expand Up @@ -110,22 +111,40 @@ object GeneUsage {
fun plotBarPlot(
df: DataFrame<GeneUsageRow>,
facetBy: String?,
) = StandardPlots.PlotType.BarPlot.plot(
df,
y = GeneUsageRow::weight.name,
primaryGroup = GeneUsageRow::gene.name,
secondaryGroup = GeneUsageRow::sample.name,
facetBy = facetBy
).plot
width: Int,
height: Int
) = run {
var plt = StandardPlots.PlotType.BarPlot.plot(
df,
y = GeneUsageRow::weight.name,
primaryGroup = GeneUsageRow::gene.name,
secondaryGroup = GeneUsageRow::sample.name,
facetBy = facetBy
).plot

if (width > 0 && height > 0)
plt += ggsize(width, height)

plt
}

fun plotBarPlotBySample(
df: DataFrame<GeneUsageRow>,
facetBy: String?,
) = StandardPlots.PlotType.BarPlot.plot(
df,
y = GeneUsageRow::weight.name,
primaryGroup = GeneUsageRow::sample.name,
secondaryGroup = GeneUsageRow::gene.name,
facetBy = facetBy
).plot
width: Int,
height: Int
) = run {
var plt = StandardPlots.PlotType.BarPlot.plot(
df,
y = GeneUsageRow::weight.name,
primaryGroup = GeneUsageRow::sample.name,
secondaryGroup = GeneUsageRow::gene.name,
facetBy = facetBy
).plot

if (width > 0 && height > 0)
plt += ggsize(width, height)

plt
}
}

0 comments on commit 5b4bdd3

Please sign in to comment.