PRELIMINAR_Analisis_Esferas_Neuronas_1.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. clear all;
  2. % %%
  3. clc
  4. % Leemos el archivo de Matlab conteniendo las neuronas
  5. % Num_File = 3;
  6. % load(['Cortes_Muestra_Axon_', num2str(Num_File), '.mat']);
  7. Path_Data_1 = '/Users/pepo/Google Drive (1)/Cesar Mario Axones/Neuronas/Selección de NeuroMorpho 23-2/Específicas - tipo 1/';
  8. Path_Data_File_1 = '/Neuronas Especificas - Tipo 1.txt';
  9. % Path_Data_1 = '/Users/pepo/Google Drive (1)/Cesar Mario Axones/Neuronas/Selección de NeuroMorpho 23-2/Multiespecíficas - tipo 2/';
  10. % Path_Data_File_1 = '/Neuronas Multiespecificas - Tipo 2.txt';
  11. % Path_Data_1 = '/Users/pepo/Google Drive (1)/Cesar Mario Axones/Neuronas/Selección de NeuroMorpho 23-2/Inespecíficas - tipo 3/';
  12. % Path_Data_File_1 = '/Neuronas Inespecificas - Tipo 3.txt';
  13. % Path_Data_1 = '/Users/pepo/Google Drive (1)/Cesar Mario Axones/Neuronas/Selección de NeuroMorpho 23-2/Locales- tipo 4/';
  14. % Path_Data_File_1 = '/Neuronas Locales - Tipo 4.txt';
  15. % Read the names of files with raw data:
  16. fileID = fopen([Path_Data_1, Path_Data_File_1]); % Spanish Data by Carlos
  17. %
  18. names_1 = textscan(fileID,'%s', 'delimiter', '\n', 'whitespace', '');
  19. fclose(fileID);
  20. names_1 = names_1{1};
  21. %%
  22. clc
  23. rr = 46;
  24. h_Cortes = 1; % Analizamos un corte cada 'h_Cortes' cortes de la muestra
  25. Grosor_Corte = 50; % En micras
  26. Diams_Sonda = 45; % Vector con los diámetros de la sonda a considerar. En micras
  27. Step_Lengths = 140; % Vector con los step lengths a considerar. En micras
  28. lado_x_Frame = 50; % en micras
  29. lado_y_Frame = 50; % en micras
  30. sampling_box_height = 50; % en micras
  31. % Leemos los archivos
  32. fname=fullfile(Path_Data_1, [names_1{rr}]);
  33. fname_new = [fname(1:end-4), '.mat'];
  34. load( fname_new );
  35. [Q, Error_Length, Axon_Real_Length, Estimated_Axon_Length, Filas_Centros, Columnas_Centros, Z_Centros] = Sgript_Estim_Long_Axon_Estereo ( AXON_Cell, AXON, Diams_Sonda, Step_Lengths, Grosor_Corte, h_Cortes, lado_x_Frame, lado_y_Frame, sampling_box_height );
  36. % %% Longitud total del axón
  37. %
  38. % branch_length = zeros( 1, length(AXON_Cell) );
  39. % aa= 0;
  40. % for i = 1:length(AXON_Cell)
  41. %
  42. % dummy = AXON_Cell{1, i};
  43. % diff_dummy = diff( dummy, 1, 1 );
  44. % branch_length( i ) = sum( sqrt( sum( diff_dummy(:, 1:3).^2, 2 ) ) );
  45. % aa = aa + length(dummy);
  46. % end
  47. % Axon_Length = sum( branch_length );
  48. %
  49. % %% Obtenemos las intersecciones de la esfera para estimar la longitud total:
  50. %
  51. % clc
  52. %
  53. % h_Cortes = 1; % Analizamos un corte cada 'h_Cortes' cortes de la muestra
  54. %
  55. % % El 'frame' es la sampling box en la que se introduce la esfera; esa caja luego se introduce en la celda de la rejilla en que se ha dividido el corte.
  56. % lado_x_Frame = 50; % en micras
  57. % lado_y_Frame = 50; % en micras
  58. % sampling_box_height = 50; % en micras
  59. %
  60. % % Radio sonda esférica:
  61. % rad_sonda = sampling_box_height/2;
  62. %
  63. % [Q, Intersecciones_Detalladas, Error_Length, Filas_Centros, Columnas_Centros, Z_Centros] = Script_Analisis_Esferas_Neuronas_1 ( Cortes_XY_Axon, h_Cortes, rad_sonda, Columnas_Rejilla, Rejilla_X, Filas_Rejilla, Rejilla_Y, Cortes, Grosor_Corte, lado_x_Frame, lado_y_Frame, sampling_box_height, Axon_Length );
  64. %
  65. %% Ploteamos el axón con las esferas
  66. clc
  67. rad_sonda = Diams_Sonda/2;
  68. [x,y,z] = sphere;
  69. figure;
  70. hold on;
  71. for i = 1:length(AXON_Cell)
  72. Puntos_Axon = AXON_Cell{1, i};
  73. plot3( Puntos_Axon(:, 1), Puntos_Axon(:, 2), Puntos_Axon(:, 3), '-k', 'markersize', 10, 'linewidth', 1.5 );
  74. xlabel('X');
  75. ylabel('Y');
  76. zlabel('Z');
  77. % zlim([150 200]);
  78. % view([-96, -90]);
  79. axis equal
  80. end
  81. % Esferas
  82. for i_x = Columnas_Centros % Columna de la rejilla
  83. for i_y = Filas_Centros % Fila de la rejilla
  84. for i_z = 1:h_Cortes:length(Z_Centros) % Corte
  85. surf( rad_sonda*x + i_x, rad_sonda*y + i_y, rad_sonda*z + Z_Centros(i_z),'FaceAlpha',0.9,'EdgeColor','none' );
  86. end
  87. end
  88. end
  89. %% Para chequear
  90. clc
  91. for j=ind_CORTE
  92. % j=437
  93. [row_a, col_a] = find(~cellfun(@isempty, dummy_CORTE{1, j})); % para cada rama estos son los índices de las celdas de ese corte en el que aparecen dichas ramas
  94. % disp([row_a, col_a]);
  95. %
  96. k = 2;
  97. if length(row_a)>1
  98. dummy_a = dummy_CORTE{1, j}{row_a(k), col_a(k)}; % Coordenadas de los puntos de la rama cuya intersección estamos estudiando
  99. % Obtenemos las distancias al centro de la sonda esférica:
  100. dist_centro_sonda = sqrt( ( dummy_a(:, 1) - Columnas_Centros(col_a(k)) ).^2 + ( dummy_a(:, 2) - Filas_Centros(row_a(k)) ).^2 +...
  101. ( dummy_a(:, 3) - Z_Centros(i) ).^2 );
  102. num_inters = sum( abs( diff( dist_centro_sonda <= rad_sonda ) ) );
  103. if num_inters > 3
  104. disp(j)
  105. end
  106. end
  107. end
  108. %% Comprobamos que está bien, ploteando rama a rama:
  109. [x,y,z] = sphere;
  110. % clc
  111. i_x = col_a(k); % Columna de la rejilla
  112. i_y = row_a(k); % Fila de la rejilla
  113. i_z = i; % Corte
  114. colores = {'r', 'b', 'm', 'k', 'g'};
  115. figure('color', 'w', 'position', [250, 200, 700, 600]);
  116. hold on
  117. % for iii = 1:length(Cortes_XY_Axon{i_z, 1})
  118. for iii = ind_CORTE
  119. if ~isempty( Cortes_XY_Axon{i_z, 1}{1, iii} )
  120. dummy = Cortes_XY_Axon{i_z, 1}{1, iii};
  121. for i_fila = 1:size(dummy, 1)
  122. for i_columna = 1:size(dummy, 2)
  123. if ~isempty(dummy{i_fila, i_columna})
  124. Puntos_Axon = dummy{i_fila, i_columna};
  125. plot3( Puntos_Axon(:, 1), Puntos_Axon(:, 2), Puntos_Axon(:, 3), '-o', 'color', colores{mod(i, 5)+1}, 'markersize', 7, 'linewidth', 1.5 );
  126. end
  127. end
  128. end
  129. end
  130. axis equal
  131. xlim([Columnas_Rejilla(i_x), Columnas_Rejilla(i_x) + Rejilla_X]);
  132. ylim([Filas_Rejilla(i_y), Filas_Rejilla(i_y) + Rejilla_Y]);
  133. zlim([Cortes(i_z), Cortes(i_z) + Grosor_Corte]);
  134. view([32, 20]);
  135. end
  136. surf( rad_sonda*x + Columnas_Centros(col_a(k)), rad_sonda*y + Filas_Centros(row_a(k)), rad_sonda*z + Z_Centros(i) );
  137. alpha 0.7
  138. % surf( rad_sonda*x + Columnas_Centros(i_x), rad_sonda*y + Filas_Centros(i_y), rad_sonda*z + Z_Centros(i_z) );
  139. %% Comprobamos que está bien, ploteando ramas enteras:
  140. [x,y,z] = sphere;
  141. % clc
  142. i_x = 2; % Columna de la rejilla
  143. i_y = 1; % Fila de la rejilla
  144. i_z = 2; % Corte
  145. ind_CORTE = find(~cellfun(@isempty, Cortes_XY_Axon{i_z, 1}));
  146. colores = {'r', 'b', 'm', 'k', 'g'};
  147. figure('color', 'w', 'position', [250, 200, 700, 600]);
  148. hold on
  149. % for iii = 1:length(Cortes_XY_Axon{i_z, 1})
  150. for iii = ind_CORTE
  151. if ~isempty( Cortes_XY_Axon{i_z, 1}{1, iii} )
  152. dummy = Cortes_XY_Axon{i_z, 1}{1, iii};
  153. for i_fila = 1:size(dummy, 1)
  154. for i_columna = 1:size(dummy, 2)
  155. if ~isempty(dummy{i_fila, i_columna})
  156. Puntos_Axon = dummy{i_fila, i_columna};
  157. plot3( Puntos_Axon(:, 1), Puntos_Axon(:, 2), Puntos_Axon(:, 3), '-', 'color', colores{mod(i, 5)+1}, 'markersize', 7, 'linewidth', 1.5 );
  158. end
  159. end
  160. end
  161. end
  162. axis equal
  163. view([32, 20]);
  164. end
  165. surf( rad_sonda*x + Columnas_Centros(i_x), rad_sonda*y + Filas_Centros(i_y), rad_sonda*z + Z_Centros(i_z) );
  166. alpha 0.7
  167. xlabel('X');
  168. ylabel('Y');
  169. zlabel('Z');
  170. % xlim([Columnas_Rejilla(i_x), Columnas_Rejilla(i_x) + Rejilla_X]);
  171. % ylim([Filas_Rejilla(i_y), Filas_Rejilla(i_y) + Rejilla_Y]);
  172. % zlim([Cortes(i_z), Cortes(i_z) + Grosor_Corte]);
  173. % % Para la neurona 5
  174. % xlim([-100, 100]);
  175. % ylim([-200, 0]);
  176. % zlim([-80, 60]);
  177. % % Para la neurona 4
  178. % xlim([-600, 400]);
  179. % ylim([-600, 800]);
  180. % zlim([-200, 700]);
  181. % Para la neurona 3
  182. xlim([-250, 100]);
  183. ylim([-300, 200]);
  184. zlim([-100, 80]);
  185. %%
  186. figure
  187. hold on
  188. surf(peaks(30))
  189. alpha 0.5
  190. plot3(10,10,10,'r*')
  191. hold off
  192. %%