Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CrawdadSharp/CrawPeakAnnotator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void peak_annotate(SlimCrawPeak peak)
//calls set_peak_areas onpeak member variables
set_peak_bg_subtracted_area(peak);
calc_fwhm(peak);
calc_fwfpcnt(peak);
}

int calc_len(int start_rt_idx, int stop_rt_idx) => stop_rt_idx - start_rt_idx + 1;
Expand Down Expand Up @@ -364,6 +365,52 @@ public void calc_fwhm(SlimCrawPeak peak)
peak.fwhm = rh_hm - lh_hm;
}

public void calc_fwfpcnt(SlimCrawPeak peak)
{
float[] chrom = active_chrom;
float lh_height = chrom[peak.start_rt_idx];
float rh_height = chrom[peak.stop_rt_idx];
float height = peak.raw_height - Math.Min(lh_height, rh_height);
float fpct_max = (float)(peak.raw_height - (height / 100 * 95));
int lh_pt = -1, rh_pt = -1;
float lh_hm, rh_hm;
for (int i = peak.start_rt_idx; i < peak.peak_rt_idx; i++)
{
if (chrom[i] <= fpct_max && chrom[i + 1] >= fpct_max)
{
lh_pt = i;
break;
}
}
for (int i = peak.peak_rt_idx; i < Math.Min(peak.stop_rt_idx, chrom.Length - 2); i++)
{
if (chrom[i] >= fpct_max && chrom[i + 1] <= fpct_max)
{
rh_pt = i;
break;
}
}

if (lh_pt == -1)
{
lh_hm = peak.start_rt_idx;
}
else
{
float frac_delta = (fpct_max - chrom[lh_pt]) / (chrom[lh_pt + 1] - chrom[lh_pt]);
lh_hm = lh_pt + frac_delta;
}
if (rh_pt == -1)
{
rh_hm = peak.stop_rt_idx;
}
else
{
float frac_delta = (chrom[rh_pt] - fpct_max) / (chrom[rh_pt] - chrom[rh_pt + 1]);
rh_hm = rh_pt + frac_delta;
}
peak.fwfpct = rh_hm - lh_hm;
}
public void refind_peak_peak(SlimCrawPeak peak)
{
peak.peak_rt_idx = get_peakloc_in_range(peak.start_rt_idx, peak.stop_rt_idx);
Expand Down
2 changes: 2 additions & 0 deletions CrawdadSharp/CrawdadPeak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public CrawdadPeak(SlimCrawPeak crawPeak)
BackgroundArea = Math.Max(0.0f, crawPeak.bg_area);
Fwhm = crawPeak.fwhm;
FwhmDegenerate = !crawPeak.fwhm_calculated_ok;
Fwfpct = crawPeak.fwfpct;
}

public int TimeIndex { get; }
Expand All @@ -29,6 +30,7 @@ public CrawdadPeak(SlimCrawPeak crawPeak)
public float BackgroundArea { get; }
public float Height { get; }
public float Fwhm { get; }
public float Fwfpct { get; }
public bool FwhmDegenerate { get; }

public bool IsIdentified(IEnumerable<int> idIndices)
Expand Down
28 changes: 27 additions & 1 deletion CrawdadSharp/CrawdadPeakFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,33 @@ void SetChromatogram(float[] intensities, int maxIntensityIndex, double baseline
}
FullWidthHalfMax = fwhm;

_widthDataWings = (int)(FullWidthHalfMax * 2);
int fwfpcnt = 0;
if (maxIntensityIndex != -1)
{
double fpcntHeight = (intensities[maxIntensityIndex] - baselineIntensity) / 20 + baselineIntensity;
int iBeginning = 0;
for (int i = maxIntensityIndex - 1; i >= 0; i--)
{
if (intensities[i] < fpcntHeight)
{
iBeginning = i;
break;
}
}
int len = intensities.Length;
int iTail = len - 1;
for (int i = maxIntensityIndex + 1; i < len; i++)
{
if (intensities[i] < fpcntHeight)
{
iTail = i;
break;
}
}
fwfpcnt = Math.Max(fwfpcnt, iTail - iBeginning);
}

_widthDataWings = (int)(FullWidthHalfMax * 2);

if (_widthDataWings > 0)
{
Expand Down
1 change: 1 addition & 0 deletions CrawdadSharp/SlimCrawPeak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class SlimCrawPeak
public int len;
public float fwhm;
public bool fwhm_calculated_ok;
public float fwfpct;
public float bg_area;
public float raw_area; // total area under the curve, including background
public float peak_area;
Expand Down