Search in sources :

Example 1 with GraphicsState

use of com.github.lindenb.jvarkit.swing.GraphicsState in project jvarkit by lindenb.

the class CoveragePlotter method drawGenes.

private void drawGenes(final Graphics2D g, final Rectangle rect, final Locatable region) {
    final IntToDoubleFunction position2pixel = X -> ((X - region.getStart()) / (double) region.getLengthOnReference()) * rect.getWidth();
    final double y = rect.getMaxY() - 4.0;
    try (GraphicsState state = GraphicsState.of(g)) {
        final int geneSize = 10;
        state.getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        g.setFont(new Font(g.getFont().getName(), Font.PLAIN, geneSize));
        g.setColor(getColor("gene", Color.DARK_GRAY));
        getGenes(region).forEach(gtfline -> {
            final double x1 = position2pixel.applyAsDouble(gtfline.getStart());
            final double x2 = position2pixel.applyAsDouble(gtfline.getEnd());
            if (gtfline.getType().equals("gene")) {
                g.drawString(gtfline.getAttribute("gene_name"), (int) Math.max(x1, 1), (int) (y - (geneSize + 3)));
            } else if (gtfline.getType().equals("exon")) {
                g.draw(new Rectangle2D.Double(x1, y - 1, (x2 - x1), 3));
            } else if (gtfline.getType().equals("transcript")) {
                g.draw(new Line2D.Double(x1, y, x2, y));
            }
        });
    }
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) CharSplitter(com.github.lindenb.jvarkit.lang.CharSplitter) Point2D(java.awt.geom.Point2D) Program(com.github.lindenb.jvarkit.util.jcommander.Program) Rectangle2D(java.awt.geom.Rectangle2D) CigarElement(htsjdk.samtools.CigarElement) CigarOperator(htsjdk.samtools.CigarOperator) RenderingHints(java.awt.RenderingHints) IntervalListProvider(com.github.lindenb.jvarkit.samtools.util.IntervalListProvider) SAMFileHeader(htsjdk.samtools.SAMFileHeader) DistanceParser(com.github.lindenb.jvarkit.util.bio.DistanceParser) StringUtil(htsjdk.samtools.util.StringUtil) DimensionConverter(com.github.lindenb.jvarkit.jcommander.converter.DimensionConverter) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) DiscreteMedian(com.github.lindenb.jvarkit.math.DiscreteMedian) Path(java.nio.file.Path) CloserUtil(htsjdk.samtools.util.CloserUtil) PrintWriter(java.io.PrintWriter) SimpleInterval(com.github.lindenb.jvarkit.samtools.util.SimpleInterval) SequenceDictionaryUtils(com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils) Composite(java.awt.Composite) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Predicate(java.util.function.Predicate) Logger(com.github.lindenb.jvarkit.util.log.Logger) LineIterator(com.github.lindenb.jvarkit.util.iterator.LineIterator) Set(java.util.Set) Collectors(java.util.stream.Collectors) GTFCodec(com.github.lindenb.jvarkit.util.bio.gtf.GTFCodec) SAMRecord(htsjdk.samtools.SAMRecord) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) StringUtils(com.github.lindenb.jvarkit.lang.StringUtils) FileExtensions(htsjdk.samtools.util.FileExtensions) ToDoubleFunction(java.util.function.ToDoubleFunction) ColorUtils(com.github.lindenb.jvarkit.util.swing.ColorUtils) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) BedLine(com.github.lindenb.jvarkit.util.bio.bed.BedLine) SamReaderFactory(htsjdk.samtools.SamReaderFactory) Rectangle(java.awt.Rectangle) Cigar(htsjdk.samtools.Cigar) CloseableIterator(htsjdk.samtools.util.CloseableIterator) SequenceUtil(htsjdk.samtools.util.SequenceUtil) ContigNameConverter(com.github.lindenb.jvarkit.util.bio.fasta.ContigNameConverter) Parameter(com.beust.jcommander.Parameter) NullOuputStream(com.github.lindenb.jvarkit.io.NullOuputStream) BedLineCodec(com.github.lindenb.jvarkit.util.bio.bed.BedLineCodec) IterableAdapter(htsjdk.samtools.util.IterableAdapter) HashMap(java.util.HashMap) ValidationStringency(htsjdk.samtools.ValidationStringency) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) GTFLine(com.github.lindenb.jvarkit.util.bio.gtf.GTFLine) Interval(htsjdk.samtools.util.Interval) AlphaComposite(java.awt.AlphaComposite) NoSplitter(com.github.lindenb.jvarkit.util.jcommander.NoSplitter) Graphics2D(java.awt.Graphics2D) SAMRecordDefaultFilter(com.github.lindenb.jvarkit.samtools.SAMRecordDefaultFilter) IOUtils(com.github.lindenb.jvarkit.io.IOUtils) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) VCFReaderFactory(com.github.lindenb.jvarkit.variant.vcf.VCFReaderFactory) TabixReader(htsjdk.tribble.readers.TabixReader) StreamSupport(java.util.stream.StreamSupport) GraphicsState(com.github.lindenb.jvarkit.swing.GraphicsState) VCFConstants(htsjdk.variant.vcf.VCFConstants) Stroke(java.awt.Stroke) OutputStream(java.io.OutputStream) Line2D(java.awt.geom.Line2D) AbstractIterator(htsjdk.samtools.util.AbstractIterator) Locatable(htsjdk.samtools.util.Locatable) IntToDoubleFunction(java.util.function.IntToDoubleFunction) Iterator(java.util.Iterator) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) VCFReader(htsjdk.variant.vcf.VCFReader) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) FractionConverter(com.github.lindenb.jvarkit.jcommander.converter.FractionConverter) Pileup(com.github.lindenb.jvarkit.samtools.util.Pileup) DynamicParameter(com.beust.jcommander.DynamicParameter) BitSet(java.util.BitSet) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) ArchiveFactory(com.github.lindenb.jvarkit.io.ArchiveFactory) GraphicsState(com.github.lindenb.jvarkit.swing.GraphicsState) IntToDoubleFunction(java.util.function.IntToDoubleFunction) Line2D(java.awt.geom.Line2D) Font(java.awt.Font)

