Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

In this page you can find the example usage for java.lang Exception getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:base.BasePlayer.FileRead.java

void readBED(File[] files) {

    try {/*  ww w  .j ava2  s.com*/

        File bedfile;
        Main.drawCanvas.loading("Loading tracks");
        int addedfiles = 0;
        for (int i = 0; i < files.length; i++) {

            bedfile = files[i];
            if (!isTrackFile(bedfile)) {
                continue;
            }
            if (!checkIndex(files[i])) {
                if (files[i].getName().endsWith(".tsv.gz") || files[i].getName().endsWith(".tsv.bgz")) {

                    Main.showError("No index file for the TSV file. Use Tools -> BED converter.", "Error");
                    continue;
                }
                if (JOptionPane.showConfirmDialog(Main.drawScroll,
                        "No index file found. Do you want to create one?", "Indexing?",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {

                    Main.drawCanvas.loadingtext = "Indexing " + files[i].getName();
                    if (files[i].getName().endsWith(".gz")) {

                        MethodLibrary.createBEDIndex(files[i]);
                    } else {
                        MethodLibrary.createBEDIndex2(files[i]);
                    }
                }
            }
            if (!checkIndex(files[i])) {

                Main.showError("Could not open file. Is the file sorted?", "Note");
                continue;
            }

            BedTrack addTrack = new BedTrack(bedfile, Main.bedCanvas.bedTrack.size());
            if (bedfile.getName().endsWith("tsv.gz") || bedfile.getName().endsWith("tsv.bgz")) {
                addTrack.getZerobased().setSelected(false);
                addTrack.iszerobased = 1;
                addTrack.getSelector().frame.setVisible(true);
            }
            Main.bedCanvas.bedTrack.add(addTrack);
            Main.bedCanvas.trackDivider.add(0.0);
            addTrack.minvalue = 0;

            if (bedfile.length() / 1048576 < Settings.settings.get("bigFile")) {
                addTrack.small = true;
                Main.bedCanvas.getBEDfeatures(addTrack, 1, Main.drawCanvas.splits.get(0).chromEnd);
            }
            if (bedfile.getName().toLowerCase().endsWith(".bedgraph")
                    || bedfile.getName().toLowerCase().endsWith(".bedgraph.gz")) {

                Main.bedCanvas.pressGraph(addTrack);
                addTrack.getSelectorButton().setVisible(true);
            } else if (bedfile.getName().toLowerCase().endsWith("bigwig")
                    || bedfile.getName().toLowerCase().endsWith("bw")) {
                addTrack.bigWig = true;
                addTrack.small = true;
                Main.bedCanvas.pressGraph(addTrack);
                addTrack.getSelectorButton().setVisible(false);
                Main.bedCanvas.getBEDfeatures(addTrack, (int) Main.drawCanvas.splits.get(0).start,
                        (int) Main.drawCanvas.splits.get(0).end);
            } else {
                setBedTrack(addTrack);
            }
            addedfiles++;
            setTable(addTrack);

        }
        Main.drawCanvas.ready("Loading tracks");
        if (Main.bedCanvas.bedTrack.size() == 0) {
            return;
        }
        if (!Main.trackPane.isVisible()) {
            Main.trackPane.setVisible(true);
            Main.varpane.setDividerSize(3);
            if (addedfiles < 5) {
                Main.varpane.setResizeWeight(addedfiles * 0.1);
                Main.trackPane.setDividerLocation(addedfiles * 0.1);
                Main.varpane.setDividerLocation(addedfiles * 0.1);
            } else {
                Main.varpane.setResizeWeight(0.8);
                Main.trackPane.setDividerLocation(0.8);
                /*Main.bedCanvas.setPreferredSize(new Dimension(Main.drawWidth, Main.bedCanvas.bedTrack.size()*30 ));
                Main.bedCanvas.bufImage = MethodLibrary.toCompatibleImage(new BufferedImage((int)Main.screenSize.getWidth(), (int)Main.bedCanvas.bedTrack.size()*30, BufferedImage.TYPE_INT_ARGB));   
                Main.bedCanvas.buf = (Graphics2D)Main.bedCanvas.bufImage.getGraphics();
                        
                Main.bedCanvas.nodeImage = MethodLibrary.toCompatibleImage(new BufferedImage((int)Main.screenSize.getWidth(), (int)Main.bedCanvas.bedTrack.size()*30, BufferedImage.TYPE_INT_ARGB));
                Main.bedCanvas.nodebuf = (Graphics2D)Main.bedCanvas.nodeImage.getGraphics();
                */
                Main.varpane.setDividerLocation(0.8);
            }
            Main.trackPane.revalidate();
            Main.varpane.revalidate();

        } else {
            Main.trackPane.setDividerLocation(Main.trackPane.getDividerLocation() + 70);
            Main.varpane.setDividerLocation(Main.varpane.getDividerLocation() + 70);
            Main.varpane.revalidate();
            Main.trackPane.revalidate();

            if (Main.controlScroll.isVisible()) {
                Main.trackPane.setDividerSize(3);
            }
        }
        Main.bedScroll.setVisible(true);
        Main.bedCanvas.setVisible(true);
        for (int i = 0; i < Main.bedCanvas.trackDivider.size(); i++) {
            Main.bedCanvas.trackDivider.set(i, ((i + 1)
                    * (Main.varpane.getDividerLocation() / (double) Main.bedCanvas.trackDivider.size())));
        }
        Main.trackPane.setDividerLocation((int) ((Main.bedCanvas.trackDivider.size())
                * (Main.varpane.getDividerLocation() / (double) Main.bedCanvas.trackDivider.size())));
    } catch (Exception e) {
        e.printStackTrace();
        ErrorLog.addError(e.getStackTrace());
    }

}

From source file:base.BasePlayer.FileRead.java

void setLevels(ReadNode node, Sample sample, Reads readClass) {
    try {//from w  w  w. j  a va 2s.c  o m

        while (node != null) {
            mundane = null;
            addNode = node.getPrev();
            found = false;
            xpos = (int) ((node.getPosition() - start) * pixel);

            for (int i = 0; i < readClass.getReads().size(); i++) {
                if (i > Settings.readDepthLimit) {
                    if (node.getNext() != null) {
                        node.getNext().setPrev(node.getPrev());
                        ;
                    }
                    if (node.getPrev() != null) {
                        node.getPrev().setNext(node.getNext());
                    }
                    mundane = null;
                    node = null;
                    //   addNode = null;
                    found = true;
                    break;
                }

                if (!node.isDiscordant()) {

                    if (node.getPosition() + node.getWidth() + 2 < readClass.getHeadAndTail().get(i)[headnode]
                            .getPosition()) {
                        if (i > 0) {

                            startY = (int) (((sample.getIndex() + 1)
                                    * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                    - ((i + 1) * (readClass.readHeight + 2))));
                            node.setRectBounds(xpos, startY, (int) (node.getWidth() * pixel),
                                    readClass.readHeight);

                            if (mundane == null) {
                                if (node.getPrev() != null) {
                                    node.getPrev().setNext(node.getNext());
                                }
                                node.getNext().setPrev(node.getPrev());
                            }

                            node.setNext(readClass.getHeadAndTail().get(i)[headnode]);
                            readClass.getHeadAndTail().get(i)[headnode].setPrev(node);
                            //node.setPrev(sample.headAndTail.get(i)[headnode].getPrev());

                            readClass.getHeadAndTail().get(i)[headnode] = node;
                            readClass.getHeadAndTail().get(i)[headnode].setPrev(null);

                        } else {

                            readClass.getHeadAndTail().get(i)[headnode] = node;

                        }

                        found = true;
                        break;

                    }
                    continue;

                } else {

                    if (node.getPosition() + node.getWidth() + 2 < readClass.getHeadAndTail().get(i)[headnode]
                            .getPosition()) {

                        if (i > 0) {

                            startY = (int) (((sample.getIndex() + 1)
                                    * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                    - ((i + 1) * (readClass.readHeight + 2))));
                            node.setRectBounds(xpos, startY, (int) (node.getWidth() * pixel),
                                    readClass.readHeight);
                            /*   if(node.getPrev()!=null) {
                                  node.getPrev().setNext(node.getNext());
                               }
                                       
                               node.getNext().setPrev(node.getPrev());
                               */
                            node.setNext(readClass.getHeadAndTail().get(i)[headnode]);

                            readClass.getHeadAndTail().get(i)[headnode].setPrev(node);
                            node.setPrev(null);
                            readClass.getHeadAndTail().get(i)[headnode] = node;
                        } else {

                            readClass.getHeadAndTail().get(i)[headnode] = node;
                        }

                        found = true;
                        break;

                    } else if (readClass.getHeadAndTail().get(i)[headnode].isDiscordant()) {

                        if (i == 0) {
                            if (node.getPrev() != null) {
                                readClass.getHeadAndTail().get(i)[headnode].setPrev(node.getPrev());
                                node.getPrev().setNext(readClass.getHeadAndTail().get(i)[headnode]);

                            }
                        }

                        continue;
                    } else {

                        mundane = readClass.getHeadAndTail().get(i)[headnode];

                        startY = (int) (((sample.getIndex() + 1) * Main.drawCanvas.drawVariables.sampleHeight
                                - Main.drawCanvas.bottom - ((i + 1) * (readClass.readHeight + 2))));
                        node.setRectBounds(xpos, startY, (int) (node.getWidth() * pixel), readClass.readHeight);
                        node.setNext(mundane.getNext());
                        if (mundane.getNext() != null) {
                            mundane.getNext().setPrev(node);
                        }
                        mundane.setNext(null);
                        mundane.setPrev(null);
                        node.setPrev(null);
                        readClass.getHeadAndTail().get(i)[headnode] = node;
                        readClass.getReads().set(i, node);
                        node = mundane;
                        found = false;
                        continue;

                    }
                }
            }
            if (!found) {

                ReadNode[] addList = new ReadNode[2];
                addList[headnode] = node;
                addList[tailnode] = node;
                readClass.getHeadAndTail().add(addList);

                if (node.getPrev() != null) {
                    node.getPrev().setNext(node.getNext());

                }
                if (node.getNext() != null) {
                    node.getNext().setPrev(node.getPrev());
                }
                node.setNext(null);
                node.setPrev(null);
                readClass.getReads().add(node);
                startY = (int) (((sample.getIndex() + 1) * Main.drawCanvas.drawVariables.sampleHeight
                        - Main.drawCanvas.bottom
                        - ((readClass.getReads().size()) * (readClass.readHeight + 2))));
                node.setRectBounds(xpos, startY, (int) (node.getWidth() * pixel), readClass.readHeight);

            }
            node = addNode;

        }

    } catch (Exception e) {
        ErrorLog.addError(e.getStackTrace());
        e.printStackTrace();
    }
    mundane = null;

}

From source file:base.BasePlayer.FileRead.java

void readSam(String chrom, Reads readClass, SAMRecord samRecordBuffer,
        java.util.ArrayList<java.util.Map.Entry<Integer, Byte>> mismatches, int level) {
    try {/*from  w w  w .  ja va2 s  . com*/

        if (readClass.getReads().isEmpty()) {

            addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom, readClass.sample,
                    splitIndex, readClass, mismatches);
            readClass.setFirstRead(addNode);
            startY = (int) (((readClass.sample.getIndex() + 1) * Main.drawCanvas.drawVariables.sampleHeight
                    - Main.drawCanvas.bottom - (readClass.readHeight + 2)));
            addNode.setRectBounds((int) ((addNode.getPosition() - start) * pixel), startY,
                    (int) (samRecordBuffer.getReadLength() * pixel), readClass.readHeight);
            readClass.getReads().add(addNode);
            ReadNode[] addList = new ReadNode[2];
            addList[headnode] = addNode;
            addList[tailnode] = addNode;
            readClass.getHeadAndTail().add(addList);
            readClass.setLastRead(addNode);

        } else {

            mundane = null;
            found = false;
            ArrayList<ReadNode> mundanes = new ArrayList<ReadNode>();
            isDiscordant = MethodLibrary.isDiscordant(samRecordBuffer, readClass.sample.getComplete());

            if (samRecordBuffer.getCigarLength() > 1) {
                if (samRecordBuffer.getCigar().getCigarElement(0).getOperator()
                        .compareTo(CigarOperator.HARD_CLIP) == 0) {
                    searchPos = samRecordBuffer.getAlignmentStart();
                } else {
                    searchPos = samRecordBuffer.getUnclippedStart();
                }
            } else {
                searchPos = samRecordBuffer.getUnclippedStart();
            }

            for (int i = level; i < readClass.getHeadAndTail().size(); i++) {
                if (i > Settings.readDepthLimit) {
                    found = true;
                    mundane = null;
                    addNode = null;
                    break;
                }
                if (mundanes.size() > 0) {
                    addNode = mundanes.get(0);
                    addNode.setNext(null);
                    addNode.setPrev(null);
                    searchPos = addNode.getPosition();
                    isDiscordant = false;

                }
                if (!isDiscordant) {
                    if (readClass.getHeadAndTail().get(i)[tailnode].getPosition()
                            + readClass.getHeadAndTail().get(i)[tailnode].getWidth() + 2 < searchPos) { //.getPosition()) {
                        try {
                            if (mundanes.size() == 0) {
                                xpos = (int) ((searchPos - start) * pixel);
                                addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                        readClass.sample, splitIndex, readClass, mismatches);
                                readClass.setLastRead(addNode);
                            } else {
                                mundanes.remove(0);
                            }

                            startY = (int) (((readClass.sample.getIndex() + 1)
                                    * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                    - ((i + 1) * (readClass.readHeight + 2))));
                            addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                    readClass.readHeight);
                            addNode.setPrev(readClass.getHeadAndTail().get(i)[tailnode]);
                            readClass.getHeadAndTail().get(i)[tailnode].setNext(addNode);
                            readClass.getHeadAndTail().get(i)[tailnode] = addNode;
                            found = true;
                            if (mundanes.size() == 0) {
                                break;
                            }

                        } catch (Exception e) {
                            ErrorLog.addError(e.getStackTrace());
                            e.printStackTrace();
                        }

                    }

                    continue;
                } else {

                    if (readClass.getHeadAndTail().get(i)[tailnode].getPosition()
                            + readClass.getHeadAndTail().get(i)[tailnode].getWidth() + 2 < searchPos) {

                        xpos = (int) ((searchPos - start) * pixel);
                        addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                readClass.sample, splitIndex, readClass, mismatches);
                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((i + 1) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);
                        addNode.setPrev(readClass.getHeadAndTail().get(i)[tailnode]);
                        readClass.getHeadAndTail().get(i)[tailnode].setNext(addNode);
                        readClass.getHeadAndTail().get(i)[tailnode] = addNode;
                        readClass.setLastRead(addNode);
                        found = true;
                        break;
                    } else if (!readClass.getHeadAndTail().get(i)[tailnode].isDiscordant()) {
                        xpos = (int) ((searchPos - start) * pixel);
                        addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                readClass.sample, splitIndex, readClass, mismatches);
                        ReadNode tempmundane = readClass.getHeadAndTail().get(i)[tailnode];
                        mundane = tempmundane;

                        while (tempmundane.getPosition() + tempmundane.getWidth() + 2 >= searchPos) {
                            mundanes.add(tempmundane);

                            mundane = tempmundane;
                            tempmundane = tempmundane.getPrev();

                            if (tempmundane == null) {
                                break;
                            }
                            if (tempmundane.isDiscordant()) {
                                break;
                            }
                        }
                        tempmundane = null;
                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((i + 1) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);

                        if (mundane.getPrev() != null) {
                            addNode.setPrev(mundane.getPrev());
                            mundane.getPrev().setNext(addNode);
                        }
                        if (readClass.getHeadAndTail().get(i)[headnode].equals(mundane)) {
                            readClass.getHeadAndTail().get(i)[headnode] = addNode;
                        }
                        readClass.getHeadAndTail().get(i)[tailnode] = addNode;
                        found = false;
                        readClass.setLastRead(addNode);

                        try {
                            readClass.getReads().set(i, addNode);
                        } catch (Exception e) {
                            System.out.println(
                                    readClass.getHeadAndTail().size() + " " + readClass.getReads().size());
                        }

                        //addNode = mundane;
                        //searchPos = addNode.getPosition();
                        //isDiscordant = false;

                        continue;
                    }

                }

            }

            if (!found) {

                if (mundanes.size() == 0) {
                    xpos = (int) ((searchPos - start) * pixel);
                    addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                            readClass.sample, splitIndex, readClass, mismatches);
                    ReadNode[] addList = new ReadNode[2];
                    addList[headnode] = addNode;
                    addList[tailnode] = addNode;
                    addNode.setPrev(null);
                    addNode.setNext(null);
                    readClass.getHeadAndTail().add(addList);
                    readClass.getReads().add(addNode);
                    readClass.setLastRead(addNode);
                    startY = (int) (((readClass.sample.getIndex() + 1)
                            * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                            - ((readClass.getReads().size()) * (readClass.readHeight + 2))));
                    addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                            readClass.readHeight);
                } else {
                    while (mundanes.size() > 0) {
                        addNode = mundanes.get(0);
                        xpos = addNode.getRect().x;

                        ReadNode[] addList = new ReadNode[2];
                        addList[headnode] = addNode;
                        addList[tailnode] = addNode;
                        addNode.setPrev(null);
                        addNode.setNext(null);
                        readClass.getHeadAndTail().add(addList);
                        readClass.getReads().add(addNode);
                        readClass.setLastRead(addNode);
                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((readClass.getReads().size()) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);
                        mundanes.remove(0);
                    }
                }
            }
        }

    } catch (Exception e) {
        ErrorLog.addError(e.getStackTrace());
        e.printStackTrace();

    }

}

