<commit_before>/*
 * Copyright (c) 2007-2011 by The Broad Institute, Inc. and the Massachusetts Institute of
 * Technology.  All Rights Reserved.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 *
 * THE SOFTWARE IS PROVIDED "AS IS." THE BROAD AND MIT MAKE NO REPRESENTATIONS OR
 * WARRANTES OF ANY KIND CONCERNING THE SOFTWARE, EXPRESS OR IMPLIED, INCLUDING,
 * WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER
 * OR NOT DISCOVERABLE.  IN NO EVENT SHALL THE BROAD OR MIT, OR THEIR RESPECTIVE
 * TRUSTEES, DIRECTORS, OFFICERS, EMPLOYEES, AND AFFILIATES BE LIABLE FOR ANY DAMAGES
 * OF ANY KIND, INCLUDING, WITHOUT LIMITATION, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
 * ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER
 * THE BROAD OR MIT SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT
 * SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
 */


//chr2:128,565,093-128,565,156

package org.broad.igv.vcf;

import org.apache.log4j.Logger;
import org.broad.igv.ui.UIConstants;
import org.broad.igv.ui.panel.ReferenceFrame;
import org.broad.igv.renderer.*;
import org.broad.igv.session.SessionReader;
import org.broad.igv.track.*;
import org.broad.igv.track.tribble.TribbleFeatureSource;
import org.broad.igv.ui.FontManager;
import org.broad.igv.ui.IGVMainFrame;
import org.broad.igv.ui.util.UIUtilities;
import org.broad.igv.util.ResourceLocator;
import org.broad.tribble.Feature;
import org.broad.tribble.util.variantcontext.Genotype;
import org.broad.tribble.util.variantcontext.VariantContext;
import org.broad.tribble.vcf.VCFHeader;

import javax.swing.*;
import java.awt.*;
import java.text.DecimalFormat;
import java.util.*;
import java.util.List;

/**
 * User: <NAME>
 * Date: Jul 16, 2010
 */
public class VCFTrack extends FeatureTrack {

    private static Logger log = Logger.getLogger(VCFTrack.class);

    private final int EXPANDED_GENOTYPE_HEIGHT = 15;
    private final int SQUISHED_GENOTYPE_HEIGHT = 4;

    private final int DEFAULT_ALLELE_HEIGHT = 25;
    private final int MAX_FILTER_LINES = 15;

    private VCFRenderer renderer = new VCFRenderer();

    private VCFMenu menu = new VCFMenu(this);

    int visibleHeight = 0;

    //private int genotypeBandHeight = EXPANDED_GENOTYPE_HEIGHT;
    private int alleleBandHeight = DEFAULT_ALLELE_HEIGHT;
    //private int savedBandHeight = genotypeBandHeight;

    // Samples, organized by pedigree or other grouping
    private LinkedHashMap<String, List<String>> samples;
    int groupCount;
    int sampleCount;

    private ColorMode coloring = ColorMode.ZYGOSITY;
    //private boolean hideReference = true;
    private boolean hideAncestral = false;


    private boolean hideFiltered = true;
    private boolean renderID = true;

    private static float dash[] = {4.0f, 1.0f};
    DecimalFormat numFormat = new DecimalFormat("#.###");

    // A hack, keeps track of last position drawn.  TODO -- need a proper component "model" for tracks, like a lightweight swing panel
    int top;