Aggregations

DynamicParameter (com.beust.jcommander.DynamicParameter)1 Parameter (com.beust.jcommander.Parameter)1 ArchiveFactory (com.github.lindenb.jvarkit.io.ArchiveFactory)1 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)1 NullOuputStream (com.github.lindenb.jvarkit.io.NullOuputStream)1 DimensionConverter (com.github.lindenb.jvarkit.jcommander.converter.DimensionConverter)1 FractionConverter (com.github.lindenb.jvarkit.jcommander.converter.FractionConverter)1 CharSplitter (com.github.lindenb.jvarkit.lang.CharSplitter)1 StringUtils (com.github.lindenb.jvarkit.lang.StringUtils)1 DiscreteMedian (com.github.lindenb.jvarkit.math.DiscreteMedian)1 SAMRecordDefaultFilter (com.github.lindenb.jvarkit.samtools.SAMRecordDefaultFilter)1 IntervalListProvider (com.github.lindenb.jvarkit.samtools.util.IntervalListProvider)1 Pileup (com.github.lindenb.jvarkit.samtools.util.Pileup)1 SimpleInterval (com.github.lindenb.jvarkit.samtools.util.SimpleInterval)1 GraphicsState (com.github.lindenb.jvarkit.swing.GraphicsState)1 DistanceParser (com.github.lindenb.jvarkit.util.bio.DistanceParser)1 SequenceDictionaryUtils (com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils)1 BedLine (com.github.lindenb.jvarkit.util.bio.bed.BedLine)1 BedLineCodec (com.github.lindenb.jvarkit.util.bio.bed.BedLineCodec)1 ContigNameConverter (com.github.lindenb.jvarkit.util.bio.fasta.ContigNameConverter)1