From source file:base.BasePlayer.FileRead.java

public void changeChrom(String chrom) {

    try {// w  w w. ja v  a2 s. c om

        nobeds = false;
        cancelfileread = false;
        if (!search) {
            FileRead.novars = false;
        }
        try {
            Main.drawCanvas.loading("Loading annotation...");

            Main.drawCanvas.splits.get(0).setGenes(getExons(chrom));

            Main.chromDraw.updateExons = true;
            Main.chromDraw.repaint();

        } catch (Exception e) {
            ErrorLog.addError(e.getStackTrace());
            e.printStackTrace();
        }

        Main.drawCanvas.ready("Loading annotation...");
        ArrayList<BedTrack> bigs = new ArrayList<BedTrack>();
        if (Main.bedCanvas.bedTrack.size() > 0) {

            Main.drawCanvas.loading("Loading BED-files...");
            Main.bedCanvas.bedOn = true;
            boolean ison = false;
            for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
                if (Main.bedCanvas.bedTrack.get(i).intersect) {

                    ison = true;
                    break;
                }
            }
            if (!ison) {
                Main.bedCanvas.bedOn = false;
            }
            //if(search) {            

            for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {

                Main.bedCanvas.bedTrack.get(i).used = false;

                if (Main.bedCanvas.bedTrack.get(i).small
                        && Main.bedCanvas.bedTrack.get(i).getBBfileReader() == null) {

                    Main.bedCanvas.getBEDfeatures(Main.bedCanvas.bedTrack.get(i), 1,
                            Main.drawCanvas.splits.get(0).chromEnd);

                } else {
                    if (search && searchEnd - searchStart < Settings.windowSize) {
                        Main.bedCanvas.getBEDfeatures(Main.bedCanvas.bedTrack.get(i), searchStart, searchEnd);
                    } else {
                        if (Main.bedCanvas.bedTrack.get(i).small) {
                            Main.bedCanvas.getBEDfeatures(Main.bedCanvas.bedTrack.get(i), 1,
                                    Main.drawCanvas.splits.get(0).chromEnd);
                        }
                    }
                }
                if (Main.bedCanvas.bedTrack.get(i).intersect && (!Main.bedCanvas.bedTrack.get(i).small
                        || Main.bedCanvas.bedTrack.get(i).getBBfileReader() != null)) {
                    Main.bedCanvas.bedTrack.get(i).intersect = false;

                    bigs.add(Main.bedCanvas.bedTrack.get(i));
                }
                if (nobeds) {
                    Main.drawCanvas.ready("Loading BED-files...");

                    return;
                }

            }
        }

        /*   }
           else {
                      
                      
              for(int i = 0; i< Main.bedCanvas.bedTrack.size(); i++) {
                         
                 Main.bedCanvas.bedTrack.get(i).used = false;
                         
                 if(Main.bedCanvas.bedTrack.get(i).small && Main.bedCanvas.bedTrack.get(i).getBBfileReader() == null) {         
                  
          Main.bedCanvas.getBEDfeatures(Main.bedCanvas.bedTrack.get(i), 1, Main.drawCanvas.splits.get(0).chromEnd);
                              
                 }
                 else {
                  
             Main.bedCanvas.getBEDfeatures(Main.bedCanvas.bedTrack.get(i), 1, Main.drawCanvas.splits.get(0).chromEnd);
                  
                 }
                 if(Main.bedCanvas.bedTrack.get(i).intersect && (!Main.bedCanvas.bedTrack.get(i).small || Main.bedCanvas.bedTrack.get(i).getBBfileReader() != null))  {
          Main.bedCanvas.bedTrack.get(i).intersect = false;
                  
          bigs.add(Main.bedCanvas.bedTrack.get(i));
                 }
                 if(nobeds) {
          Main.drawCanvas.ready("Loading BED-files...");
                  
          return;
                 }
                         
              }
           }
           */
        //}

        Main.drawCanvas.ready("Loading BED-files...");

        if (novars) {
            Main.drawCanvas.variantsStart = 0;
            Main.drawCanvas.variantsEnd = 0;

        } else {
            changing = true;
        }

        if (Main.varsamples > 0 && !novars && !bigcalc) {
            removeNonListVariants();
            removeBedLinks();

            Main.drawCanvas.loading("Loading variants...");
            head.putNext(null);
            current = FileRead.head;
            if (FileRead.head.getPosition() > 0) {
                FileRead.head = new VarNode(0, (byte) 0, "N", 0, 0, false, (float) 0, (float) 0, null, null,
                        null, null, null);
            }
            Main.drawCanvas.current = head;
            Main.chromDraw.varnode = null;
            Main.chromDraw.vardraw = null;

            for (int i = 0; i < Main.samples; i++) {
                if (nobeds) {
                    return;
                }
                if (cancelfileread || !Main.drawCanvas.loading) {

                    cancelFileRead();
                    break;
                }
                if (Main.drawCanvas.sampleList.get(i).getTabixFile() == null
                        || Main.drawCanvas.sampleList.get(i).multipart) {
                    continue;
                }

                if (search) {

                    getVariants(chrom, FileRead.searchStart, FileRead.searchEnd,
                            Main.drawCanvas.sampleList.get(i));
                } else {

                    getVariants(chrom, 0, Main.drawCanvas.splits.get(0).chromEnd,
                            Main.drawCanvas.sampleList.get(i));
                }

            }

            annotate();

            if (Main.drawCanvas.annotationOn) {
                SampleDialog.checkAnnotation();
            }

            Main.drawCanvas.loading("Applying controls...");
            if (Control.controlData.controlsOn) {
                Control.applyControl();
            }
            Main.drawCanvas.ready("Applying controls...");
            readFiles = false;
            Main.bedCanvas.intersected = false;
            if (bigcalc) {
                Main.drawCanvas.calcClusters(FileRead.head);
            } else {
                Main.drawCanvas.calcClusters(FileRead.head);

            }

            if (Main.bedCanvas.bedOn) {

                Main.drawCanvas.loadingtext = "Annotating variants";
                int smalls = 0;
                for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
                    if (Main.bedCanvas.bedTrack.get(i).small
                            && Main.bedCanvas.bedTrack.get(i).getBBfileReader() == null) {
                        if (Main.bedCanvas.bedTrack.get(i).intersect
                                && !Main.bedCanvas.bedTrack.get(i).loading) {
                            smalls++;
                            Main.bedCanvas.annotate(Main.bedCanvas.bedTrack.get(i).getHead(),
                                    FileRead.head.getNext());
                            Main.bedCanvas.intersected = true;

                        } else if (Main.bedCanvas.bedTrack.get(i).intersect
                                && Main.bedCanvas.bedTrack.get(i).loading) {
                            Main.bedCanvas.bedTrack.get(i).waiting = true;
                        }
                    }
                    //else if(Main.bedCanvas.bedTrack.get(i).intersect) {   
                    //bigs.add(Main.bedCanvas.bedTrack.get(i));
                    /*BedCanvas.Annotator annotator = Main.bedCanvas.new Annotator(Main.bedCanvas.bedTrack.get(i));
                    annotator.annotateVars();                  
                    Main.bedCanvas.intersected = true;                  */
                    //}
                }
                if (smalls == 0) {
                    VarNode current = FileRead.head.getNext();
                    while (current != null) {

                        current.bedhit = true;
                        current = current.getNext();
                    }
                }
                for (int i = 0; i < bigs.size(); i++) {

                    bigs.get(i).intersect = true;
                    BedCanvas.Annotator annotator = Main.bedCanvas.new Annotator(bigs.get(i));
                    annotator.annotateVars();
                    Main.bedCanvas.intersected = true;
                }
                bigs.clear();
            }

            if (FileRead.bigcalc) {
                Main.drawCanvas.calcClusters(FileRead.head);
            } else {
                Main.drawCanvas.calcClusters(FileRead.head);

            }
        }

        Draw.updatevars = true;
        Main.drawCanvas.ready("Loading variants...");
        if (!Main.drawCanvas.loading) {
            Draw.calculateVars = true;
        }
        if (novars) {
            Main.drawCanvas.variantsStart = 0;
            Main.drawCanvas.variantsEnd = Main.drawCanvas.splits.get(0).chromEnd;
        }

        search = false;
        changing = false;
        current = null;
        Main.chromDraw.updateExons = true;
        Main.chromDraw.repaint();

    } catch (Exception e) {
        e.printStackTrace();
        ErrorLog.addError(e.getStackTrace());
        changing = false;
    }

    Main.drawCanvas.loadbarAll = 0;
    Main.drawCanvas.loadBarSample = 0;
    Main.drawCanvas.repaint();
}

