Пример #1
0
 public static int getImageMinWidth2(Context context) {
   if (mScreenWidth <= 0) {
     mScreenWidth =
         DensityUtil.getImageWeidth(context, 1.0F) - DensityUtil.getDisplayMetrics(context, 40F);
     mScreenWidth = mScreenWidth / 4;
   }
   return mScreenWidth;
 }
Пример #2
0
  static void calculateEigenvector(String file, String chr, int binsize) throws IOException {
    if (!file.endsWith("hic")) {
      System.err.println("Only 'hic' files are supported");
      System.exit(-1);
    }
    // Load the expected density function, if it exists.
    Map<Integer, DensityFunction> zoomToDensityMap = null;
    String densityFile = file + ".densities";
    if (FileUtils.resourceExists(densityFile)) {
      InputStream is = null;
      try {
        is = ParsingUtils.openInputStream(densityFile);
        zoomToDensityMap = DensityUtil.readDensities(is);

      } finally {
        if (is != null) is.close();
      }
    } else {
      System.err.println("Densities file doesn't exist");
      System.exit(-1);
    }

    SeekableStream ss = IGVSeekableStreamFactory.getStreamFor(file);
    Dataset dataset = (new DatasetReader(ss)).read();
    Chromosome[] tmp = dataset.getChromosomes();

    Map<String, Chromosome> chromosomeMap = new HashMap<String, Chromosome>();
    for (Chromosome c : tmp) {
      chromosomeMap.put(c.getName(), c);
    }

    if (!chromosomeMap.containsKey(chr)) {
      System.err.println("Unknown chromosome: " + chr);
      System.exit(-1);
    }
    int zoomIdx = 0;
    boolean found = false;
    for (; zoomIdx < HiCGlobals.zoomBinSizes.length; zoomIdx++) {
      if (HiCGlobals.zoomBinSizes[zoomIdx] == binsize) {
        found = true;
        break;
      }
    }

    if (!found) {
      System.err.println("Unknown bin size: " + binsize);
      System.exit(-1);
    }

    Matrix matrix = dataset.getMatrix(chromosomeMap.get(chr), chromosomeMap.get(chr));
    MatrixZoomData zd = matrix.getObservedMatrix(zoomIdx);
    final DensityFunction df = zoomToDensityMap.get(zd.getZoom());
    double[] eigenvector = zd.computeEigenvector(df, 0);
    for (double ev : eigenvector) System.out.print(ev + " ");
    System.out.println();
  }
Пример #3
0
 /**
  * 获取圆角位图的方法
  *
  * @param bitmap 需要转化成圆角的位图
  * @param pixels 圆角的度数,数值越大,圆角越大
  * @return 处理后的圆角位图
  */
 public static Bitmap toRoundCorner(Context context, Bitmap bitmap, int pixels) {
   Bitmap newbmp =
       ThumbnailUtils.extractThumbnail(
           bitmap,
           DensityUtil.dip2px(context, 60),
           DensityUtil.dip2px(context, 60),
           ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
   Bitmap output = Bitmap.createBitmap(newbmp.getWidth(), newbmp.getHeight(), Config.ARGB_8888);
   Canvas canvas = new Canvas(output);
   final int color = 0xff424242;
   final Paint paint = new Paint();
   final Rect rect = new Rect(0, 0, newbmp.getWidth(), newbmp.getWidth());
   final RectF rectF = new RectF(rect);
   final float roundPx = pixels;
   paint.setAntiAlias(true);
   canvas.drawARGB(0, 0, 0, 0);
   paint.setColor(color);
   canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
   canvas.drawBitmap(newbmp, rect, rect, paint);
   newbmp.recycle();
   return output;
 }
  private void initView() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    RelativeLayout menu = (RelativeLayout) findViewById(R.id.menu);
    int width =
        getResources().getDisplayMetrics().widthPixels - DensityUtil.dip2px(mContext, 56 - 8);
    DrawerLayout.LayoutParams params =
        (android.support.v4.widget.DrawerLayout.LayoutParams) menu.getLayoutParams();
    params.width = width;
    menu.setLayoutParams(params);
    drawerLayout.setDrawerListener(
        new DrawerLayout.DrawerListener() {
          @Override
          public void onDrawerSlide(View view, float v) {}

          @Override
          public void onDrawerOpened(View view) {
            closePopView();
            updateLockStatus();
          }

          @Override
          public void onDrawerClosed(View view) {}

          @Override
          public void onDrawerStateChanged(int i) {}
        });

    tv_lock_status = (TextView) findViewById(R.id.tv_lock_status);
    drawer_logo = (ImageView) findViewById(R.id.drawer_logo);

    actionView = (ActionView) findViewById(R.id.btn_more);
    tv_tab_box = (TextView) findViewById(R.id.tab_box);
    tv_tab_lock = (TextView) findViewById(R.id.tab_lock);

    // tab_thumb
    tab_thumb = findViewById(R.id.tab_thumb);
    RelativeLayout.LayoutParams thumbLp = (RelativeLayout.LayoutParams) tab_thumb.getLayoutParams();
    thumbLp.width = 0;
    tab_thumb.requestLayout();

    // vp_main
    vp_main = (ViewPager) findViewById(R.id.vp_main);
    mainAdapter = new MainPagerAdapter(mContext);
    vp_main.setAdapter(mainAdapter);
    vp_main.setOnPageChangeListener(new PagerListener());

    // pop
    popView = findViewById(R.id.layout_pop);
    pop_background = findViewById(R.id.pop_background);
    pop_background.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            closePopView();
          }
        });
    pop_background.setVisibility(View.INVISIBLE);

    // image info
    btn_menu = (ImageView) findViewById(R.id.btn_menu);

    // txt
    txt_drawer_version_num = (TextView) findViewById(R.id.txt_drawer_version_num);
    txt_drawer_info_reply = (TextView) findViewById(R.id.txt_drawer_info_reply);
  }
