getParentalARA.m 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. %% Method generate a atlas with all parental regions of the given xlsx file
  2. % getParentalARA('./annotation_label_IDs_valid.xlsx','./annotation/annotation.nii.gz')
  3. function getParentalARA(xml_file,atlasNii_file)
  4. addpath('./AllenBrainAPI-master/');
  5. labelsStrArray = char(readXML_Lables(xml_file));
  6. atlasData = load_nii(atlasNii_file);
  7. parentalAtlasVolume = zeros(size(atlasData.img));
  8. for label_idx = 1:length(labelsStrArray)
  9. disp(labelsStrArray(label_idx,:));
  10. childTable = getAllenStructureList('childrenOf',labelsStrArray(label_idx,:));
  11. if isempty(childTable)
  12. continue
  13. end
  14. childIDs = childTable.id;
  15. parentalID = name2structureID(labelsStrArray(label_idx,:));
  16. for child_idx = 1:length(childIDs)
  17. parentalAtlasVolume(atlasData.img==childIDs(child_idx)) = parentalID;
  18. end
  19. end
  20. % change large annotation value of Primary somatosensory area, unassigned
  21. parentalAtlasVolume(parentalAtlasVolume==182305689)= 1098;
  22. file=dir(atlasNii_file);
  23. fileName = strsplit(string(file.name),'.');
  24. output_file = [fileName{1} '_parent.' fileName{2} '.' fileName{3}];
  25. atlasData.img = parentalAtlasVolume;
  26. save_nii(atlasData,output_file);
  27. end