|
73 | 73 | obj.images = dictionary(); |
74 | 74 | obj.projections = dictionary(); |
75 | 75 | obj.metadata = dictionary(); |
| 76 | + obj.subtile = struct(); |
76 | 77 | obj.layers = struct(); |
77 | 78 | obj.registration = dictionary(); |
78 | 79 | obj.signal = struct(); |
79 | 80 | obj.codebook = struct(); |
80 | 81 |
|
| 82 | + obj.subtile.index = 0; |
81 | 83 | obj.layers.seq = []; |
82 | 84 | obj.layers.other = []; |
83 | 85 | obj.layers.ref = []; |
|
720 | 722 | defaultSplitIndex = [5]; |
721 | 723 | addParameter(p, 'split_index', defaultSplitIndex); |
722 | 724 |
|
| 725 | + defaultSaveScores = false; |
| 726 | + addParameter(p, 'save_scores', defaultSaveScores); |
| 727 | + |
723 | 728 | parse(p, varargin{:}); |
724 | 729 |
|
725 | 730 | fprintf('====Reads Filtration====\n'); |
726 | 731 | end_base = string(p.Results.end_base); |
727 | 732 |
|
728 | 733 | % remove reads with incorrect colors |
| 734 | + n_spots = size(obj.signal.allSpots, 1); |
729 | 735 | no_color_spots = contains(obj.signal.allSpots.color_seq, "N"); |
730 | 736 | multi_color_spots = contains(obj.signal.allSpots.color_seq, "M"); |
731 | 737 | to_keep = ~or(no_color_spots, multi_color_spots); |
|
734 | 740 | fprintf(sprintf('Number of spots were dropped because of multi-max color: %d\n', sum(multi_color_spots))); |
735 | 741 | fprintf('Comparing with codebook...\n'); |
736 | 742 | fprintf(sprintf('Number of barcode segments: %d\n', p.Results.n_barcode_segments)); |
| 743 | + obj.signal.scores = [n_spots sum(no_color_spots) sum(multi_color_spots)]; |
737 | 744 |
|
738 | 745 | if numel(end_base) > 1 |
739 | 746 | end_base_msg = strjoin(end_base, " or "); |
|
748 | 755 | obj = FilterReadsMultiSegment(obj, end_base, p.Results.split_index); |
749 | 756 | end |
750 | 757 |
|
| 758 | + if p.Results.save_scores |
| 759 | + current_fname = fullfile(obj.outputPath, "log", "rsf_scores.csv"); |
| 760 | + current_output_folder_msg = strrep(current_fname, '\', '\\'); |
| 761 | + fprintf(sprintf('Saving scores to %s\n', current_output_folder_msg)); |
| 762 | + if obj.subtile.index > 0 |
| 763 | + scores_to_save = [string(obj.fovID) string(obj.subtile.index) string(obj.signal.scores)]; |
| 764 | + else |
| 765 | + scores_to_save = [string(obj.fovID) string(obj.signal.scores)]; |
| 766 | + end |
| 767 | + |
| 768 | + if ~exist(current_fname, 'file') |
| 769 | + writematrix(scores_to_save, current_fname, 'Delimiter', ','); |
| 770 | + else |
| 771 | + writematrix(scores_to_save, current_fname, 'Delimiter', ',', 'WriteMode', 'append'); |
| 772 | + end |
| 773 | + end |
| 774 | + |
751 | 775 | % change metadata |
752 | 776 | obj.jobFinished.ReadsFiltration = true; |
753 | 777 |
|
|
847 | 871 |
|
848 | 872 | switch p.Results.signal_slot |
849 | 873 | case "goodSpots" |
850 | | - current_fname = fullfile(p.Results.output_path, sprintf("%s_goodSpots.csv", obj.fovID)); |
| 874 | + if obj.subtile.index > 0 |
| 875 | + current_fname = fullfile(obj.outputPath, "output", "subtile", obj.fovID, sprintf("subtile_goodSpots_%d.csv", obj.subtile.index)); |
| 876 | + else |
| 877 | + current_fname = fullfile(p.Results.output_path, sprintf("%s_goodSpots.csv", obj.fovID)); |
| 878 | + end |
851 | 879 | current_output_folder_msg = strrep(current_fname, '\', '\\'); |
852 | 880 | fprintf(sprintf('Saving goodSpots to %s\n', current_output_folder_msg)); |
853 | 881 | output_table = obj.signal.goodSpots(:, p.Results.field_to_keep); |
854 | 882 | writetable(output_table, current_fname); |
855 | 883 | case "allSpots" |
856 | | - current_fname = fullfile(p.Results.output_path, sprintf("%s_allSpots.csv", obj.fovID)); |
| 884 | + if obj.subtile.index > 0 |
| 885 | + current_fname = fullfile(obj.outputPath, "output", "subtile", obj.fovID, sprintf("subtile_allSpots_%d.csv", obj.subtile.index)); |
| 886 | + else |
| 887 | + current_fname = fullfile(p.Results.output_path, sprintf("%s_allSpots.csv", obj.fovID)); |
| 888 | + end |
857 | 889 | current_output_folder_msg = strrep(current_fname, '\', '\\'); |
858 | 890 | fprintf(sprintf('Saving allSpots to %s\n', current_output_folder_msg)); |
859 | 891 | output_table = obj.signal.allSpots(:, p.Results.field_to_keep); |
|
879 | 911 | defaultSave = false; |
880 | 912 | addOptional(p, 'save', defaultSave); |
881 | 913 |
|
882 | | - defaultOutputFolder = fullfile(obj.outputPath, "temp"); |
| 914 | + defaultOutputFolder = fullfile(obj.outputPath, "output"); |
883 | 915 | addOptional(p, 'output_path', defaultOutputFolder); |
884 | 916 |
|
885 | 917 | defaultRefLayer = obj.layers.ref; |
|
891 | 923 | mkdir(p.Results.output_path) |
892 | 924 | end |
893 | 925 |
|
| 926 | + current_subtile_folder = fullfile(p.Results.output_path, "subtile"); |
| 927 | + if ~exist(current_subtile_folder, 'dir') |
| 928 | + mkdir(current_subtile_folder) |
| 929 | + end |
| 930 | + |
894 | 931 | current_metadata = obj.metadata{p.Results.ref_layer}; |
895 | | - current_metadata = current_metadata{1}; |
896 | | - obj.subtile = MakeSubtileTable(current_metadata.dims, p.Results.sqrt_pieces); |
| 932 | + obj.subtile.coords = MakeSubtileTable(current_metadata.dims, p.Results.sqrt_pieces); |
897 | 933 |
|
898 | 934 | if p.Results.save |
899 | | - writetable(obj.subtile, fullfile(p.Results.output_path, sprintf("%s_subtile.csv", obj.fovID)), 'Delimiter',',', 'QuoteStrings',false); |
| 935 | + current_output_folder = fullfile(current_subtile_folder, obj.fovID); |
| 936 | + if ~exist(current_output_folder, 'dir') |
| 937 | + mkdir(current_output_folder) |
| 938 | + end |
| 939 | + % save the coords of subtiles |
| 940 | + writetable(obj.subtile.coords, fullfile(current_output_folder, "subtile_coords.csv"), 'Delimiter',',', 'QuoteStrings',false); |
| 941 | + |
| 942 | + % save the object of subtiles |
| 943 | + for i=1:size(obj.subtile.coords) |
| 944 | + tile_idx = obj.subtile.coords.t(i); |
| 945 | + start_coords_x = obj.subtile.coords.scoords_x(i); |
| 946 | + start_coords_y = obj.subtile.coords.scoords_y(i); |
| 947 | + |
| 948 | + end_coords_x = obj.subtile.coords.ecoords_x(i); |
| 949 | + end_coords_y = obj.subtile.coords.ecoords_y(i); |
| 950 | + |
| 951 | + subtile_data = obj; |
| 952 | + for l=1:length(obj.layers.seq) |
| 953 | + current_layer = obj.layers.seq{l}; |
| 954 | + subtile_data.images{current_layer} = subtile_data.images{current_layer}(start_coords_y:end_coords_y, start_coords_x:end_coords_x, :, :); |
| 955 | + end |
| 956 | + subtile_data.subtile.index = tile_idx; |
| 957 | + |
| 958 | + save(fullfile(current_output_folder, sprintf('subtile_data_%d.mat', tile_idx)), "subtile_data"); |
| 959 | + end |
| 960 | + |
900 | 961 | end |
901 | 962 |
|
902 | 963 | % change metadata |
|
0 commit comments