Esempio n. 1
0
 private boolean isSequenceRecognized(final String sequence) {
   return (sequenceDictionary.getSequence(sequence) != null);
 }
Esempio n. 2
0
  @Override
  public int doWork(String[] args) {

    com.github.lindenb.jvarkit.util.cli.GetOpt opt =
        new com.github.lindenb.jvarkit.util.cli.GetOpt();
    int c;
    while ((c = opt.getopt(args, getGetOptDefault() + "k:")) != -1) {
      switch (c) {
        case 'k':
          this.ucscKnownGene = opt.getOptArg();
          break;
        default:
          {
            switch (handleOtherOptions(c, opt, null)) {
              case EXIT_FAILURE:
                return -1;
              case EXIT_SUCCESS:
                return 0;
              default:
                break;
            }
          }
      }
    }

    VcfIterator iter = null;
    BufferedReader r = null;
    try {
      if (opt.getOptInd() == args.length) {
        info("Reading from stdin");
        iter = new VcfIterator(System.in);
      } else if (opt.getOptInd() + 1 == args.length) {
        String uri = args[opt.getOptInd()];
        info("Reading from " + uri);
        iter = new VcfIterator(IOUtils.openURIForReading(uri));
      } else {
        error("Illegal number of arguments.");
        return -1;
      }
      info("Reading " + this.ucscKnownGene);
      SAMSequenceDictionary dict = iter.getHeader().getSequenceDictionary();

      int nKG = 0;
      r = IOUtils.openURIForBufferedReading(ucscKnownGene);
      Pattern tab = Pattern.compile("[\t]");
      String line;
      while ((line = r.readLine()) != null) {
        String tokens[] = tab.split(line);
        KnownGene g = new KnownGene(tokens);
        if (dict != null && dict.getSequence(g.getChr()) == null) continue;

        List<KnownGene> kg = this.chrom2knownGenes.get(g.getChr());
        if (kg == null) {
          kg = new ArrayList<KnownGene>();
          this.chrom2knownGenes.put(g.getChr(), kg);
        }
        kg.add(g);
        ++nKG;
      }
      r.close();
      info("Done Reading knownGenes. N=" + nKG);

      final double ticksH = (fHeight / 2.0f) * 0.6f;
      final double ticksx = 20;

      System.out.print(
          "%!PS\n"
              + "%%Creator: Pierre Lindenbaum PhD [email protected] http://plindenbaum.blogspot.com\n"
              + "%%Title: "
              + getClass().getSimpleName()
              + "\n"
              + "%%CreationDate: "
              + new Date()
              + "\n"
              + "%%EndComments\n"
              + "%%BoundingBox: 0 0 "
              + (this.pageDef.width + margin.left + margin.right)
              + " "
              + (this.pageDef.height + margin.top + margin.bottom)
              + "\n"
              + "/Courier findfont 9 scalefont setfont\n"
              + "/circle { 10 0 360 arc} bind def\n"
              + "/ticksF {\n"
              + (-ticksH)
              + " "
              + (ticksH)
              + " rmoveto\n"
              + ticksH
              + " "
              + (-ticksH)
              + " rlineto\n"
              + (-ticksH)
              + " "
              + (-ticksH)
              + " rlineto\n"
              + ticksH
              + " "
              + ticksH
              + " rmoveto\n"
              + "} bind def\n"
              + "/ticksR {\n"
              + (ticksH)
              + " "
              + (ticksH)
              + " rmoveto\n"
              + (-ticksH)
              + " "
              + (-ticksH)
              + " rlineto\n"
              + (ticksH)
              + " "
              + (-ticksH)
              + " rlineto\n"
              + (-ticksH)
              + " "
              + (ticksH)
              + " rmoveto\n"
              + "} bind def\n"
              + "/forticksF {2 dict begin\n"
              + "/x2 exch def\n"
              + "/x1 exch def\n"
              + "0 1 x2 x1 sub "
              + ticksx
              + " div {\n"
              + "ticksF "
              + ticksx
              + " 0 rmoveto\n"
              + "}for\n"
              + "} bind def\n"
              + "/forticksR {2 dict begin\n"
              + "/x2 exch def\n"
              + "/x1 exch def\n"
              + "0 1 x2 x1 sub "
              + ticksx
              + " div {\n"
              + " ticksR  "
              + ticksx
              + " 0 rmoveto\n"
              + "}for\n"
              + "} bind def\n"
              + "/box\n"
              + "{\n"
              + "4 dict begin\n"
              + "/height exch def\n"
              + "/width exch def\n"
              + "/y exch def\n"
              + "/x exch def\n"
              + "x y moveto\n"
              + "width 0 rlineto\n"
              + "0 height rlineto\n"
              + "width -1 mul 0 rlineto\n"
              + "0 height -1 mul rlineto\n"
              + "end\n"
              + "} bind def\n"
              + "/gradient\n"
              + "{\n"
              + "4 dict begin\n"
              + "/height exch def\n"
              + "/width exch def\n"
              + "/y exch def\n"
              + "/x exch def\n"
              + "/i 0 def\n"
              + "height 2 div /i exch def\n"
              + "\n"
              + "0 1 height 2 div {\n"
              + "	1 i height 2.0 div div sub setgray\n"
              + "	newpath\n"
              + "	x  \n"
              + "	y height 2 div i sub  add\n"
              + "	width\n"
              + "	i 2 mul\n"
              + "	box\n"
              + "	closepath\n"
              + "	fill\n"
              + "	i 1 sub /i exch def\n"
              + "	}for\n"
              + "newpath\n"
              + "0 setgray\n"
              + "0.4 setlinewidth\n"
              + "x y width height box\n"
              + "closepath\n"
              + "stroke\n"
              + "end\n"
              + "} bind def\n");

      run(iter);
      System.out.print("\n%%Trailer\n%%EOF\n");
      return 0;
    } catch (Exception err) {
      error(err);
      return -1;
    } finally {
      CloserUtil.close(r);
      CloserUtil.close(iter);
    }
  }