Skip to content

Commit

Permalink
Merge pull request #1202 from saimarathore/master
Browse files Browse the repository at this point in the history
Molecular subtype prediction fixes and code cleanup
  • Loading branch information
sarthakpati authored Jul 24, 2020
2 parents 250bcdf + 82ef813 commit a378796
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 241 deletions.
401 changes: 233 additions & 168 deletions src/applications/MolecularSubtypePredictor.cpp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/applications/MolecularSubtypePredictor.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "MolecularSubtypePredictor.h"
#include "cbicaUtilities.h"
#include "cbicaCmdParser.h"

#include "CaPTkGUIUtils.h"


//------------------Molecular subtype prediction on existing model-----------------------
std::vector<std::map<CAPTK::ImageModalityType, std::string>> LoadQualifiedSubjectsFromGivenDirectory(const std::string directoryname)
{
Expand Down
9 changes: 5 additions & 4 deletions src/applications/MolecularSubtypePredictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ See COPYING file or https://www.med.upenn.edu/sbia/software-agreement.html
#include "NiftiDataManager.h"
#include "FeatureReductionClass.h"
#include "FeatureScalingClass.h"
#include "TrainingModule.h"
#include "FeatureExtractionClass.h"
#include "itkCSVArray2DFileReader.h"
#include "itkConnectedComponentImageFilter.h"
Expand Down Expand Up @@ -262,10 +263,10 @@ class MolecularSubtypePredictor



VariableSizeMatrixType SelectSixMonthsModelFeatures(const VariableSizeMatrixType &SixMonthsFeatures);
VariableSizeMatrixType SelectEighteenMonthsModelFeatures(const VariableSizeMatrixType &EighteenModelFeatures);

template<class ImageType>
VariableSizeMatrixType SelectModelFeatures(const VariableSizeMatrixType &ModelFeatures, const VariableLengthVectorType &selectedFeatures);
VariableSizeMatrixType SelectModelFeatures(const VariableSizeMatrixType &ModelFeatures, const VectorDouble &selectedFeatures);
template<class ImageType>
typename ImageType::Pointer RemoveSmallerComponentsFromTumor(const typename ImageType::Pointer &etumorImage, const typename ImageType::Pointer &ncrImage);

VariableLengthVectorType DistanceFunction(const VariableSizeMatrixType &testData, const std::string &filename, const double &rho, const double &bestg);
Expand Down
1 change: 0 additions & 1 deletion src/applications/PerfusionPCA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int main(int argc, char **argv)
parser.addOptionalParameter("m", "model", cbica::Parameter::STRING, "", "The directory having PCA models");
parser.addRequiredParameter("o", "output", cbica::Parameter::STRING, "", "The output directory.");
parser.addOptionalParameter("L", "Logger", cbica::Parameter::STRING, "log file which user has write access to", "Full path to log file to store console outputs", "By default, only console output is generated");
//parser.exampleUsage("");
parser.addExampleUsage("-t 0 -i C:/properly/formatted/inputDir -o C:/outputDir -n 5", "Trains a new model based on the samples in inputDir");
parser.addExampleUsage("-t 1 -i C:/input -m C:/model -o C:/output -m C:/modelDir -n 5", "Tests an existing model for inputs in 'C:/input' based on 'C:/modelDir' ");
parser.addApplicationDescription("Perfusion PCA Training and Prediction application");
Expand Down
155 changes: 91 additions & 64 deletions src/applications/common_includes/FeatureExtractionClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,72 +160,99 @@ void FeatureExtractionClass::FormulateEGFRTrainingData(const VariableSizeMatrixT
}
}

void FeatureExtractionClass::FormulateMolecularTrainingData(VectorDouble inputLabels,
VectorDouble & proneuralModelLabels, VectorDouble & neuralModelLabels,
VectorDouble & messModelLabels, VectorDouble & classicalModelLabels)
{
for (unsigned int i = 0; i < inputLabels.size(); i++)
{
if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::PRONEURAL)
proneuralModelLabels.push_back(1);
else
proneuralModelLabels.push_back(-1);

if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::NEURAL)
neuralModelLabels.push_back(1);
else
neuralModelLabels.push_back(-1);

if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::MESSENCHYMAL)
messModelLabels.push_back(1);
else
messModelLabels.push_back(-1);

if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::CLASSICAL)
classicalModelLabels.push_back(1);
else
classicalModelLabels.push_back(-1);
}
}



void FeatureExtractionClass::FormulateMolecularTrainingData(const VariableSizeMatrixType &inputFeatures, std::vector<double> inputLabels, VariableSizeMatrixType & proneuralModelFeatures, VariableSizeMatrixType & neuralModelFeatures, VariableSizeMatrixType & messenchymalModelFeatures, VariableSizeMatrixType & classicalModelFeatures)
{
std::vector<int> proneuralModelIndices;
std::vector<int> neuralModelIndices;
std::vector<int> messenchymalModelIndices;
std::vector<int> classicalModelIndices;

for (unsigned int i = 0; i < inputLabels.size(); i++)
{
if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::PRONEURAL)
proneuralModelIndices.push_back(i);
else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::NEURAL)
neuralModelIndices.push_back(i);
else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::MESSENCHYMAL)
messenchymalModelIndices.push_back(i);
else
classicalModelIndices.push_back(i);
}
classicalModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
proneuralModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
neuralModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
messenchymalModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);


