Package gem

Source Code of gem.ActivityPredicter3$Group

package gem;

import gem.parser.TabDelimitedFileParser;
import gem.util.Binomial;
import gem.util.GraphML;

import java.awt.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.List;

public class ActivityPredicter3 implements Constants
{
  public static final double THR = 0.05;
  private static final List<String> DW_MODS = CellLineCorrecter.dwNames_LNCaP;

  public static void main(String[] args) throws Throwable
  {
    String dir = "resource/expdata/Ling/";
    boolean[][] pos = StageAnalyzer.getPos(dir);
    List<Triplet> trips = StageAnalyzer.readTrips(dir);

    List<Group> groups = groupTriplets(trips);

    boolean[] pos1 = pos[1];
    boolean[] pos2 = pos[3];

    List<Group> rem = new ArrayList<Group>();
    for (Group g : groups)
    {
      g.calculate(pos1, pos2);
      if (g.sign == 0) rem.add(g);
    }
    groups.removeAll(rem);
    assignAndrResponse(groups);
//    filterToAndrRespTars(groups);

    int act = 0;
    int inh = 0;
    for (Group g : groups)
    {
//      if (g.andrResp == g.sign) continue;

      if (g.tarCh * g.sign == 1) act++;
      else if (g.tarCh * g.sign == -1) inh++;
      else throw new RuntimeException("something zero");
    }
    System.out.println("act = " + act);
    System.out.println("inh = " + inh);
  }


  private static Gene getGene(List<Triplet> trips, String symbol)
  {
    for (Triplet t : trips)
    {
      if (t.getMSym().equals(symbol)) return t.M;
      if (t.getFSym().equals(symbol)) return t.F;
      if (t.getTSym().equals(symbol)) return t.T;
    }
    return null;
  }

  private static List<Group> groupTriplets(List<Triplet> trips)
  {
    Map<String, Group> map = new HashMap<String, Group>();
    for (Triplet t : trips)
    {
      if (!map.containsKey(t.target))
      {
        Group g = new Group(t.T);
        map.put(t.target, g);
      }
      map.get(t.target).trips.add(t);
    }
    List<Group> groups = new ArrayList<Group>(map.values());
    return groups;
  }

  private static void filterToAndrRespTars(List<Group> groups)
  {
    TabDelimitedFileParser p = new TabDelimitedFileParser("resource/factors/AR_andr.txt");
    Set<String> tars = p.getColumnSet("Target");
    Iterator<Group> iter = groups.iterator();
    while (iter.hasNext())
    {
      Group g = iter.next();
      if (!tars.contains(g.tar)) iter.remove();
    }
  }

  public static void printExpChange(Gene gene, boolean[] pos1, boolean[] pos2)
  {
    double pv = CellTypeMatcher.getChangePvalBetweenTissues(gene, pos1, pos2);
    double mch = CellTypeMatcher.getMeanChange(gene, pos1, pos2);

    System.out.println(gene.getSymbol() + "\t" + fmt.format(mch) +
      "\t" + pv);
  }

  private static void assignAndrResponse(List<Group> groups)
  {
    TabDelimitedFileParser parser = new TabDelimitedFileParser("resource/factors/AR_andr.txt");
    Map<String, String> score = parser.getOneToOneMap("Target", "Score");

    int same = 0;
    int oppo = 0;
    for (Group g : groups)
    {
      assert score.containsKey(g.tar);

      g.andrResp = score.get(g.tar).startsWith("-") ? -1 : 1;
      if (g.andrResp == g.sign) same++; else oppo++;
    }
    System.out.println("same = " + same);
    System.out.println("oppo = " + oppo);
  }

  static class Group
  {
    String tar;
    Gene T;
    Set<Triplet> trips;
    int tarCh;

    int actCnt = 0;
    int inhCnt = 0;

    int sign;

    int andrResp;

    Group(Gene t)
    {
      T = t;
      tar = Triplet.getGeneToSymbolMap().get(T.geneid);
      trips = new HashSet<Triplet>();
    }

    void calculate(boolean[] pos1, boolean[] pos2)
    {
      double pv = CellTypeMatcher.getChangePvalBetweenTissues(T, pos1, pos2);

      if (pv < THR)
      {
        tarCh = CellTypeMatcher.getMeanChange(T, pos1, pos2) > 0 ? 1 : -1;

        for (Triplet t : trips)
        {
          double pv1 = Difference.calcAlphaFpval(t);
          double pv2 = Difference.calcBetaFpval(t);

          int s1 = pv1 < THR ? Difference.calcAlphaF(t) > 0 ? 1 : -1 : 0;
          int s2 = pv2 < THR ? Difference.calcBetaF(t) > 0 ? 1 : -1 : 0;

//          if (DW_MODS.contains(t.M.getSymbol()))
          {
            if (s1 > 0) actCnt++; else if (s1 < 0) inhCnt++;
          }
//          else
          {
            if (s2 > 0) actCnt++; else if (s2 < 0) inhCnt++;
          }
        }

        if (Math.abs(actCnt - inhCnt) > 0)
        {
          sign = actCnt > inhCnt ? 1 : -1;
        }
      }
    }

    @Override
    public String toString()
    {
      String s = tar + "\t" + sign;
//      s += "\t" + actCnt + "\t" + inhCnt + "\t" + trips.size();

      return s;
    }

  }
}
TOP

Related Classes of gem.ActivityPredicter3$Group

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.