Skip to content

Commit

Permalink
qvals determination
Browse files Browse the repository at this point in the history
  • Loading branch information
yuw committed Jan 29, 2017
1 parent a9d888d commit 7c7f450
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deprecated/Ms2Hit_.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ public Ms2Hit_ isIsotopeErr(Range<Integer> range, Tolerance tol)
public Integer hashcodeByYBmz()
{
int hash=0;
if (getY()!=null) hash+=getY().hashcodeByTrackMz();
if (getB()!=null) hash+=getB().hashcodeByTrackMz();
if (getY()!=null) hash+=getY().hashcodeByTrackMz(2);
if (getB()!=null) hash+=getB().hashcodeByTrackMz(2);

return hash;
}
Expand Down
20 changes: 20 additions & 0 deletions src/org/ms2ms/algo/Spectra.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Range;
import org.expasy.mzjava.core.io.ms.spectrum.MgfWriter;
import org.expasy.mzjava.core.ms.Tolerance;
import org.expasy.mzjava.core.ms.peaklist.*;
import org.expasy.mzjava.core.ms.spectrum.MsnSpectrum;
import org.expasy.mzjava.core.ms.spectrum.RetentionTime;
import org.expasy.mzjava.core.ms.spectrum.RetentionTimeList;
import org.ms2ms.data.ms.IsoEnvelope;
import org.ms2ms.data.ms.OffsetPpmTolerance;
import org.ms2ms.io.MsReaders;
import org.ms2ms.math.Histogram;
import org.ms2ms.math.Stats;
import org.ms2ms.mzjava.AnnotatedPeak;
import org.ms2ms.mzjava.IsotopePeakAnnotation;
import org.ms2ms.utils.Strs;
import org.ms2ms.utils.Tools;

import java.io.IOException;
import java.util.*;

/**
Expand Down Expand Up @@ -801,4 +804,21 @@ public static MsnSpectrum purgeC13(MsnSpectrum ms)
}
return ms;
}
// -2.3,2.9
public static MsnSpectrum setIsolationComment(MsnSpectrum ms, double left, double right, MsnSpectrum ms10, MsnSpectrum ms11)
{
// parse the isolated m/z. It maybe different from the precursor m/z
String[] strs = ms.getComment().split("@")[0].split(" ");
double center = (Tools.isSet(strs)? Stats.toDouble(strs[strs.length-1]):ms.getPrecursor().getMz());

// save the precursor isolation region
String isolation = "isolation/"+ms10.getScanNumbers().getFirst().getValue()+"/"+center+
(ms11!=null?("/"+ms11.getScanNumbers().getFirst().getValue()):""),
line = MsReaders.Peaks2Str(Peaks.isolate(ms10, center+left, center+right)) +
(ms11!=null?(","+MsReaders.Peaks2Str(Peaks.isolate(ms11, center+left, center+right))):"");

if (Strs.isSet(line)) ms.setComment(isolation+","+line);

return ms;
}
}
14 changes: 11 additions & 3 deletions src/org/ms2ms/data/ms/FpmEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,23 @@ public int hashcodeByTrack()

return hash;
}
public int hashcodeByTrackMz()
public int hashcodeByTrackMz(int precision)
{
int hash=0;
int hash=0; double multi = Math.pow(10d, precision);
if (Tools.isSet(getTrack()))
for (int i=0; i<getTrack().size(); i++)
hash+=getTrack().get(i).getMz()*1000;
// grab the obs m/z rather than the ppm
hash+=Math.round(getTrack().get(i).getIntensity()*multi);

return hash;
}
public Collection<Double> fillMz(Collection<Double> data)
{
if (Tools.isSet(getTrack()))
for (AnnotatedPeak p : getTrack()) data.add(p.getIntensity());

return data;
}
@Override
public FpmEntry clone()
{
Expand Down
7 changes: 6 additions & 1 deletion src/org/ms2ms/data/ms/OffsetPpmTolerance.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class OffsetPpmTolerance extends PpmTolerance
{
private double mScale=1d, mOffset=0d, mTol=0d, mTransitionMass=0, mOffsetSlope=0, mTolSlope=0, mZval=0;
private boolean mIsIncremental=false;

public OffsetPpmTolerance() { super(0d); }
public OffsetPpmTolerance(double tol) { super(tol); mTol=tol; }
Expand All @@ -17,6 +18,9 @@ public OffsetPpmTolerance(double tol, double offset)
super(tol); mOffset=offset; mTol=tol;
}

public OffsetPpmTolerance isIncremental(boolean s) { mIsIncremental=s; return this; }
public boolean isIncremental() { return mIsIncremental; }

public OffsetPpmTolerance setOffsetParams(double transition, double intercept, double slope)
{
mTransitionMass=transition; mOffsetSlope=slope; mOffset=intercept; return this;
Expand All @@ -33,6 +37,7 @@ public double getOffset(double m)
}
// 2-sigma to cover the 95% interval
public double getPpmTol(double m) { return mTolSlope!=0?Math.exp(mTol+mTolSlope*m)*mZval*mScale : (mTol*mScale); }
public double getPpmTol() { return mTol; }

public OffsetPpmTolerance scale( double s) { mScale =s; return this; }
public OffsetPpmTolerance offset(double s) { mOffset=s; return this; }
Expand Down Expand Up @@ -60,7 +65,7 @@ public Location check(double expected, double actual)

public OffsetPpmTolerance clone()
{
return new OffsetPpmTolerance().setOffsetParams(mTransitionMass, mOffset, mOffsetSlope).setTolParams(mTol, mTolSlope, 3d);
return new OffsetPpmTolerance().setOffsetParams(mTransitionMass, mOffset, mOffsetSlope).setTolParams(mTol, mTolSlope, mZval).isIncremental(mIsIncremental);
}
private double calcError( double expectedMass) { return expectedMass * (getPpmTol(expectedMass)/1000000d); }
private double calcOffset(double expectedMass) { return expectedMass * (getOffset(expectedMass)/1000000d); }
Expand Down
3 changes: 2 additions & 1 deletion src/org/ms2ms/data/ms/ProteinID.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ProteinID implements Comparable<ProteinID>

public Double getBestQVal() { return mBestQVal; }
public String getSequence() { return mSequence; }
public String getAccession() { return mAccessionId; }
public Multimap<String, PeptideMatch> getSeqMatch() { return mSeqMatch; }

public ProteinID updateBestQVal(Double s) { if (mBestQVal==null || (s!=null && mBestQVal>s)) mBestQVal=s; return this; }
Expand Down Expand Up @@ -69,7 +70,7 @@ public static TreeMultimap<Float, ProteinID> toAbundanceRanks(Collection<Protein
if (Tools.isSet(protein.getSeqMatch()) && protein.getSequence()!=null)
{
// Float abund = (float )protein.getSeqMatch().values().size() / (float )protein.getSequence().length();
Float abund = (float )protein.getSeqMatch().values().size();
Float abund = (float )protein.getSeqMatch().keySet().size();
peptide_protein.put(abund, protein);
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/ms2ms/io/CustomFastaProteinReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public CustomFastaProteinReader(File file) throws FileNotFoundException
protected void parseHeader(String header, Protein.Builder builder)
{
int left = header.indexOf('>')+1, right = header.indexOf(' ');
builder.setAccessionId((right>0?header.substring(left, right):header.substring(left)).replaceAll("\\|", "_"));
// builder.setAccessionId((right>0?header.substring(left, right):header.substring(left)).replaceAll("\\|", "_"));
builder.setAccessionId(header.substring(left).replaceAll("\\|", "_"));
}
}

0 comments on commit 7c7f450

Please sign in to comment.