for (unsigned int i = 0; i < inputFeatures.Rows(); i++)
{
unsigned int j = 0;
for (j = 0; j < inputFeatures.Cols(); j++)
{
classicalModelFeatures(i, j) = inputFeatures(i, j);
neuralModelFeatures(i, j) = inputFeatures(i, j);
proneuralModelFeatures(i, j) = inputFeatures(i, j);
messenchymalModelFeatures(i, j) = inputFeatures(i, j);
}
if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::PRONEURAL)
{
proneuralModelFeatures(i, j) = 1;
neuralModelFeatures(i, j) = 0;
messenchymalModelFeatures(i, j) = 0;
classicalModelFeatures(i, j) = 0;
}
else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::NEURAL)
{
proneuralModelFeatures(i, j) = 0;
neuralModelFeatures(i, j) = 1;
messenchymalModelFeatures(i, j) = 0;
classicalModelFeatures(i, j) = 0;
}
else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::CLASSICAL)
{
proneuralModelFeatures(i, j) = 0;
neuralModelFeatures(i, j) = 0;
messenchymalModelFeatures(i, j) = 0;
classicalModelFeatures(i, j) = 1;
}
else
{
proneuralModelFeatures(i, j) = 0;
neuralModelFeatures(i, j) = 0;
messenchymalModelFeatures(i, j) = 1;
classicalModelFeatures(i, j) = 0;
}
}
}
//
//
//void FeatureExtractionClass::FormulateMolecularTrainingData(const VariableSizeMatrixType &inputFeatures, std::vector<double> inputLabels, VariableSizeMatrixType & proneuralModelFeatures, VariableSizeMatrixType & neuralModelFeatures, VariableSizeMatrixType & messenchymalModelFeatures, VariableSizeMatrixType & classicalModelFeatures)
//{
// std::vector<int> proneuralModelIndices;
// std::vector<int> neuralModelIndices;
// std::vector<int> messenchymalModelIndices;
// std::vector<int> classicalModelIndices;
//
// for (unsigned int i = 0; i < inputLabels.size(); i++)
// {
// if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::PRONEURAL)
// proneuralModelIndices.push_back(i);
// else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::NEURAL)
// neuralModelIndices.push_back(i);
// else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::MESSENCHYMAL)
// messenchymalModelIndices.push_back(i);
// else
// classicalModelIndices.push_back(i);
// }
// classicalModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
// proneuralModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
// neuralModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
// messenchymalModelFeatures.SetSize(inputFeatures.Rows(), inputFeatures.Cols() + 1);
//
//
// for (unsigned int i = 0; i < inputFeatures.Rows(); i++)
// {
// unsigned int j = 0;
// for (j = 0; j < inputFeatures.Cols(); j++)
// {
// classicalModelFeatures(i, j) = inputFeatures(i, j);
// neuralModelFeatures(i, j) = inputFeatures(i, j);
// proneuralModelFeatures(i, j) = inputFeatures(i, j);
// messenchymalModelFeatures(i, j) = inputFeatures(i, j);
// }
// if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::PRONEURAL)
// {
// proneuralModelFeatures(i, j) = 1;
// neuralModelFeatures(i, j) = 0;
// messenchymalModelFeatures(i, j) = 0;
// classicalModelFeatures(i, j) = 0;
// }
// else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::NEURAL)
// {
// proneuralModelFeatures(i, j) = 0;
// neuralModelFeatures(i, j) = 1;
// messenchymalModelFeatures(i, j) = 0;
// classicalModelFeatures(i, j) = 0;
// }
// else if (inputLabels[i] == CAPTK::MOLECULAR_SUBTYPES::CLASSICAL)
// {
// proneuralModelFeatures(i, j) = 0;
// neuralModelFeatures(i, j) = 0;
// messenchymalModelFeatures(i, j) = 0;
// classicalModelFeatures(i, j) = 1;
// }
// else
// {
// proneuralModelFeatures(i, j) = 0;
// neuralModelFeatures(i, j) = 0;
// messenchymalModelFeatures(i, j) = 1;
// classicalModelFeatures(i, j) = 0;
// }
// }
//}
5 changes: 3 additions & 2 deletions src/applications/common_includes/FeatureExtractionClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ class FeatureExtractionClass

void FormulateEGFRTrainingData(const VariableSizeMatrixType &inputFeatures, std::vector<double> inputSurvival, VariableSizeMatrixType & SixModelFeatures);

void FormulateMolecularTrainingData(const VariableSizeMatrixType &inputFeatures, std::vector<double> inputLabels, VariableSizeMatrixType & proneuralModelFeatures, VariableSizeMatrixType & neuralModelFeatures, VariableSizeMatrixType & messenchymalModelFeatures, VariableSizeMatrixType & classicalModelFeatures);

void FormulateMolecularTrainingData(VectorDouble inputLabels,
VectorDouble & proneuralModelLabels, VectorDouble & neuralModelLabels,
VectorDouble & messModelLabels, VectorDouble & classicalModelLabels);
/**
\brief Formulates the test data by using intensities of near and far regions, and adding corresponding label
\param testdata Intensities of test voxels
Expand Down

0 comments on commit a378796

Please sign in to comment.