Skip to content
16 changes: 16 additions & 0 deletions src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ namespace OpenMS
static std::map<std::string, double> simpleFindBestFeature(const OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType & transition_group_map,
bool useQualCutoff = false,
double qualCutoff = 0.0);

/**
* @brief Subsample a library based on a given
*
* This method is used to subsample the library intelligently in order to ensure that the subsampled compounds are distributed across RT space.
*
* @param nrBins Number of bins across RT
* @param peptidesPerBin aim number of peptides per bin, if not reached a warning is issued
*
* @return LightTargetedExperiment with the subsampled library
*/
static OpenSwath::LightTargetedExperiment subsampleLibrary(OpenSwath::LightTargetedExperiment& library,
int nrBins,
int minPeptidesPerBin);


};

} // namespace OpenMS
Expand Down
14 changes: 14 additions & 0 deletions src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathWorkflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ namespace OpenMS
bool pasef = false,
bool load_into_memory = false);

TransformationDescription performAutoRTNormalization(
OpenSwath::LightTargetedExperiment& irt_transitions,
std::vector< OpenSwath::SwathMap > & swath_maps,
TransformationDescription& im_trafo,
double min_rsq,
double min_coverage,
const Param& feature_finder_param,
ChromExtractParams& cp_irt,
const Param& irt_detection_param,
const Param& calibration_param,
Size debug_level,
bool pasef,
bool load_into_memory);

public:

/** @brief Perform retention time and m/z calibration
Expand Down
65 changes: 65 additions & 0 deletions src/openms/source/ANALYSIS/OPENSWATH/OpenSwathHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// --------------------------------------------------------------------------

#include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathHelper.h>
#include <OpenMS/MATH/STATISTICS/Histogram.h>

namespace OpenMS
{
Expand Down Expand Up @@ -187,4 +188,68 @@ namespace OpenMS
return result;
}

OpenSwath::LightTargetedExperiment OpenSwathHelper::subsampleLibrary(OpenSwath::LightTargetedExperiment& library,
int nrBins,
int peptidesPerBin)
{
std::pair<double,double> RTRange = OpenSwathHelper::estimateRTRange(library);
OPENMS_LOG_DEBUG << "Detected retention time range from " << RTRange.first << " to " << RTRange.second << std::endl;

// Sort the LightTargetedExperiment Peptide precursors by their RT
auto peptide_precursors = library.getCompounds();
std::sort(peptide_precursors.begin(), peptide_precursors.end(),
[](const OpenSwath::LightCompound& a, const OpenSwath::LightCompound& b)
{
return a.rt < b.rt;
});

std::vector<OpenSwath::LightCompound> selected_compounds;

// Create a histogram bins with the desired number of bins
Math::Histogram<> hist(RTRange.first, RTRange.second, nrBins);
for (size_t h = 0; h < hist.size(); h++)
{
OPENMS_LOG_DEBUG << "Bin " << h << " has left border of " << hist.leftBorderOfBin(h) << " and right border of " << hist.rightBorderOfBin(h) << std::endl;
}

// Take the first `minPeptidesPerBin` peptides from each bin
int i = 0; // index of the peptide precursor
for (size_t h = 0; h < hist.size(); h++)
{
int numPepsInBin = 0;
bool doneWithBin = false;
while ((numPepsInBin < peptidesPerBin) && (!doneWithBin))
{
// Check if the peptide precursor is within the bin range
OPENMS_LOG_DEBUG << "Checking peptide precursor with RT " << peptide_precursors[i].rt << " against bin with left border of " << hist.leftBorderOfBin(h) << std::endl;
if (peptide_precursors[i].rt >= hist.leftBorderOfBin(h) && peptide_precursors[i].rt < hist.rightBorderOfBin(h))
{
OPENMS_LOG_DEBUG << "Adding peptide precursor with RT " << peptide_precursors[i].rt << " to bin with left border of " << hist.leftBorderOfBin(h) << std::endl;
selected_compounds.push_back(peptide_precursors[i]);
numPepsInBin++;
i++;
}
else
{
// If we have less than the minimum number of peptides in the bin, warn the user
OPENMS_LOG_WARN << "RT Bin from " << hist.leftBorderOfBin(h) << " to " << hist.rightBorderOfBin(h) << " has only "
<< numPepsInBin << " peptides. This is less than the minumum number specified of " << peptidesPerBin << std::endl;

doneWithBin = true;
}
}

// Have the minumum number of peptides required, seek to the next bin
while (peptide_precursors[i].rt < hist.rightBorderOfBin(h))
{
i++;
}
numPepsInBin = 0;
}

OPENMS_LOG_DEBUG << "Subsampled library has " << selected_compounds.size() << " precursors" << std::endl;
return library.selectCompounds(selected_compounds);
}


}
Loading
Loading