From source file:base.BasePlayer.FileRead.java

void readSamLeft(String chrom, Reads readClass, SAMRecord samRecordBuffer,
        java.util.ArrayList<java.util.Map.Entry<Integer, Byte>> mismatches) {
    try {//  w ww .j a v a 2  s . c o  m

        mundane = null;
        found = false;

        isDiscordant = MethodLibrary.isDiscordant(samRecordBuffer, readClass.sample.getComplete());

        if (samRecordBuffer.getCigarLength() > 1) {
            if (samRecordBuffer.getCigar().getCigarElement(0).getOperator()
                    .compareTo(CigarOperator.HARD_CLIP) == 0) {
                searchPos = samRecordBuffer.getAlignmentEnd();
            } else {
                searchPos = samRecordBuffer.getUnclippedEnd();
            }
        } else {
            searchPos = samRecordBuffer.getUnclippedEnd();
        }

        for (int i = 0; i < readClass.getHeadAndTail().size(); i++) {
            if (i > Settings.readDepthLimit) {
                found = true;
                mundane = null;
                addNode = null;
                break;
            }

            if (readClass.getHeadAndTail().get(i)[headnode].getPrev() != null
                    && readClass.getHeadAndTail().get(i)[headnode].getPrev().getPosition() > searchPos) {
                ReadNode tempnode;
                while (readClass.getHeadAndTail().get(i)[headnode].getPrev() != null) {
                    tempnode = readClass.getHeadAndTail().get(i)[headnode].getPrev();
                    readClass.getHeadAndTail().get(i)[headnode] = tempnode;
                }

                tempnode = null;

            }
            if (!isDiscordant) {
                if (readClass.getHeadAndTail().get(i)[headnode].getPosition() - 2 > searchPos) {

                    if (readClass.getHeadAndTail().get(i)[headnode].getPrev() != null
                            && readClass.getHeadAndTail().get(i)[headnode].getPrev().getPosition()
                                    + readClass.getHeadAndTail().get(i)[headnode].getPrev()
                                            .getWidth() > searchPos - samRecordBuffer.getReadLength()) {
                        continue;
                    }

                    try {

                        if (mundane == null) {
                            xpos = (int) ((searchPos - start) * pixel);
                            addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                    readClass.sample, splitIndex, readClass, mismatches);

                        }

                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((i + 1) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);
                        addNode.setPrev(readClass.getHeadAndTail().get(i)[headnode].getPrev());

                        readClass.getHeadAndTail().get(i)[headnode].setPrev(addNode);
                        addNode.setNext(readClass.getHeadAndTail().get(i)[headnode]);
                        if (addNode.getPrev() != null) {
                            addNode.getPrev().setNext(addNode);
                        }

                        found = true;
                        break;

                    } catch (Exception e) {
                        ErrorLog.addError(e.getStackTrace());
                        e.printStackTrace();
                    }

                } else if (readClass.getHeadAndTail().get(i)[tailnode].getPosition()
                        + readClass.getHeadAndTail().get(i)[tailnode].getWidth() + 2 < searchPos) {

                    readSam(chrom, readClass, samRecord, mismatches, i);
                    return;
                }
                continue;
            } else {

                if (readClass.getHeadAndTail().get(i)[headnode].getPosition() - 2 > searchPos) {

                    if (readClass.getHeadAndTail().get(i)[headnode].getPrev() != null
                            && readClass.getHeadAndTail().get(i)[headnode].getPrev().getPosition()
                                    + readClass.getHeadAndTail().get(i)[headnode].getPrev()
                                            .getWidth() < searchPos - samRecordBuffer.getReadLength() - 2) {

                        xpos = (int) ((searchPos - samRecordBuffer.getReadLength() - start) * pixel);
                        addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                readClass.sample, splitIndex, readClass, mismatches);

                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((i + 1) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);
                        addNode.setPrev(readClass.getHeadAndTail().get(i)[headnode].getPrev());
                        readClass.getHeadAndTail().get(i)[headnode].setPrev(addNode);
                        addNode.setNext(readClass.getHeadAndTail().get(i)[headnode]);
                        if (addNode.getPrev() != null) {
                            addNode.getPrev().setNext(addNode);
                        }
                        //readClass.setLastRead(addNode);   
                        found = true;

                        break;
                    }

                    else if (readClass.getHeadAndTail().get(i)[headnode].getPrev() != null
                            && !readClass.getHeadAndTail().get(i)[headnode].getPrev().isDiscordant()) {

                        xpos = (int) ((searchPos - samRecordBuffer.getReadLength() - start) * pixel);
                        addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                                readClass.sample, splitIndex, readClass, mismatches);

                        mundane = readClass.getHeadAndTail().get(i)[headnode].getPrev();

                        startY = (int) (((readClass.sample.getIndex() + 1)
                                * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                                - ((i + 1) * (readClass.readHeight + 2))));
                        addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                                readClass.readHeight);

                        if (mundane.getPrev() != null) {
                            addNode.setPrev(mundane.getPrev());
                            mundane.getPrev().setNext(addNode);
                        }
                        addNode.setNext(readClass.getHeadAndTail().get(i)[headnode]);
                        readClass.getHeadAndTail().get(i)[headnode].setPrev(addNode);
                        /*if(readClass.getHeadAndTail().get(i)[headnode].equals(mundane)) {
                           readClass.getHeadAndTail().get(i)[headnode] = addNode;
                        }*/
                        //readClass.getHeadAndTail().get(i)[headnode] = addNode;
                        found = false;
                        //readClass.setLastRead(addNode);   

                        try {
                            readClass.getReads().set(i, addNode);
                        } catch (Exception e) {
                            System.out.println(
                                    readClass.getHeadAndTail().size() + " " + readClass.getReads().size());
                        }
                        addNode = mundane;
                        searchPos = addNode.getPosition() + addNode.getWidth();
                        isDiscordant = false;
                        addNode.setNext(null);
                        addNode.setPrev(null);

                        continue;
                    }

                } else if (readClass.getHeadAndTail().get(i)[tailnode].getPosition()
                        + readClass.getHeadAndTail().get(i)[tailnode].getWidth() + 2 < searchPos) {

                    readSam(chrom, readClass, samRecord, mismatches, i);
                    return;
                } else {

                    //TILANNE ETT DISCORDANTTI TULEE HEADNODEN PLLE JA HEADI PIT SIIRT YLS

                    xpos = (int) ((searchPos - samRecordBuffer.getReadLength() - start) * pixel);
                    addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom,
                            readClass.sample, splitIndex, readClass, mismatches);

                    mundane = readClass.getHeadAndTail().get(i)[headnode];
                    //mundanes.add(readClass.getHeadAndTail().get(i)[headnode]);            
                    startY = (int) (((readClass.sample.getIndex() + 1)
                            * Main.drawCanvas.drawVariables.sampleHeight - Main.drawCanvas.bottom
                            - ((i + 1) * (readClass.readHeight + 2))));
                    addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel),
                            readClass.readHeight);
                    readClass.getHeadAndTail().get(i)[headnode] = addNode;
                    if (mundane.getPrev() != null) {
                        addNode.setPrev(mundane.getPrev());
                        mundane.getPrev().setNext(addNode);
                    }
                    addNode.setNext(mundane.getNext());
                    if (mundane.getNext() != null) {
                        mundane.getNext().setPrev(addNode);
                    }
                    found = false;
                    try {
                        readClass.getReads().set(i, addNode);
                    } catch (Exception e) {
                        System.out
                                .println(readClass.getHeadAndTail().size() + " " + readClass.getReads().size());
                    }
                    addNode = mundane;
                    searchPos = addNode.getPosition() + addNode.getWidth();
                    isDiscordant = false;

                    /*if(readClass.getHeadAndTail().get(i)[headnode].equals(mundane)) {
                       readClass.getHeadAndTail().get(i)[headnode] = addNode;
                    }*/
                    //readClass.getHeadAndTail().get(i)[headnode] = addNode;

                    //readClass.setLastRead(addNode);   

                    continue;
                }

            }

        }

        if (!found) {

            if (mundane == null) {

                xpos = (int) ((searchPos - start) * pixel);
                addNode = new ReadNode(samRecordBuffer, readClass.sample.getComplete(), chrom, readClass.sample,
                        splitIndex, readClass, mismatches);
            }
            ReadNode[] addList = new ReadNode[2];
            addList[headnode] = addNode;
            addList[tailnode] = addNode;
            addNode.setPrev(null);
            addNode.setNext(null);
            readClass.getHeadAndTail().add(addList);
            readClass.getReads().add(addNode);
            //readClass.setLastRead(addNode);   
            startY = (int) (((readClass.sample.getIndex() + 1) * Main.drawCanvas.drawVariables.sampleHeight
                    - Main.drawCanvas.bottom - ((readClass.getReads().size()) * (readClass.readHeight + 2))));
            addNode.setRectBounds(xpos, startY, (int) (addNode.getWidth() * pixel), readClass.readHeight);

            /*   }
               else {
                  while( mundanes.size() > 0) {
                      
             addNode = mundanes.get(0);
             xpos = addNode.getRect().x;
                     
             ReadNode[] addList = new ReadNode[2];
             addList[headnode] = addNode;
             addList[tailnode] = addNode;
             addNode.setPrev(null);
             addNode.setNext(null);
             readClass.getHeadAndTail().add(addList);
             readClass.getReads().add(addNode);
             readClass.setLastRead(addNode);   
             startY = (int)(((readClass.sample.getIndex()+1)*Main.drawCanvas.drawVariables.sampleHeight-Main.drawCanvas.bottom-((readClass.getReads().size())*(readClass.readHeight+2))));               
             addNode.setRectBounds(xpos, startY, (int)(addNode.getWidth()*pixel), readClass.readHeight);
             mundanes.remove(0);
                  }
               }   */
        }

    } catch (Exception e) {
        ErrorLog.addError(e.getStackTrace());
        e.printStackTrace();

    }

}

