| 180 | } |
| 181 | |
| 182 | void MSChromatogram::sortByPosition() |
| 183 | { |
| 184 | if (float_data_arrays_.empty()) |
| 185 | { |
| 186 | std::sort(ContainerType::begin(), ContainerType::end(), PeakType::PositionLess()); |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | //sort index list |
| 191 | std::vector<std::pair<PeakType::PositionType, Size> > sorted_indices; |
| 192 | sorted_indices.reserve(ContainerType::size()); |
| 193 | for (Size i = 0; i < ContainerType::size(); ++i) |
| 194 | { |
| 195 | sorted_indices.emplace_back(ContainerType::operator[](i).getPosition(), i); |
| 196 | } |
| 197 | std::sort(sorted_indices.begin(), sorted_indices.end()); |
| 198 | |
| 199 | //apply sorting to ContainerType and to metadataarrays |
| 200 | ContainerType tmp; |
| 201 | for (Size i = 0; i < sorted_indices.size(); ++i) |
| 202 | { |
| 203 | tmp.push_back(*(ContainerType::begin() + (sorted_indices[i].second))); |
| 204 | } |
| 205 | ContainerType::swap(tmp); |
| 206 | |
| 207 | for (Size i = 0; i < float_data_arrays_.size(); ++i) |
| 208 | { |
| 209 | std::vector<float> mda_tmp; |
| 210 | for (Size j = 0; j < float_data_arrays_[i].size(); ++j) |
| 211 | { |
| 212 | mda_tmp.push_back(*(float_data_arrays_[i].begin() + (sorted_indices[j].second))); |
| 213 | } |
| 214 | std::swap(float_data_arrays_[i], mda_tmp); |
| 215 | } |
| 216 | |
| 217 | for (Size i = 0; i < string_data_arrays_.size(); ++i) |
| 218 | { |
| 219 | std::vector<String> mda_tmp; |
| 220 | for (Size j = 0; j < string_data_arrays_[i].size(); ++j) |
| 221 | { |
| 222 | mda_tmp.push_back(*(string_data_arrays_[i].begin() + (sorted_indices[j].second))); |
| 223 | } |
| 224 | std::swap(string_data_arrays_[i], mda_tmp); |
| 225 | } |
| 226 | |
| 227 | for (Size i = 0; i < integer_data_arrays_.size(); ++i) |
| 228 | { |
| 229 | std::vector<Int> mda_tmp; |
| 230 | for (Size j = 0; j < integer_data_arrays_[i].size(); ++j) |
| 231 | { |
| 232 | mda_tmp.push_back(*(integer_data_arrays_[i].begin() + (sorted_indices[j].second))); |
| 233 | } |
| 234 | std::swap(integer_data_arrays_[i], mda_tmp); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | bool MSChromatogram::isSorted() const |