// function that creates a roi map from glm and a previously defined roi in mni void FunctionalConnectivity::createROIVolume(studyParams &vdb) { // Bring MNI Mask to Subject Space char outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500]; double correlationExtractPercent; char prefix[30]="_RFI2"; extractFileName(vdb.mniMask, name); for (int t=0;t<strlen(name);t++) if (name[t] == '.') name[t] = '_'; sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix); MniToSubject(vdb.rfiFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix); // read Region extract map file and percentage correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "RegionExtractionMapPerc") / 100.0; strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "RegionExtractionMapFile")); RegionExtraction extractor; // reading the mappings std::map<int, int> mappings; extractor.readMappings(regionExtractMapFile, mappings); sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii"); // Execute segmentation extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent); }
// function that creates a roi map from glm and a previously defined roi in mni void emotionRoiProcessing::createROIVolume(studyParams &vdb) { // Bring MNI Mask to Subject Space char compositeFile[500], outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500], meanFile[500]; char pngFile[500]; double correlationExtractPercent; stringstream CmdLn; char prefix[30] = "_RFI2"; vector<vector<double>> timeseries; // generating the means file volume<float> v; // preparing timeseries variable timeseries.resize(meanCalculation.roiCount()); for (int i = 0; i < timeseries.size(); i++) timeseries[i].resize(vdb.interval.maxIndex()); // calculating the means for (int i = 0; i < vdb.interval.maxIndex(); i++) { loadVolume(vdb, v, i+1); meanCalculation.calculateMeans(v); for (int j = 0; j < meanCalculation.roiCount(); j++) timeseries[j][i] = meanCalculation.roiMean(j); } // z normalized for (int j = 0; j < timeseries.size(); j++) znormalise(timeseries[j]); // saving the result to file sprintf(meanFile, "%s%s_%s%s.txt", vdb.outputDir, vdb.subject, "means", vdb.trainFeatureSuffix); fstream Output(meanFile, fstream::in | fstream::out | fstream::trunc); for (int i = 0; i < vdb.interval.maxIndex(); i++) { for (int j = 0; j < timeseries.size(); j++) Output << timeseries[j][i] << '\t'; Output << '\n'; } Output.close(); // generating the roi means graph png fprintf(stderr, "Generating roi means graphic\n"); changeFileExt(meanFile, ".png", pngFile); CmdLn << "fsl_tsplot -i " << meanFile << " -t \"z-normalised roi means plot\" -u 1 --start=1 --finish=" << meanCalculation.roiCount() << " -a "; vector<int> roiValues; meanCalculation.getRoiValues(roiValues); // Building the labels with the intensities of the roi volume file int counter=0; CmdLn << '\"'; for (int t = 0; t < roiValues.size(); t++) { CmdLn << "Intensity " << roiValues[t]; counter++; if (counter < meanCalculation.roiCount()) CmdLn << ','; } // completing the command CmdLn << '\"'; CmdLn << " -w 640 -h 144 -o " << pngFile; fsl_tsplot((char *)CmdLn.str().c_str()); extractFileName(vdb.mniMask, name); for (int t = 0; t<strlen(name); t++) if (name[t] == '.') name[t] = '_'; sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix); MniToSubject(vdb.maskFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix); // saving a composite file just to assure the side of the roi volume sprintf(compositeFile, "%s%s%s.nii", vdb.inputDir, "compositeFile", vdb.trainFeatureSuffix); uniteVolumes(vdb.rfiFile, outputFile, compositeFile); // read Region extract map file and percentage correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "PercentageOfBestVoxelsPerROI") / 100.0; strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "ROIExtractionMapFile")); RegionExtraction extractor; // reading the mappings std::map<int, int> mappings; extractor.readMappings(regionExtractMapFile, mappings); sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii"); // Execute segmentation extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent); // calculate initial target values for positive and negative conditions if (fileExists(roiVolumeFile)) { meanCalculation.loadReference(roiVolumeFile); positiveIndex = meanCalculation.roiIndex(3); // 3 in the intensity value of positive emotion ROI negativeIndex = meanCalculation.roiIndex(1); // 1 in the intensity value of negative emotion ROI for (int i=1; i <= vdb.interval.maxIndex(); i++) { float classnum, projection; processVolume(vdb, i, classnum, projection); } char negativeCurveFile[BUFF_SIZE], positiveCurveFile[BUFF_SIZE]; sprintf(negativeCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "negative_curve", vdb.trainFeatureSuffix); sprintf(positiveCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "positive_curve", vdb.trainFeatureSuffix); positiveActivationLevel.saveCurves(positiveCurveFile); negativeActivationLevel.saveCurves(negativeCurveFile); vdb.readedIni.SetDoubleValue("FRIEND", "NegativeActivationLevel", negativeActivationLevel.mean); vdb.readedIni.SetDoubleValue("FRIEND", "PositiveActivationLevel", positiveActivationLevel.mean); vdb.readedIni.SaveFile(vdb.configFileNameRead); } }