From source file:base.BasePlayer.FileRead.java

void getVariants(String chrom, int start, int end, Sample sample) {
    if (sample.calledvariants) {
        Main.drawCanvas.variantsStart = start;
        Main.drawCanvas.variantsEnd = end;
        return;/*from   ww w. j  a va  2s  . c o m*/
    }
    String line;
    String[] split;
    cancelfileread = false;
    cancelvarcount = false;

    try {
        if (!(VariantHandler.hideIndels.isSelected() && VariantHandler.hideSNVs.isSelected())) {
            readFiles = true;
            Main.drawCanvas.splits.get(0).transStart = 0;
            Main.drawCanvas.variantsStart = start;
            Main.drawCanvas.variantsEnd = end;
            Main.drawCanvas.loadbarAll = (int) ((sample.getIndex() / (double) (Main.samples)) * 100);

            linecounter = 0;
            if (cancelfileread) {
                cancelFileRead();
                return;
            }
            if (sample.multipart) {
                return;
            }

            if (sample.getTabixFile() != null) {

                String searchChrom = setVCFFileStart(chrom, start, end, sample);

                boolean vcf = sample.getVCFReader() != null;

                if (vcf) {
                    try {
                        sample.getVCFReader().ready();
                    } catch (IOException ex) {
                        return;
                    }
                }

                sample.setMaxCoverage(0F);
                current = head;
                line = "";
                first = true;
                stop = false;

                while (true) {
                    if (stop) {

                        break;
                    }
                    if (cancelfileread || cancelvarcount || !Main.drawCanvas.loading) {
                        cancelFileRead();

                        break;
                    }

                    try {

                        if (vcf) {

                            line = sample.getVCFReader().readLine();

                            if (line != null && line.startsWith("#")) {
                                continue;
                            }
                        } else {
                            try {
                                line = sample.getVCFInput().readLine();
                            } catch (htsjdk.samtools.FileTruncatedException e) {
                                e.printStackTrace();

                            }

                        }
                        if (line == null) {
                            break;
                        }
                    } catch (Exception ex) {
                        Main.showError(ex.getMessage(), "Error");
                        ErrorLog.addError(ex.getStackTrace());
                        ex.printStackTrace();
                        Main.cancel();
                        changing = false;
                        break;
                    }
                    if (sample.oddchar != null) {
                        line = line.replaceAll(sample.oddchar, "");
                    }

                    split = line.split("\\t+");
                    try {
                        if (split[0].startsWith("#")) {
                            continue;
                        }

                        if (vcf && split.length > 2
                                && (Integer.parseInt(split[1]) > end || !split[0].equals(searchChrom))) {

                            break;
                        }

                    } catch (Exception e) {
                        String string = "";
                        for (int i = 0; i < split.length; i++) {
                            string += split[i] + "\t";
                        }

                        ErrorLog.addError(string);
                    }
                    if (sample.getVCFInput() != null) {
                        if (sample.getVCFInput().getFilePointer() > sample.vcfEndPos) {

                            break;
                        }
                    }
                    if (sample.multiVCF) {

                        readLineMulti(split, sample);
                    } else {

                        readLine(split, sample);

                    }
                    if (first) {
                        first = false;
                    }

                }
                if (sample.getVCFReader() != null) {
                    sample.getVCFReader().close();
                }
                Draw.updatevars = true;
                if (sample.getIndex()
                        * Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()
                                + Main.drawCanvas.drawVariables.sampleHeight) {
                    if (Main.drawCanvas.splits.get(0).viewLength < 2000000) {
                        Main.chromDraw.updateExons = true;
                        Main.chromDraw.repaint();
                    }
                }
            }
        }
    } catch (Exception exc) {
        Main.showError(exc.getMessage(), "Error");

        System.out.println(sample.getName());
        exc.printStackTrace();
        ErrorLog.addError(exc.getStackTrace());
        changing = false;
    }

}

From source file:base.BasePlayer.FileRead.java

