Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add differential expression #70

Merged
merged 6 commits into from
Dec 5, 2024
Merged

Conversation

asizemore
Copy link
Member

@asizemore asizemore commented Nov 11, 2024

Adds a differential expression compute to the "compute service".

Fully functional. Test with VEuPathDB/veupathUtils#50

Can use

{
	"config": {
		"differentialExpressionMethod": "DESeq",
		"pValueFloor": "1e-200",
		"collectionVariable": {
			"entityId": "OBI_0002623",
			"collectionId": "EUPATH_0009254"
		},
		"comparator": {
			"variable": {
				"entityId": "EUPATH_0000096",
				"variableId": "EUPATH_0000639"
			},
			"groupA": [
				{
					"label": "Control"
				}
			],
			"groupB": [
				{
					"label": "Cystic fibrosis"
				}
			]
		}
	},
	"derivedVariables": [],
	"filters": [],
	"studyId": "BONUS-1"
}

send to computes/differentialexpression/

For the volcanoplot, first ensure the above computation has finished, then send the following to apps/differentialexpression/visualizations/volcanoplot

{
	"studyId": "BONUS-1",
	"filters": [],
	"config": {},
	"computeConfig": {
		"differentialExpressionMethod": "DESeq",
		"pValueFloor": "1e-200",
		"collectionVariable": {
			"entityId": "OBI_0002623",
			"collectionId": "EUPATH_0009254"
		},
		"comparator": {
			"variable": {
				"entityId": "EUPATH_0000096",
				"variableId": "EUPATH_0000639"
			},
			"groupA": [
				{
					"label": "Control"
				}
			],
			"groupB": [
				{
					"label": "Cystic fibrosis"
				}
			]
		}
	}
}

@asizemore asizemore marked this pull request as ready for review November 22, 2024 23:08
Copy link
Member

@bobular bobular left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I haven't tested it because I'm on the wrong machine and don't really have time to set everything up. I have a couple of comments and a question!

EntityDef entity = meta.getEntity(entityId).orElseThrow();
VariableDef computeEntityIdVarSpec = util.getEntityIdVarSpec(entityId);
String computeEntityIdColName = util.toColNameOrEmpty(computeEntityIdVarSpec);
// if we ever introduce limma we can go back to this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limma is another method for differential abundance analysis. But it's no longer on the horizon. Comment removed 👍

VariableDef computeEntityIdVarSpec = util.getEntityIdVarSpec(entityId);
String computeEntityIdColName = util.toColNameOrEmpty(computeEntityIdVarSpec);
// if we ever introduce limma we can go back to this
String method = computeConfig.getDifferentialExpressionMethod().getValue().equals("DESeq") ? "DESeq" : "unknown";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this throw an exception if it's not DESeq? There are no other options in the RAML.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does error if it doesn't receive DESeq. The api doesn't let it pass, but then also the R code will err as well if the method isn't DESeq.

computeInputVars.addAll(util.getCollectionMembers(collectionSpec));
computeInputVars.addAll(idColumns);
connection.voidEval(util.getVoidEvalFreadCommand(INPUT_DATA, computeInputVars));
connection.voidEval("countData <- " + INPUT_DATA); // Renaming here so we can go get the sampleMetadata later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit roundabout loading as R variable differential_expression_input (aka INPUT_DATA) and then renaming immediately but I guess it's what we always do?

But, as you explain, we're reading the same file again into sampleMetadataVars so it makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I went back and forth on this a while, because you're right, it does seem a little roundabout. But I'm hoping it'll be a little faster this way!


// Turn the list of id columns into an array of strings for R
List<String> dotNotatedIdColumns = idColumns.stream().map(VariableDef::toDotNotation).toList();
StringBuilder dotNotatedIdColumnsString = new StringBuilder("c(");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following from our friend (assuming it works) might be more readable?

String dotNotatedIdColumnsString = "c(" + 
    dotNotatedIdColumns.stream()
                       .map(this::singleQuote)
                       .collect(Collectors.joining(",")) + ")";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a try!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it didn't work, unfortunately, even with a little tweaking. Perhaps when my java skills are sharper i can revisit!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries - sorry I didn't test it out myself!

@Override
public PostAppsDifferentialexpressionVisualizationsVolcanoplotResponse postAppsDifferentialexpressionVisualizationsVolcanoplot(DifferentialExpressionVolcanoplotPostRequest entity) {
return wrapPlugin(() -> PostAppsDifferentialexpressionVisualizationsVolcanoplotResponse.respond200WithApplicationJson(
new DifferentialExpressionStatsResponseStream(processRequest(new DifferentialExpressionVolcanoplotPlugin(), entity))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm puzzling where DifferentialExpressionStatsResponseStream is defined...?

Is it in a previous PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DifferentialExpressionStatsResponseStream gets automatically generated. The auto-generated files aren't usually tracked in git because there are too many of them. But it'll show up in eda/generated/model.

@asizemore asizemore merged commit 66c7075 into master Dec 5, 2024
@asizemore asizemore deleted the add-differential-expression branch December 5, 2024 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants