<commit_before>package org.ms2ms.data.ms;

import com.google.common.collect.Ordering;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
import org.ms2ms.data.Binary;
import org.ms2ms.math.Histogram;
import org.ms2ms.utils.IOs;
import org.ms2ms.utils.Tools;

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

/** Representation of an individual component score in a composite scheme
 *
 * Created by yuw on 10/10/16.
 */
public class ScoreModel implements Binary
{
  public enum eType
  {
    exact("Exact"), open("Open"), all("ALL"), sim("Simulated"), y("y"), b("b"), bs("bootstrapped");

    private final String name;
    eType(String n) { this.name = n; }

    public String getName() { return name; }
  };

  private String                    mName;
  private EnumMap<eType, Histogram> mDecoys, mNorms, mBoth;
  private EnumMap<eType, Double>    mOffsets;
  private Double                    mBaseline,mCenter;
  private Integer                   mBootstrapSize=1000;
  private SortedSetMultimap<String, Double> mBootsrapped;

  public static float[] sTrypicity = {0f,0f,0f,0f,0.5f,1f,2f};

  public ScoreModel() { super(); }
  public ScoreModel(String s) { super(); mName=s; }

  public Double getBaseline()      { return mBaseline; }
  public Double getCenter()        { return mCenter; }

  public Double getOffset(eType t) { return mOffsets.get(t); }
  public String getName() { return mName; }
  public Integer getBootstrapSize() { return mBootstrapSize; }

  public int size(boolean decoy, eType t)
  {
    if ( decoy && mDecoys!=null && mDecoys.get(t)!=null && mDecoys.get(t).getData()!=null) return mDecoys.get(t).getData().size();
    if (!decoy && mNorms !=null &&  mNorms.get(t)!=null &&  mNorms.get(t).getData()!=null) return  mNorms.get(t).getData().size();
    return 0;
  }

  public Histogram get(Boolean decoy, eType t)
  {
    if (decoy==null &&          mBoth  !=null) return   mBoth.get(t);
    if (decoy!=null && decoy && mDecoys!=null) return mDecoys.get(t);
    if (decoy!=null &&!decoy && mNorms !=null) return  mNorms.get(t);
    return null;
  }
  public ScoreModel setCenter(double s) { mCenter=s; return this; }
  public ScoreModel setOffset(eType t, double s)
  {<commit_msg>move the consolidation to PsmPile<commit_after>package org.ms2ms.data.ms;

import com.google.common.collect.Ordering;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
import org.ms2ms.data.Binary;
import org.ms2ms.math.Histogram;
import org.ms2ms.utils.IOs;
import org.ms2ms.utils.Tools;

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

/** Representation of an individual component score in a composite scheme
 *
 * Created by yuw on 10/10/16.
 */
public class ScoreModel implements Binary
{
  public enum eType
  {
    exact("Exact"), open("Open"), all("ALL"), sim("Simulated"), y("y"), b("b"), bs("bootstrapped");

    private final String name;
    eType(String n) { this.name = n; }

    public String getName() { return name; }
  };

  private String                    mName;
  private EnumMap<eType, Histogram> mDecoys, mNorms, mBoth;
  private EnumMap<eType, Double>    mOffsets;
  private Double                    mBaseline,mCenter;
  private Integer                   mBootstrapSize=1000;
  private SortedSetMultimap<String, Double> mBootsrapped;

  public static float[] sTrypicity = {0f,0f,0f,0f,0.5f,1f,2f};

  // temp counts
  private int nPeaks=0;
  private double mCenterY=0d, mSigmaY=0d, mCenterB=0d, mSigmaB=0d, mNumHits=0;


  public ScoreModel() { super(); }
  public ScoreModel(String s) { super(); mName=s; }

  public Double getBaseline()      { return mBaseline; }
  public Double getCenter()        { return mCenter; }

  public Double getOffset(eType t) { return mOffsets.get(t); }
  public String getName() { return mName; }
  public Integer getBootstrapSize() { return mBootstrapSize; }

  public double getCenterY() { return mNumHits>0?mCenterY/mNumHits:0d; }
  public double getCenterB() { return mNumHits>0?mCenterB/mNumHits:0d; }
  public double getSigmaY( ) { return mNumHits>0 && mSigmaY>0?mSigmaY/mNumHits:1d; }
  public double getSigmaB( ) { return mNumHits>0 && mSigmaB>0?mSigmaB/mNumHits:1d; }

  public double getOffsetB() { return mCenterB / mSigmaB; }
  public double getOffsetY() { return mCenterY / mSigmaY; }

  public double toZvalY(double s) { return (s-mCenterY)/mSigmaY; }
  public double toZvalB(double s) { return (s-mCenterB)/mSigmaB; }

  public ScoreModel increCenterY(double s) { mCenterY+=s; return this; }
  public ScoreModel increCenterB(double s) { mCenterB+=s; return this; }
  public ScoreModel increSigmaY( double s) { mSigmaY +=s; return this; }
  public ScoreModel increSigmaB( double s) { mSigmaB +=s; return this; }

  public int size(boolean decoy, eType t)
  {
    if ( decoy && mDecoys!=null && mDecoys.get(t)!=null && mDecoys.get(t).getData()!=null) return mDecoys.get(t).getData().size();
    if (!decoy && mNorms !=null &&  mNorms.get(t)!=null &&  mNorms.get(t).getData()!=null) return  mNorms.get(t).getData().size();
    return 0;
  }

  public Histogram get(Boolean decoy, eType t)
  {
    if (decoy==null &&          mBoth  !=null) return   mBoth.get(t);
    if (decoy!=null && decoy && mDecoys!=null) return mDecoys.get(t);
    if (decoy!=null &&!decoy && mNorms !=null) return  mNorms.get(t);
    return null;
  }
  public ScoreModel setCenter(double s) { mCenter=s; return this; }
  public ScoreModel setOffset(eType t, double s)
  {
{'fraction_non_alphanumeric': 0.1347316032705297, 'fraction_numerical': 0.011375755421258443, 'mean_word_length': 3.8592400690846285, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '234105', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1935, 'n_words': 478}