public void readLineMulti(String[] split, Sample sample) {

    samplecount = 0;/*from   ww w  . j a va  2 s .  c o  m*/
    try {
        pos = Integer.parseInt(split[1]) - 1;
    } catch (Exception e) {
        return;
    }
    if (pos < Main.drawCanvas.variantsStart) {
        return;
    } else if (pos >= Main.drawCanvas.variantsEnd) {
        stop = true;
        return;
    }
    /*else if(sample.getVCFInput().getFilePointer() > sample.vcfEndPos) {
               
       return;
    }*/
    if (linecounter == 0
            || pos - linecounter > (Main.drawCanvas.variantsEnd - Main.drawCanvas.variantsStart) / 100) {
        Main.drawCanvas.loadBarSample = (int) (((pos - Main.drawCanvas.variantsStart)
                / (double) (Main.drawCanvas.variantsEnd - Main.drawCanvas.variantsStart)) * 100);
        Draw.updatevars = true;
        linecounter = pos;
    }

    first = true;

    while (current != null && current.getNext() != null && current.getPosition() < pos) {
        current = current.getNext();
    }
    if (current.getPosition() == pos) {
        first = false;

    }

    for (int s = 9; s < split.length; s++) {
        try {
            currentSample = Main.drawCanvas.sampleList.get(sample.getIndex() + 1 + s - 9);
            if (currentSample.removed) {

                continue;
            }

            info = split[s].split(":");
            noref = false;
            HashMap<String, Integer> infofield = new HashMap<String, Integer>();

            String[] infos = split[8].split(":");
            for (int i = 0; i < infos.length; i++) {
                infofield.put(infos[i], i);
            }

            if (infofield.containsKey("GT")) {
                gtindex = infofield.get("GT");
                if (info[gtindex].contains(".") || info[gtindex].length() < 3) {
                    continue;
                }

                if (info[gtindex].contains("|")) {

                    firstallele = Short.parseShort("" + info[gtindex].split("|")[0]);
                    secondallele = Short.parseShort("" + info[gtindex].split("|")[2]);
                } else {
                    firstallele = Short.parseShort("" + info[gtindex].split("/")[0]);
                    secondallele = Short.parseShort("" + info[gtindex].split("/")[1]);
                }

                genotype = firstallele == secondallele;

                if (genotype && firstallele == 0) {
                    continue;
                }

                if (infofield.containsKey("AD")) {
                    if (infofield.containsKey("RD")) {
                        refcalls = Integer.parseInt(info[infofield.get("RD")]);
                        altcalls = Integer.parseInt(info[infofield.get("AD")]);
                    } else {
                        try {
                            coverages = info[infofield.get("AD")].split(",");
                            calls1 = Integer.parseInt(coverages[firstallele]);
                            calls2 = Integer.parseInt(coverages[secondallele]);
                        } catch (Exception e) {
                            return;
                        }
                    }
                } else {
                    calls1 = 20;
                    calls2 = 20;
                }

                if (!genotype) {
                    if (firstallele == 0) {
                        refallele = firstallele;
                        refcalls = calls1;
                        altallele = secondallele;
                        altcalls = calls2;
                    } else if (secondallele == 0) {
                        refallele = secondallele;
                        refcalls = calls2;
                        altallele = firstallele;
                        altcalls = calls1;
                    } else {
                        noref = true;
                        refallele = firstallele;
                        refcalls = calls1;
                        altallele = secondallele;
                        altcalls = calls2;
                    }
                } else {

                    refcalls = calls1; //(short)(Short.parseShort(coverages[0]));
                    altallele = secondallele;
                    altcalls = calls2;

                }
            }

            if (!split[4].contains(",")) {
                altbase = getVariant(split[3], split[4]);

            } else if (!noref) {

                altbase = getVariant(split[3], split[4].split(",")[altallele - 1]);

            } else {
                altbase = getVariant(split[3], split[4].split(",")[altallele - 1]);
                altbase2 = getVariant(split[3], split[4].split(",")[refallele - 1]);

            }
            if (altbase.contains("*") || (altbase2 != null && altbase2.contains("*"))) {
                continue;
            }
            quality = null;
            if (split[8].contains("Q")) {
                if (infofield.containsKey("GQ") && !info[infofield.get("GQ")].equals(".")) {
                    gq = (float) Double.parseDouble(info[split[8].indexOf("GQ") / 3]);
                } else if (infofield.containsKey("BQ") && !info[infofield.get("BQ")].equals(".")) {
                    quality = (float) Double.parseDouble(info[infofield.get("BQ")]);
                } else if (split[7].contains("SSC")) {
                    quality = Float.parseFloat(split[7].substring(split[7].indexOf("SSC") + 4).split(";")[0]);
                }

            }
            if (quality == null) {
                if (split[5].matches("\\d+.?.*")) {
                    quality = (float) Double.parseDouble(split[5]);

                }
            }

            HashMap<String, Float> advancedQualities = null;

            if (VariantHandler.freeze.isSelected()) {

                if (refcalls + altcalls < VariantHandler.coverageSlider.getValue()) {

                    continue;
                }

                if (quality != null && quality < VariantHandler.qualitySlider.getValue()) {
                    continue;
                }
                if (gq != null && gq < VariantHandler.gqSlider.getValue()) {
                    continue;
                }
                if (altcalls / (double) (refcalls + altcalls) < VariantHandler.callSlider.getValue() / 100.0) {

                    continue;
                }

                if (VariantHandler.hideSNVs.isSelected() && altbase.length() == 1) {
                    continue;
                }

                if (VariantHandler.hideIndels.isSelected() && altbase.length() > 1) {
                    continue;
                }

                if (VariantHandler.rscode.isSelected() && !split[2].equals(".")) {
                    continue;
                }

            }
            if (split.length > 6) {
                if (checkAdvFilters(split[6], altbase.length() > 1)) {
                    return;
                }
            }
            if (split.length > 7) {
                advqual = checkAdvQuals(split[7], infofield, info, altbase.length() > 1);
                if (advqual == 2) {
                    return;
                }
                if (advqual == 1) {
                    continue;
                }
            }
            if (refcalls + altcalls > VariantHandler.maxCoverageSlider.getMaximum()) {
                VariantHandler.maxCoverageSlider.setMaximum(refcalls + altcalls);
                VariantHandler.maxCoverageSlider.setValue(refcalls + altcalls);
            }
            /*   if(currentSample.getMaxCoverage() < calls1+calls2) {
                  currentSample.setMaxCoverage((float)(calls1+calls2));   
               }
               */
            if (first && current.getNext() == null) {

                if (!split[2].equals(".")) {
                    current.putNext(new VarNode(pos, (byte) split[3].charAt(0), altbase, refcalls + altcalls,
                            altcalls, genotype, quality, gq, advancedQualities, split[2], currentSample,
                            current, null));
                } else {
                    current.putNext(new VarNode(pos, (byte) split[3].charAt(0), altbase, refcalls + altcalls,
                            altcalls, genotype, quality, gq, advancedQualities, null, currentSample, current,
                            null));
                }
                if (noref) {
                    if (split.length > 6) {
                        if (checkAdvFilters(split[6], altbase2.length() > 1)) {
                            return;
                        }
                    }
                    if (split.length > 7) {
                        advqual = checkAdvQuals(split[7], infofield, info, altbase2.length() > 1);
                        if (advqual == 1) {
                            current = current.getNext();
                            first = false;
                            continue;
                        }
                        if (advqual == 2) {
                            return;
                        }
                    }

                    current.getNext().addSample(altbase2, refcalls + altcalls, refcalls, genotype, quality, gq,
                            advancedQualities, currentSample);
                }

                current = current.getNext();
                first = false;

            } else if (pos == current.getPosition()) {

                current.addSample(altbase, refcalls + altcalls, altcalls, genotype, quality, gq,
                        advancedQualities, currentSample);
                if (noref) {
                    if (split.length > 6) {
                        if (checkAdvFilters(split[6], altbase2.length() > 1)) {
                            return;
                        }
                    }
                    if (split.length > 7) {
                        advqual = checkAdvQuals(split[7], infofield, info, altbase2.length() > 1);
                        if (advqual == 1) {

                            continue;
                        }
                        if (advqual == 2) {
                            return;
                        }
                    }

                    current.addSample(altbase2, refcalls + altcalls, refcalls, genotype, quality, gq,
                            advancedQualities, currentSample);
                }
                if (current.isRscode() == null && !split[2].equals(".")) {
                    current.setRscode(split[2]);
                }

            }

            else if (current.getPosition() > pos) {

                if (!split[2].equals(".")) {
                    current.getPrev()
                            .putNext(new VarNode(pos, (byte) split[3].charAt(0), altbase, refcalls + altcalls,
                                    altcalls, genotype, quality, gq, advancedQualities, split[2], currentSample,
                                    current.getPrev(), current));
                } else {
                    current.getPrev()
                            .putNext(new VarNode(pos, (byte) split[3].charAt(0), altbase, refcalls + altcalls,
                                    altcalls, genotype, quality, gq, advancedQualities, null, currentSample,
                                    current.getPrev(), current));

                }
                if (noref) {
                    if (split.length > 6) {
                        if (checkAdvFilters(split[6], altbase2.length() > 1)) {
                            return;
                        }
                        if (split.length > 7) {

                            advqual = checkAdvQuals(split[7], infofield, info, altbase2.length() > 1);
                            if (advqual == 1) {

                                continue;
                            }
                            if (advqual == 2) {
                                return;
                            }
                        }
                    }

                    current.getPrev().addSample(altbase2, refcalls + altcalls, refcalls, genotype, quality, gq,
                            advancedQualities, currentSample);
                }
                current.putPrev(current.getPrev().getNext());
                current = current.getPrev();

            }

        } catch (Exception ex) {
            ErrorLog.addError(ex.getStackTrace());
            ex.printStackTrace();
            for (int i = 0; i < split.length; i++) {
                System.out.print(split[i] + " ");
            }
            System.out.println();
            break;
        }

        if (first) {
            first = false;
        }
    }

}

From source file:base.BasePlayer.FileRead.java

static String setVCFFileStart(String chrom, int start, int end, Sample sample) {
    try {/*from ww  w  . jav  a  2 s.  com*/
        Index index = null;
        if (sample.getVCFReader() != null) {
            try {
                index = IndexFactory.loadIndex(sample.getTabixFile() + ".idx");
            } catch (Exception e) {
                index = IndexFactory.loadIndex(sample.getTabixFile() + ".tbi");
            }
        } else {
            try {
                index = new TabixIndex(new File(sample.getTabixFile() + ".tbi"));
            } catch (Exception e) {
                index = new TabixIndex(new File(sample.getTabixFile() + ".csi"));
            }
        }

        java.util.List<Block> blocks = null;

        if (index.containsChromosome(sample.vcfchr + chrom)) {
            chrom = sample.vcfchr + chrom;

            try {
                blocks = index.getBlocks(chrom, start, end);

            } catch (Exception e) {

                sample.vcfEndPos = 0;
                return "";
            }

            if (blocks.size() > 0) {

                if (sample.getVCFReader() != null) {
                    sample.setInputStream();
                    sample.getVCFReader().skip(blocks.get(0).getStartPosition());

                } else {
                    try {
                        sample.getVCFInput().seek(0);
                        sample.getVCFInput().seek(blocks.get(0).getStartPosition());
                    } catch (Exception e) {
                        ErrorLog.addError(e.getStackTrace());
                        return "";
                    }
                }

                sample.vcfEndPos = blocks.get(blocks.size() - 1).getEndPosition();

            } else {

                if (sample.getVCFReader() != null) {
                    sample.setInputStream();
                } else {
                    sample.getVCFInput().seek(0);
                }
            }

        } else {

            if (index.containsChromosome(sample.vcfchr + (Main.chromosomeDropdown.getSelectedIndex() + 1))) {
                try {
                    blocks = index.getBlocks(sample.vcfchr + (Main.chromosomeDropdown.getSelectedIndex() + 1),
                            start, end);
                } catch (Exception e) {
                    sample.vcfEndPos = 0;
                    return "";
                }

                if (blocks.size() > 0) {
                    if (sample.getVCFReader() != null) {
                        sample.setInputStream();
                        sample.getVCFReader().skip(blocks.get(0).getStartPosition());
                    } else {
                        sample.getVCFInput().seek(0);
                        sample.getVCFInput().seek(blocks.get(0).getStartPosition());
                    }
                } else {
                    if (sample.getVCFReader() != null) {
                        sample.setInputStream();
                    } else {
                        sample.getVCFInput().seek(0);
                    }
                }
                chrom = sample.vcfchr + (Main.chromosomeDropdown.getSelectedIndex() + 1);
            } else {
                sample.vcfEndPos = 0;
            }
        }

    } catch (Exception e) {
        e.printStackTrace();

    }
    return chrom;
}

From source file:base.BasePlayer.FileRead.java