    private static Stroke dashedStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER, 1.0f, dash, 0.0f);
    private static final Color OFF_WHITE = new Color(150, 150, 150);


    public VCFTrack(ResourceLocator locator, TribbleFeatureSource source) {
        super(locator, source);
        VCFHeader header = (VCFHeader) source.getHeader();

        sampleCount = header.getGenotypeSamples().size();
        samples = new LinkedHashMap();
        if (UIConstants.isSigmaProject()) {
            samples.put("L Unaffected", new ArrayList());
            samples.put("AA", new ArrayList());
            samples.put("BIP", new ArrayList());
            samples.put("L", new ArrayList());
            samples.put("LA", new ArrayList());
            samples.put("OK", new ArrayList());
            for (String s : header.getGenotypeSamples()) {
                if (s.endsWith("375")) {
                    samples.get("L Unaffected").add(s);
                }
                if (s.endsWith("259") || s.endsWith("265") || s.endsWith("266")) {
                    samples.get("AA").add(s);
                }
                if (s.endsWith("701") || s.endsWith("564")) {
                    samples.get("BIP").add(s);
                }
                if (s.endsWith("352") || s.endsWith("414")) {
                    samples.get("L").add(s);
                }
                if (s.endsWith("4") || s.endsWith("8") || s.endsWith("13") || s.endsWith("15")) {
                    samples.get("LA").add(s);
                }
                if (s.endsWith("563") || s.endsWith("566")) {
                    samples.get("OK").add(s);
                }
            }
            groupCount = samples.size();

        } else {
            groupCount = 1;
            samples.put("All", new ArrayList<String>(header.getGenotypeSamples()));
        }

        int visWindow = 2500000;
        if (sampleCount > 10) {
            visWindow = Math.max(2500000, 2500000 - 100000 * (sampleCount - 10));
            this.setDisplayMode(DisplayMode.EXPANDED);
        }
        setRenderID(false);
        setVisibilityWindow(visWindow);
    }


    public int getGenotypeBandHeight() {
        switch (getDisplayMode()) {
            case SQUISHED:
                return SQUISHED_GENOTYPE_HEIGHT;
            case COLLAPSED:
                return 0;
            default:
                return EXPANDED_GENOTYPE_HEIGHT;

        }
    }

    public int getHeight() {
        if (getDisplayMode() == Track.DisplayMode.COLLAPSED) {
            return alleleBandHeight;
        } else {
            return alleleBandHeight + (sampleCount * getGenotypeBandHeight());
        }
<commit_msg>Further VCF tweaks<commit_after>/*
 * Copyright (c) 2007-2011 by The Broad Institute, Inc. and the Massachusetts Institute of
 * Technology.  All Rights Reserved.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 *
 * THE SOFTWARE IS PROVIDED "AS IS." THE BROAD AND MIT MAKE NO REPRESENTATIONS OR
 * WARRANTES OF ANY KIND CONCERNING THE SOFTWARE, EXPRESS OR IMPLIED, INCLUDING,
 * WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER
 * OR NOT DISCOVERABLE.  IN NO EVENT SHALL THE BROAD OR MIT, OR THEIR RESPECTIVE
 * TRUSTEES, DIRECTORS, OFFICERS, EMPLOYEES, AND AFFILIATES BE LIABLE FOR ANY DAMAGES
 * OF ANY KIND, INCLUDING, WITHOUT LIMITATION, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
 * ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER
 * THE BROAD OR MIT SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT
 * SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
 */


//chr2:128,565,093-128,565,156

package org.broad.igv.vcf;

import org.apache.log4j.Logger;
import org.broad.igv.ui.UIConstants;
import org.broad.igv.ui.panel.ReferenceFrame;
import org.broad.igv.renderer.*;
import org.broad.igv.session.SessionReader;
import org.broad.igv.track.*;
import org.broad.igv.track.tribble.TribbleFeatureSource;
import org.broad.igv.ui.FontManager;
import org.broad.igv.ui.IGVMainFrame;
import org.broad.igv.ui.util.UIUtilities;
import org.broad.igv.util.ResourceLocator;
import org.broad.tribble.Feature;
import org.broad.tribble.util.variantcontext.Genotype;
import org.broad.tribble.util.variantcontext.VariantContext;
import org.broad.tribble.vcf.VCFHeader;

import javax.swing.*;
import java.awt.*;
import java.text.DecimalFormat;
import java.util.*;
import java.util.List;

/**
 * User: <NAME>
 * Date: Jul 16, 2010
 */
public class VCFTrack extends FeatureTrack {

    private static Logger log = Logger.getLogger(VCFTrack.class);

    private final int EXPANDED_GENOTYPE_HEIGHT = 15;
    private final int SQUISHED_GENOTYPE_HEIGHT = 4;

    private final int DEFAULT_ALLELE_HEIGHT = 25;
    private final int MAX_FILTER_LINES = 15;

    private VCFRenderer renderer = new VCFRenderer();

    private VCFMenu menu = new VCFMenu(this);

    int visibleHeight = 0;

    //private int genotypeBandHeight = EXPANDED_GENOTYPE_HEIGHT;
    private int alleleBandHeight = DEFAULT_ALLELE_HEIGHT;
    //private int savedBandHeight = genotypeBandHeight;

    // Samples, organized by pedigree or other grouping
    private LinkedHashMap<String, List<String>> samples;
    int groupCount;
    int sampleCount;

    private ColorMode coloring = ColorMode.ZYGOSITY;
    //private boolean hideReference = true;
    private boolean hideAncestral = false;


    private boolean hideFiltered = true;
    private boolean renderID = true;

    private static float dash[] = {4.0f, 1.0f};
    DecimalFormat numFormat = new DecimalFormat("#.###");

    // A hack, keeps track of last position drawn.  TODO -- need a proper component "model" for tracks, like a lightweight swing panel
    int top;

    private static Stroke dashedStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER, 1.0f, dash, 0.0f);
    private static final Color OFF_WHITE = new Color(150, 150, 150);


    public VCFTrack(ResourceLocator locator, TribbleFeatureSource source) {
        super(locator, source);
        VCFHeader header = (VCFHeader) source.getHeader();

        Set<String> allSamples = header.getGenotypeSamples();
        samples = new LinkedHashMap();
        if (UIConstants.isSigmaProject() && locator.getPath().contains("mckd1")) {
            samples.put("L Unaffected", new ArrayList());
            samples.put("AA", new ArrayList());
            samples.put("BIP", new ArrayList());
            samples.put("L", new ArrayList());
            samples.put("LA", new ArrayList());
            samples.put("OK", new ArrayList());
            sampleCount=0;
            for (String s : header.getGenotypeSamples()) {
                if (s.endsWith("-375")) {
                    samples.get("L Unaffected").add(s);
                    sampleCount++;
                }
                if (s.endsWith("-259") || s.endsWith("-265") || s.endsWith("-266")) {
                    samples.get("AA").add(s);
                    sampleCount++;
                }
                if (s.endsWith("-701") || s.endsWith("-564")) {
                    samples.get("BIP").add(s);
                    sampleCount++;
                }
                if (s.endsWith("-352") || s.endsWith("-414")) {
                    samples.get("L").add(s);
                    sampleCount++;
                }
                if (s.endsWith("-4") || s.endsWith("-8") || s.endsWith("-13") || s.endsWith("-15")) {
                    samples.get("LA").add(s);
                    sampleCount++;
                }
                if (s.endsWith("-563") || s.endsWith("-566")) {
                    samples.get("OK").add(s);
                    sampleCount++;
                }
            }
            groupCount = samples.size();

        } else {
            groupCount = 1;
            sampleCount = allSamples.size();
            samples.put("All", new ArrayList<String>(allSamples));
        }

        int visWindow = 2500000;
        if (sampleCount > 10) {
            visWindow = Math.max(2500000, 2500000 - 100000 * (sampleCount - 10));
            this.setDisplayMode(DisplayMode.EXPANDED);
        }
        setRenderID(false);
        setVisibilityWindow(visWindow);
    }


    public int getGenotypeBandHeight() {
        switch (getDisplayMode()) {
            case SQUISHED:
                return SQUISHED_GENOTYPE_HEIGHT;
            case COLLAPSED:
                return 0;
            default:
                return EXPANDED_GENOTYPE_HEIGHT;

        }
    }

    public int getHeight() {
        if (getDisplayMode() == Track.DisplayMode.COLLAPSED) {
            return alleleBandHeight;
        } else {
            return alleleBandHeight + (groupCount-1) * 3 +  (sampleCount * getGenotypeBandHeight());
        }

{'fraction_non_alphanumeric': 0.11086583272013735, 'fraction_numerical': 0.022238574114953807, 'mean_word_length': 2.536282162474704, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '803316', 'n_tokens_mistral': 3883, 'n_tokens_neox': 3527, 'n_words': 951}