Пример #5
0
  static void dumpMatrix(String file, String chr1, String chr2, int binsize, String type)
      throws IOException {

    if (!file.endsWith("hic")) {
      System.err.println("Only 'hic' files are supported");
      System.exit(-1);
    }
    // Load the expected density function, if it exists.
    Map<Integer, DensityFunction> zoomToDensityMap = null;
    if (type.equals("oe") || type.equals("pearson")) {
      String densityFile = file + ".densities";
      if (FileUtils.resourceExists(densityFile)) {
        InputStream is = null;
        try {
          is = ParsingUtils.openInputStream(densityFile);
          zoomToDensityMap = DensityUtil.readDensities(is);

        } finally {
          if (is != null) is.close();
        }
      } else {
        System.err.println("Densities file doesn't exist, cannot calculate O/E or Pearson's");
        System.exit(-1);
      }
    }

    SeekableStream ss = IGVSeekableStreamFactory.getStreamFor(file);
    Dataset dataset = (new DatasetReader(ss)).read();
    Chromosome[] tmp = dataset.getChromosomes();

    Map<String, Chromosome> chromosomeMap = new HashMap<String, Chromosome>();
    for (Chromosome c : tmp) {
      chromosomeMap.put(c.getName(), c);
    }

    if (!chromosomeMap.containsKey(chr1)) {
      System.err.println("Unknown chromosome: " + chr1);
      System.exit(-1);
    } else if (!chromosomeMap.containsKey(chr2)) {
      System.err.println("Unknown chromosome: " + chr2);
      System.exit(-1);
    }
    if (type.equals("oe") || type.equals("pearson")) {
      if (!chr1.equals(chr2)) {
        System.err.println("Chromosome " + chr1 + " not equal to Chromosome " + chr2);
        System.err.println("Currently only intrachromosomal O/E and Pearson's are supported.");
        System.exit(-1);
      }
    }

    int zoomIdx = 0;
    boolean found = false;
    for (; zoomIdx < HiCGlobals.zoomBinSizes.length; zoomIdx++) {
      if (HiCGlobals.zoomBinSizes[zoomIdx] == binsize) {
        found = true;
        break;
      }
    }

    if (!found) {
      System.err.println("Unknown bin size: " + binsize);
    }

    Matrix matrix = dataset.getMatrix(chromosomeMap.get(chr1), chromosomeMap.get(chr2));
    MatrixZoomData zd = matrix.getObservedMatrix(zoomIdx);
    if (type.equals("oe") || type.equals("pearson")) {
      final DensityFunction df = zoomToDensityMap.get(zd.getZoom());
      if (df == null) {
        System.err.println("Densities not calculated to this resolution.");
        System.exit(-1);
      }
      zd.dumpOE(df, type.equals("oe"));
    } else zd.dump();
  }