private void readVCF(File[] files) {
    try {/*from   ww w. j av a2  s  .  co m*/
        if (files.length == 1 && files[0].getName().endsWith(".tbi")) {
            Main.showError("Please select vcf.gz file, not the index (.tbi)", "Error");
            return;
        }
        Main.drawCanvas.loading("Loading samples...");
        File[] addDir;
        int sampletemp = Main.samples;
        Boolean added = false;
        Sample addSample = null;
        sampleString = new StringBuffer("");

        int fileindex = -1;
        readFiles = true;
        cancelfileread = false;
        ArrayList<File> bamdirs = new ArrayList<File>();

        if (Control.controlData.controlsOn) {
            Control.dismissControls(head);
        }
        int addnumber = 0;
        for (int fi = 0; fi < files.length; fi++) {

            if (Main.cancel || !Main.drawCanvas.loading) {
                current = null;
                FileRead.head.putNext(null);
                return;
            }
            if (!files[fi].exists()) {
                continue;
            }

            addDir = null;

            if (files[fi].isDirectory()) {

                addDir = files[fi].listFiles(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().endsWith(".vcf.gz") || name.toLowerCase().endsWith(".vcf");
                    }
                });
                bamdirs.add(files[fi]);
                for (int f = 0; f < addDir.length; f++) {
                    if (cancelfileread || !Main.drawCanvas.loading) {
                        current = null;
                        FileRead.head.putNext(null);
                        return;
                    }
                    if (!checkIndex(addDir[f])) {
                        Main.putMessage("Check Tools->View log");
                        ErrorLog.addError("No index file found for " + addDir[f].getName());
                    }
                    addSample = new Sample(addDir[f].getName(), (short) Main.samples,
                            addDir[f].getCanonicalPath());
                    Main.drawCanvas.sampleList.add(addSample);
                    Main.varsamples++;
                    Main.samples++;
                    Main.drawCanvas.drawVariables.visiblesamples++;
                    checkMulti(addSample);
                    addnumber++;
                    Main.drawCanvas.loadingtext = "Loading samples... " + addnumber;

                    added = true;
                    VariantHandler.commonSlider.setMaximum(Main.varsamples);
                    VariantHandler.commonSlider.setUpperValue(Main.varsamples);
                    VariantHandler.geneSlider.setMaximum(Main.varsamples);
                    sampleString.append(addSample.getName() + ";");
                    fileindex = f;
                }

            } else {
                if (!files[fi].getName().endsWith(".vcf") && !files[fi].getName().endsWith(".vcf.gz")) {
                    continue;
                }

                if (!bamdirs.contains(files[fi].getParentFile())) {
                    bamdirs.add(files[fi].getParentFile());
                }
                File testfile = null;
                boolean testing = false;
                if (!checkIndex(files[fi])) {
                    Main.putMessage("Check Tools->View log");
                    ErrorLog.addError("No index file found for " + files[fi].getName());
                    if (JOptionPane.showConfirmDialog(Main.drawScroll,
                            "No index file found. Do you want to create one?", "Indexing?",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {

                        Main.drawCanvas.loadingtext = "Creating index for " + files[fi].getName();
                        if (files[fi].getName().endsWith(".vcf.gz")) {
                            testing = true;
                            testfile = MethodLibrary.createVCFIndex(files[fi]);
                        } else {
                            MethodLibrary.createVCFIndex2(files[fi]);
                        }
                    } else {
                        continue;
                    }
                }
                if (testing && testfile != null) {
                    files[fi] = testfile;
                }
                if (fileindex > -1) {
                    if (!files[fi].getParent().equals(files[fileindex].getParent())) {
                        //   diffPaths = true;
                    }
                }
                fileindex = fi;

                addSample = new Sample(files[fi].getName(), (short) Main.samples, files[fi].getCanonicalPath());
                Main.drawCanvas.sampleList.add(addSample);
                Main.varsamples++;
                Main.samples++;
                Main.drawCanvas.drawVariables.visiblesamples = (short) Main.samples;
                sampleString.append(addSample.getName() + ";");
                checkMulti(addSample);
                addnumber++;
                Main.drawCanvas.loadingtext = "Loading samples... " + addnumber;
                added = true;
                VariantHandler.commonSlider.setMaximum(Main.varsamples);
                VariantHandler.commonSlider.setUpperValue(Main.varsamples);
                VariantHandler.geneSlider.setMaximum(Main.varsamples);

            }
        }
        if (!added) {
            Main.drawCanvas.ready("Loading samples...");
            return;
        }
        if (bamdirs.size() > 0) {

            SearchBamFiles search = new SearchBamFiles(files, bamdirs, sampletemp);
            search.execute();
        }

        Main.drawCanvas.drawVariables.visiblesamples = (short) (Main.drawCanvas.sampleList.size());
        Main.drawCanvas.checkSampleZoom();
        Main.drawCanvas.resizeCanvas(Main.drawScroll.getViewport().getWidth(),
                Main.drawScroll.getViewport().getHeight());

        int loading = 0;
        if (!(VariantHandler.hideIndels.isSelected() && VariantHandler.hideSNVs.isSelected())) {
            Main.drawCanvas.loadingtext = "Loading variants...";
            for (int i = sampletemp; i < Main.drawCanvas.sampleList.size(); i++) {
                linecounter = 0;
                if (cancelfileread || !Main.drawCanvas.loading) {
                    cancelFileRead();
                    break;
                }

                if ((Main.drawCanvas.sampleList.get(i).getIndex() + 1)
                        * Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()
                                + Main.drawCanvas.drawVariables.sampleHeight) {
                    //   Main.drawCanvas.drawVariables.visibleend = (short)(Main.drawCanvas.sampleList.get(i).getIndex());      
                    //   Main.drawCanvas.drawVariables.visiblesamples = (short)(Main.drawCanvas.sampleList.get(i).getIndex()+1);   
                    Main.drawCanvas.checkSampleZoom();
                }
                Main.drawCanvas.loadbarAll = (int) ((loading
                        / (double) (Main.drawCanvas.sampleList.size() - sampletemp)) * 100);
                //   if(!Main.drawCanvas.sampleList.get(i).multipart) {       

                try {

                    //      vcfreader = new VCFFileReader(new File(Main.drawCanvas.sampleList.get(i).getTabixFile()));
                    /*  try {
                         tabixreader = new TabixReader(Main.drawCanvas.sampleList.get(i).getTabixFile());
                      }
                      catch(Exception ex) {
                         JOptionPane.showMessageDialog(Main.chromDraw, "Index file (tbi) not found for " +Main.drawCanvas.sampleList.get(i).getName(), "Error", JOptionPane.ERROR_MESSAGE);
                         ErrorLog.addError(ex.getStackTrace());
                         ex.printStackTrace();
                      }*/
                    //      iterator=null;   
                    if (Main.drawCanvas.sampleList.get(i).getTabixFile() == null) {
                        continue;
                    }

                    if (start > 10000 && end < Main.drawCanvas.splits.get(0).chromEnd - 10000) {

                        if (Main.drawCanvas.variantsEnd > 0) {
                            // iterator = tabixreader.query(Main.drawCanvas.sampleList.get(i).vcfchr +Main.chromosomeDropdown.getSelectedItem().toString()+":" +Main.drawCanvas.variantsStart +"-" +Main.drawCanvas.variantsEnd);
                            getVariants(Main.chromosomeDropdown.getSelectedItem().toString(),
                                    Main.drawCanvas.variantsStart, Main.drawCanvas.variantsEnd,
                                    Main.drawCanvas.sampleList.get(i));

                        } else {
                            Main.drawCanvas.variantsStart = start;
                            Main.drawCanvas.variantsEnd = end;
                            //  iterator = tabixreader.query(Main.drawCanvas.sampleList.get(i).vcfchr +Main.chromosomeDropdown.getSelectedItem().toString()+":" +Main.drawCanvas.variantsStart +"-" +Main.drawCanvas.variantsEnd);
                            getVariants(Main.chromosomeDropdown.getSelectedItem().toString(),
                                    Main.drawCanvas.variantsStart, Main.drawCanvas.variantsEnd,
                                    Main.drawCanvas.sampleList.get(i));

                        }
                    } else {
                        //  iterator = tabixreader.query(Main.drawCanvas.sampleList.get(i).vcfchr +Main.chromosomeDropdown.getSelectedItem().toString());
                        Main.drawCanvas.variantsStart = 0;
                        Main.drawCanvas.variantsEnd = Main.drawCanvas.splits.get(0).chromEnd;
                        getVariants(Main.chromosomeDropdown.getSelectedItem().toString(),
                                Main.drawCanvas.variantsStart, Main.drawCanvas.variantsEnd,
                                Main.drawCanvas.sampleList.get(i));

                    }
                } catch (Exception e) {
                    Main.showError(e.getMessage(), "Error");
                    ErrorLog.addError(e.getStackTrace());
                    e.printStackTrace();

                }

                /*
                 if(iterator == null) {
                    tabixreader = null;
                    continue;
                 }*/
                //    }
                /*      else {
                         continue;
                      }
                   line = null;
                          
                   current = head;      
                   first = true;
                         
                   while(true) {                     
                      try {
                         if(cancelfileread) {
                            cancelFileRead();
                                   
                           }
                         try {
                                    
                            line = iterator.next();
                         //   vcfline = vcfIterator.next();
                              
                            if(line == null) {
                               break;
                            }
                                    
                         //   line = vcfline.getSource();
                                    
                         }
                         catch(Exception ex) {
                            JOptionPane.showMessageDialog(Main.chromDraw, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                            Main.cancel();
                   //         tabixreader.mFp.close();
                            ex.printStackTrace();
                            break;
                         }
                                          
                                 
                         split = line.split("\\t+");      
                         if(Main.drawCanvas.sampleList.get(i).multiVCF) {
                                 
                            readLineMulti(split, Main.drawCanvas.sampleList.get(i));
                         }
                         else {
                                    
                            readLine(split, Main.drawCanvas.sampleList.get(i));   
                         //   readLine(vcfline, Main.drawCanvas.sampleList.get(i));
                         }
                         if(first) {
                            first = false;
                         }
                         }
                         catch(Exception e) {
                            e.printStackTrace();
                //               tabixreader.mFp.close();
                         }
                   }      
                //      tabixreader.mFp.close();
                   Main.drawCanvas.current = FileRead.head.getNext();
                           
                   if(Main.drawCanvas.splits.get(0).viewLength < 2000000) {
                              
                      Main.chromDraw.updateExons = true;
                      Main.chromDraw.repaint();
                   }
                   if(!Main.drawCanvas.loading) {
                      Draw.calculateVars = true;
                   }
                   Draw.updatevars = true;
                    Draw.updateReads = true;
                   Main.drawCanvas.repaint();
                   loading++;*/
            }

        }
        //Main.opensamples.setText("Add samples");
        checkSamples();
        annotate();

        readFiles = false;
        //   Main.drawCanvas.clusterCalc = true;
        if (Control.controlData.controlsOn) {
            Control.applyControl();
        }

        Main.bedCanvas.intersected = false;
        if (bigcalc) {
            Main.drawCanvas.calcClusters(FileRead.head);
        } else {
            Main.drawCanvas.calcClusters(FileRead.head, 1);
        }

        if (Main.bedCanvas.bedOn) {
            Main.drawCanvas.loadingtext = "Annotating variants";
            for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
                if (Main.bedCanvas.bedTrack.get(i).intersect && !Main.bedCanvas.bedTrack.get(i).loading) {
                    if (Main.bedCanvas.bedTrack.get(i).small) {
                        Main.bedCanvas.annotate(Main.bedCanvas.bedTrack.get(i).getHead(),
                                FileRead.head.getNext());

                    } else {
                        BedCanvas.Annotator annotator = Main.bedCanvas.new Annotator(
                                Main.bedCanvas.bedTrack.get(i));
                        annotator.annotateVars();

                    }
                } else if (Main.bedCanvas.bedTrack.get(i).intersect && Main.bedCanvas.bedTrack.get(i).loading) {
                    Main.bedCanvas.bedTrack.get(i).waiting = true;
                }
            }
            Main.bedCanvas.intersected = true;
        }

        if (bigcalc) {
            Main.drawCanvas.calcClusters(FileRead.head);
        } else {
            Main.drawCanvas.calcClusters(FileRead.head, 1);
        }
        if (Main.drawCanvas.splits.get(0).viewLength < 2000000) {

            Main.chromDraw.updateExons = true;
            Main.chromDraw.repaint();
        }
        //   Main.drawCanvas.drawVariables.visibleend = Main.samples;
        //Main.drawCanvas.drawVariables.visiblesamples = Main.samples;
        Main.drawCanvas.checkSampleZoom();
        Main.drawCanvas.current = head;
        //   Draw.updatevars = true;
        //   Main.drawCanvas.repaint();   
        current = null;
        Main.drawCanvas.ready("Loading samples...");
        Main.drawCanvas.loadbarAll = 0;
        Main.drawCanvas.loadBarSample = 0;

    } catch (Exception e) {
        e.printStackTrace();
        ErrorLog.addError(e.getStackTrace());
    }
}

From source file:base.BasePlayer.FileRead.java

void varCalcBig() {
    boolean isfreeze = VariantHandler.freeze.isSelected();
    FileRead.novars = false;/*from  w  w  w. j  av a 2 s.  c  o  m*/
    if (!VariantHandler.none.isSelected()) {
        SampleDialog.checkFiles();

        if (affected == 0) {
            Main.showError("Set at least one individual as affected. (right click sample sidebar)", "Note");
            return;
        }
    } else {
        VariantHandler.freeze.setSelected(true);
    }
    bigcalc = true;

    Draw.calculateVars = false;
    Draw.variantcalculator = true;
    int adder = Settings.windowSize, presearchpos = 1;
    clearVariantsFromGenes();
    int chromcounter = 0;
    clearVariantsFromBeds();
    if (Main.drawCanvas.clusterNodes == null) {
        Main.drawCanvas.clusterNodes = new ArrayList<ClusterNode>();

    } else {
        Main.drawCanvas.clusterNodes.clear();

    }
    for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
        if (Main.bedCanvas.bedTrack.get(i).getVarcalc().isSelected()) {
            Main.bedCanvas.bedTrack.get(i).intersect = true;
        }
    }
    Main.drawCanvas.clusterId = 1;
    VariantHandler.table.variants = 0;
    VariantHandler.stattable.variants = 0;
    VariantHandler.clusterTable.variants = 0;
    for (int i = 0; i < VariantHandler.tables.size(); i++) {
        VariantHandler.tables.get(i).variants = 0;
    }

    cancelvarcount = false;
    VariantHandler.table.genearray.clear();
    VariantHandler.table.aminoarray.clear();
    VariantHandler.table.controlarray = null;
    VariantHandler.stattable.sampleArray.clear();

    for (int i = 0; i < VariantHandler.tables.size(); i++) {
        VariantHandler.tables.get(i).bedarray = null;
        VariantHandler.tables.get(i).aminoarray = null;
        VariantHandler.tables.get(i).vararray = null;
        VariantHandler.tables.get(i).controlarray = null;
        VariantHandler.tables.get(i).variants = 0;

    }
    head.putNext(null);
    VarNode vardraw;

    Object[] addobject;

    for (int i = 0; i < Main.drawCanvas.sampleList.size(); i++) {
        if (Main.drawCanvas.sampleList.get(i).multiVCF
                || (Main.drawCanvas.sampleList.get(i).getTabixFile() == null
                        && !Main.drawCanvas.sampleList.get(i).multipart)) {
            continue;
        }
        addobject = new Object[VariantHandler.stattable.headerlengths.length];
        addobject[0] = Main.drawCanvas.sampleList.get(i);
        for (int j = 1; j < addobject.length; j++) {
            addobject[j] = 0;
        }
        Main.drawCanvas.sampleList.get(i).mutationTypes = new double[6];
        for (int j = 0; j < 6; j++) {
            Main.drawCanvas.sampleList.get(i).mutationTypes[j] = 0.0;
        }
        VariantHandler.stattable.sampleArray.add(addobject);

        Main.drawCanvas.sampleList.get(i).heterozygotes = 0;
        Main.drawCanvas.sampleList.get(i).homozygotes = 0;
        Main.drawCanvas.sampleList.get(i).varcount = 0;
        Main.drawCanvas.sampleList.get(i).indels = 0;
        Main.drawCanvas.sampleList.get(i).snvs = 0;
        Main.drawCanvas.sampleList.get(i).sitioRate = 0;
        Main.drawCanvas.sampleList.get(i).versioRate = 0;
        Main.drawCanvas.sampleList.get(i).ins = 0;
        Main.drawCanvas.sampleList.get(i).callrates = 0.0;
        Main.drawCanvas.sampleList.get(i).coding = 0;
        Main.drawCanvas.sampleList.get(i).syn = 0;
        Main.drawCanvas.sampleList.get(i).nonsyn = 0;
        Main.drawCanvas.sampleList.get(i).missense = 0;
        Main.drawCanvas.sampleList.get(i).splice = 0;
        Main.drawCanvas.sampleList.get(i).nonsense = 0;
        Main.drawCanvas.sampleList.get(i).fshift = 0;
        Main.drawCanvas.sampleList.get(i).inframe = 0;

    }
    VariantHandler.stattable.setPreferredSize(new Dimension(VariantHandler.statsScroll.getViewport().getWidth(),
            (VariantHandler.stattable.sampleArray.size() + 1) * (Main.defaultFontSize + 5) + 2));
    VariantHandler.stattable.revalidate();
    VariantHandler.stattable.repaint();
    clearVariantsFromGenes();

    if (VariantHandler.allChroms.isSelected()) {
        if (VariantHandler.allChromsfrom.isSelected()) {
            chromcounter = Main.chromosomeDropdown.getSelectedIndex();
            Main.nothread = true;
            search = true;
            searchStart = (int) Main.drawCanvas.splits.get(0).start;
            searchEnd = (int) Main.drawCanvas.splits.get(0).start + Settings.windowSize;
            Main.chromosomeDropdown.setSelectedIndex(Main.chromosomeDropdown.getSelectedIndex());
            Main.nothread = false;

            Main.drawCanvas.clusterNodes.clear();
            Main.drawCanvas.calcClusters(FileRead.head.getNext());
            vardraw = FileRead.head.getNext();
        } else if (Main.drawCanvas.splits.get(0).start > 10
                || Main.chromosomeDropdown.getSelectedIndex() != 0) {
            Main.nothread = true;
            search = true;
            Main.chromosomeDropdown.setSelectedIndex(0);
            Main.nothread = false;
            vardraw = FileRead.head.getNext();
            Main.drawCanvas.clusterNodes.clear();
            Main.drawCanvas.calcClusters(FileRead.head.getNext());

        } else {
            searchStart = 0;
            searchEnd = searchStart + Settings.windowSize;
            getVariantWindow(Main.drawCanvas.splits.get(0).chrom, searchStart, searchEnd);
            Main.drawCanvas.clusterNodes.clear();
            Main.drawCanvas.calcClusters(FileRead.head.getNext());
            vardraw = FileRead.head.getNext();
        }

    } else {

        searchStart = (int) Main.drawCanvas.splits.get(0).start;

        searchEnd = getNextIntergenic(searchStart + adder);
        if (searchEnd > (int) Main.drawCanvas.splits.get(0).end) {
            searchEnd = (int) Main.drawCanvas.splits.get(0).end;

        }

        getVariantWindow(Main.drawCanvas.splits.get(0).chrom, searchStart, searchEnd);
        vardraw = FileRead.head.getNext();
        /*   for(int i = 0 ; i < Main.bedCanvas.bedTrack.size(); i++) {
              if(Main.bedCanvas.bedTrack.get(i).getVarcalc().isSelected()) {
                 Main.bedCanvas.bedTrack.get(i).intersect = true;            
                    if(Main.bedCanvas.bedTrack.get(i).small && Main.bedCanvas.bedTrack.get(i).getBBfileReader() == null) {                  
             Main.bedCanvas.annotate(Main.bedCanvas.bedTrack.get(i).getHead());   
             Main.bedCanvas.intersected = true;         
                  
                    }
                    else {                  
                  
          BedCanvas.Annotator annotator = Main.bedCanvas.new Annotator(Main.bedCanvas.bedTrack.get(i));
          annotator.annotateVars();                  
          Main.bedCanvas.intersected = true;
                  
                    }
                 }         
           }
           */
    }
    presearchpos = searchEnd;
    lastVar = FileRead.head;

    if (VariantHandler.writetofile.isSelected()) {

        lastWriteVar = FileRead.head;
    }
    Main.drawCanvas.loadbarAll = 0;
    Main.drawCanvas.loadBarSample = 0;
    while (true) {

        if (cancelvarcount || cancelfileread || !Main.drawCanvas.loading) {
            cancelFileRead();
            nullifyVarNodes();
            vardraw = null;
            break;
        }
        if (vardraw == null) {
            if (VariantHandler.writetofile.isSelected()) {

                if (VariantHandler.geneSlider.getValue() > 1) {

                    flushVars(vardraw);

                } else {
                    clearVariantsFromGenes();
                }
                lastVar.putPrev(null);
                lastWriteVar.putPrev(null);
            }
            try {
                if (VariantHandler.commonSlider.getValue() > 1 && VariantHandler.clusterSize > 0
                        && Main.drawCanvas.clusterNodes.size() > 0) {
                    Main.drawCanvas.clusterNodes
                            .get(Main.drawCanvas.clusterNodes.size() - 1).width = Main.drawCanvas.clusterNodes
                                    .get(Main.drawCanvas.clusterNodes.size() - 1).varnodes
                                            .get(Main.drawCanvas.clusterNodes
                                                    .get(Main.drawCanvas.clusterNodes.size() - 1).varnodes
                                                            .size()
                                                    - 1)
                                            .getPosition()
                                    - Main.drawCanvas.clusterNodes
                                            .get(Main.drawCanvas.clusterNodes.size() - 1).varnodes.get(0)
                                                    .getPosition()
                                    + 1;
                    VariantHandler.clusterTable.setPreferredSize(new Dimension(
                            VariantHandler.tableScroll.getViewport().getWidth(),
                            (Main.drawCanvas.clusterNodes.size() + 1) * VariantHandler.clusterTable.rowHeight));
                    VariantHandler.clusterTable.revalidate();
                    VariantHandler.clusterTable.repaint();
                }

                for (int i = 0; i < VariantHandler.stattable.sampleArray.size(); i++) {
                    sample = (Sample) VariantHandler.stattable.sampleArray.get(i)[0];
                    VariantHandler.stattable.sampleArray.get(i)[1] = sample.varcount;
                    VariantHandler.stattable.sampleArray.get(i)[2] = sample.snvs;
                    VariantHandler.stattable.sampleArray.get(i)[3] = sample.indels;
                    VariantHandler.stattable.sampleArray.get(i)[4] = sample.ins;
                    VariantHandler.stattable.sampleArray.get(i)[5] = sample.coding;
                    VariantHandler.stattable.sampleArray.get(i)[6] = MethodLibrary
                            .round(sample.heterozygotes / (double) sample.homozygotes, 2);
                    VariantHandler.stattable.sampleArray.get(i)[7] = MethodLibrary
                            .round((int) sample.sitioRate / (double) sample.versioRate, 2);

                    for (int j = 0; j < 6; j++) {
                        VariantHandler.stattable.sampleArray.get(i)[8 + j] = MethodLibrary
                                .round(sample.mutationTypes[j] / (double) sample.snvs, 2);
                    }

                    VariantHandler.stattable.sampleArray.get(i)[14] = MethodLibrary
                            .round(sample.callrates / (double) sample.varcount, 2);
                    VariantHandler.stattable.repaint();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (VariantHandler.allChroms.isSelected() && searchEnd > Main.drawCanvas.splits.get(0).chromEnd) {

                for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
                    removeNonListBeds(Main.bedCanvas.bedTrack.get(i).getHead(),
                            Main.drawCanvas.splits.get(0).chromEnd);
                }

                if (cancelvarcount) {
                    break;
                }
                if (Main.selectedChrom < Main.chromosomeDropdown.getItemCount()) {

                    chromcounter++;
                    if (chromcounter == Main.chromosomeDropdown.getItemCount()) {
                        break;
                    }
                    if (VariantHandler.onlyAutosomes.isSelected()) {
                        if (Main.chromosomeDropdown.getItemAt(chromcounter).toString().equals("X")
                                || Main.chromosomeDropdown.getItemAt(chromcounter).toString().equals("Y")) {
                            continue;
                        }
                    }
                    //clearVariantsFromGenes();
                    Main.nothread = true;
                    //search = true;

                    Main.chromosomeDropdown.setSelectedIndex(chromcounter);
                    searchStart = 1;
                    searchEnd = adder;

                    //search = false;
                    Main.nothread = false;

                    presearchpos = searchEnd;
                    getVariantWindow(Main.drawCanvas.splits.get(0).chrom, searchStart, searchEnd);

                    Main.drawCanvas.calcClusters(FileRead.head.getNext());
                    vardraw = head.getNext();
                    FileRead.head.putNext(null);
                    if (vardraw == null) {
                        continue;
                    }

                    vardraw.putPrev(lastVar);
                    lastVar.putNext(vardraw);

                    VariantHandler.table
                            .setPreferredSize(new Dimension(VariantHandler.tableScroll.getViewport().getWidth(),
                                    VariantHandler.table.getTableSize() * VariantHandler.table.rowHeight));
                    if (VariantHandler.tabs.getSelectedIndex() == 0) {
                        VariantHandler.aminoCount.setText(VariantHandler.table.variants + " variants");
                    } else if (VariantHandler.tabs.getSelectedIndex() == 1) {
                        VariantHandler.aminoCount.setText(VariantHandler.stattable.variants + " variants");
                    } else if (VariantHandler.tabs.getSelectedIndex() == 2) {
                        VariantHandler.aminoCount.setText(VariantHandler.clusterTable.variants + " variants");
                    } else {
                        VariantHandler.aminoCount.setText(
                                VariantHandler.tables.get(VariantHandler.tabs.getSelectedIndex() - 3).variants
                                        + " variants");
                    }
                    VariantHandler.table.revalidate();
                    VariantHandler.table.repaint();

                }

            } else {

                VariantHandler.table
                        .setPreferredSize(new Dimension(VariantHandler.tableScroll.getViewport().getWidth(),
                                VariantHandler.table.getTableSize() * VariantHandler.table.rowHeight));
                if (VariantHandler.tabs.getSelectedIndex() == 0) {
                    VariantHandler.aminoCount.setText(VariantHandler.table.variants + " variants");
                } else if (VariantHandler.tabs.getSelectedIndex() == 1) {
                    VariantHandler.aminoCount.setText(VariantHandler.stattable.variants + " variants");
                } else if (VariantHandler.tabs.getSelectedIndex() == 2) {
                    VariantHandler.aminoCount.setText(VariantHandler.clusterTable.variants + " variants");
                } else {
                    VariantHandler.aminoCount.setText(
                            VariantHandler.tables.get(VariantHandler.tabs.getSelectedIndex() - 3).variants
                                    + " variants");
                }

                VariantHandler.table.revalidate();
                VariantHandler.table.repaint();

                Main.chromDraw.varnode = null;
                Main.chromDraw.vardraw = null;

                if (searchEnd >= (int) Main.drawCanvas.splits.get(0).end) {
                    break;
                }

                searchStart = presearchpos;
                searchEnd = searchStart + adder; //getNextIntergenic(presearchpos+adder);
                presearchpos = searchEnd;
                for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {
                    removeNonListBeds(Main.bedCanvas.bedTrack.get(i).getHead(), searchStart);
                }
                getVariantWindow(Main.drawCanvas.splits.get(0).chrom, searchStart, searchEnd);

                vardraw = head.getNext();
                head.putNext(null);
                if (vardraw == null) {
                    continue;
                }
                vardraw.putPrev(lastVar);
                lastVar.putNext(vardraw);
            }
        }
        try {

            if (!VariantHandler.allChroms.isSelected()) {

                if (vardraw != null && vardraw.getPosition() < Main.drawCanvas.splits.get(0).start) {
                    vardraw = vardraw.getNext();
                }
                if (vardraw == null || vardraw.getPosition() > Main.drawCanvas.splits.get(0).end) {
                    vardraw = null;
                    continue;
                }
            }

            //STATS
            /*   if(vardraw == null) {
                  continue;
               }
               */
            //   Main.drawCanvas.loadbarAll = (int)((vardraw.getPosition()/(double)(Main.drawCanvas.splits.get(0).chromEnd))*100);

            /*   coding = false;
               if(vardraw.getExons() != null) {
                  for(int e = 0; e < vardraw.getExons().size(); e++) {
                     if(vardraw.getPosition()+1 > vardraw.getExons().get(e).getTranscript().getCodingStart() && vardraw.getPosition()+1 < vardraw.getExons().get(e).getTranscript().getCodingEnd()) {
                        if(vardraw.getPosition()+1 >= vardraw.getExons().get(e).getStart()-2 && vardraw.getPosition()+1 < vardraw.getExons().get(e).getEnd()+2) {
                           coding = true;
                           break;
                        }
                     }
                             
                  }
               }
               */

            //if(!VariantHandler.vcf.isSelected()) {

            vardraw = annotateVariant(vardraw);
            /*}
            else {         
               if(VariantHandler.writetofile.isSelected()) {
                  VariantHandler.writeNodeToFile(vardraw,Main.chromosomeDropdown.getSelectedItem().toString(), output, outputgz);
               }
               else {
                  annotateVariant(vardraw);      
               }
            }
            */

            //vardraw = vardraw.getNext();

        } catch (Exception ex) {
            ErrorLog.addError(ex.getStackTrace());
            ex.printStackTrace();
        }
    }
    Draw.calculateVars = true;
    Draw.updatevars = true;
    Main.drawCanvas.repaint();
    vardraw = null;
    for (int i = 0; i < VariantHandler.tables.size(); i++) {
        VariantHandler.tables.get(i).setPreferredSize(new Dimension(
                VariantHandler.tableScroll.getViewport().getWidth(),
                (VariantHandler.tables.get(i).getTableSize() + 1) * VariantHandler.tables.get(i).rowHeight));
        VariantHandler.tables.get(i).revalidate();
        VariantHandler.tables.get(i).repaint();
    }
    VariantHandler.stattable.repaint();
    VariantHandler.table.setPreferredSize(new Dimension(VariantHandler.tableScroll.getViewport().getWidth(),
            (VariantHandler.table.getTableSize() + 1) * VariantHandler.table.rowHeight));

    if (VariantHandler.tabs.getSelectedIndex() == 0) {
        VariantHandler.aminoCount.setText(VariantHandler.table.variants + " variants");
    } else if (VariantHandler.tabs.getSelectedIndex() == 1) {
        VariantHandler.aminoCount.setText(VariantHandler.stattable.variants + " variants");
    } else if (VariantHandler.tabs.getSelectedIndex() == 2) {

        VariantHandler.aminoCount.setText(VariantHandler.clusterTable.variants + " variants");
    } else {
        VariantHandler.aminoCount.setText(
                VariantHandler.tables.get(VariantHandler.tabs.getSelectedIndex() - 3).variants + " variants");
    }
    try {
        if (output != null) {
            output.close();
        }
        if (outputgz != null) {
            for (int i = 0; i < VariantHandler.outputStrings.size(); i++) {
                outputgz.write(VariantHandler.outputStrings.get(i).getBytes());

                Feature vcf = VariantHandler.vcfCodec.decode(VariantHandler.outputStrings.get(i));
                FileRead.indexCreator.addFeature(vcf, FileRead.filepointer);
                FileRead.filepointer = outputgz.getFilePointer();

            }

            VariantHandler.outputStrings.clear();
            outputgz.flush();
            Index index = indexCreator.finalizeIndex(outputgz.getFilePointer());
            index.writeBasedOnFeatureFile(outFile);
            outputgz.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    VariantHandler.table.revalidate();
    VariantHandler.table.repaint();
    if (!isfreeze) {
        VariantHandler.freeze.setSelected(false);
    }

    Main.drawCanvas.current = FileRead.head;
    if (!Main.drawCanvas.loading) {
        Draw.calculateVars = true;
    }
    Main.drawCanvas.ready("all");
    nullifyVarNodes();
    bigcalc = false;
    Draw.variantcalculator = false;
    Main.drawCanvas.loadbarAll = 0;
    Main.drawCanvas.loadBarSample = 0;
    if (VariantHandler.allChroms.isSelected()) {
        Main.showError("Variant annotation ready!", "Note");
    }
}