Jump to content

This topic is 3128 days old. Please don't post here. Open a new topic instead.

Recommended Posts

We are trying to generate the chromatogram for an ABI DNA sequencing file. Biojava (http://biojava.org) has a jar that will do this and many other things for DNA sequence files. Not sure how technical I need to be but a chromatogram is basically an image of the DNA detecting on the sequencing machine. I need to generate that image. I have attached the Jar and a sequencing file ("t1.ab1" as an example) and the Java code we are trying to get to work (with not a lot of success). We think we are close, but have a couple of errors. Anyone care to take a look and see if a fresh set of eyes will help? THANKS!!!

 

 

####Code below#####

 

import java.awt.image.BufferedImage;

import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.RenderingHints;

import java.io.IOException;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Iterator;

import javax.imageio.ImageIO;

import javax.imageio.ImageWriter;

import javax.imageio.stream.FileImageOutputStream;

import org.biojava.bio.chromatogram.Chromatogram;

import org.biojava.bio.chromatogram.ChromatogramFactory;

import org.biojava.bio.chromatogram.UnsupportedChromatogramFormatException;

import org.biojava.bio.chromatogram.graphic.ChromatogramGraphic;

import org.biojava.bio.program.abi.ABIFChromatogram

import org.biojava.bio.chromatogram.graphic.ChromatogramGraphic

import org.biojava.bio.chromatogram.*

import org.biojava.bio.chromatogram.graphic.*

import org.biojava.bio.program.abi.*;

import org.biojava.bio.*;

import org.biojava.bio.program.abi.*;

import org.biojava.bio.seq.*;

import org.biojava.bio.seq.impl.*;

import org.biojava.bio.seq.io.*;

import org.biojava.bio.symbol.*;

 

int OUT_HEIGHT = 240;

float OUT_HORIZ_SCALE = 2.0f;

 

File infile = new File('/Users/kessingb/Desktop/Chromatogram/t1.ab1');

//return infile

 

String name = infile.getName()

 

ABITrace trace = new ABITrace(infile)

//return trace.getSequenceLength()

return trace.getTraceLength()

 

Chromatogram c = ABIFChromatogram.create(infile)

//Chromatogram c = ChromatogramFactory.create(infile)

 

String outExt = "png";

Iterator writers = ImageIO.getImageWritersBySuffix(outExt);

ImageWriter iw = (ImageWriter) writers.next();

 

        /* build output stream */

        

File outfile = new File('/Users/kessingb/Desktop/Chromatogram/t1.jpg');

//FileImageOutputStream out = new FileImageOutputStream(outfile);

 

        

ChromatogramGraphic gfx = new ChromatogramGraphic(trace);

gfx.setHeight(OUT_HEIGHT);

gfx.setHorizontalScale(OUT_HORIZ_SCALE);

//set some options that affect the output

// turn off filled-in "callboxes"

gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_A, Boolean.FALSE);

gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_C, Boolean.FALSE);

gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_G, Boolean.FALSE);

gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_T, Boolean.FALSE);

gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_OTHER, Boolean.FALSE);

//this option controls whether each trace/callbox/etc is scaled/positioned

        // individually, or whether the scaling is done on all shapes at the level

        // of the graphics context

        // enabling this option is recommended for higher-quality output

gfx.setOption(ChromatogramGraphic.Option.USE_PER_SHAPE_TRANSFORM, Boolean.TRUE);

        

        /* create output image */

 

        BufferedImage bi = new BufferedImage(

                                   gfx.getWidth(), 

                                   gfx.getHeight(), 

                                   BufferedImage.TYPE_INT_RGB);

        Graphics2D g2 = bi.createGraphics();

        g2.setBackground(Color.white);

        g2.clearRect(0, 0, bi.getWidth(), bi.getHeight());

 

        /* draw chromatogram into image */

 

        // turn on AA for nicer output

        //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // the main event

        gfx.drawTo(g2);

        // work-around an OS X bug where sometimes the last Shape drawn

        // doesn't show up in the output

        g2.draw(new java.awt.Rectangle(-10, -10, 5, 5));

 

        /* write image out */

 

        iw.setOutput(outfile);

biojava-1.7.1.jar

t1.ab1

Link to comment
Share on other sites

Bailey

heres some code which works...
simplified where appropriate

<code>

import java.awt.image.BufferedImage
import java.awt.Color
import java.awt.Graphics2D
import java.awt.Rectangle
import java.awt.RenderingHints
import javax.imageio.ImageIO
import org.biojava.bio.chromatogram.Chromatogram
import org.biojava.bio.chromatogram.graphic.ChromatogramGraphic
import org.biojava.bio.program.abi.ABIFChromatogram
import org.biojava.bio.program.abi.ABITrace

OUT_HEIGHT = 240
OUT_HORIZ_SCALE = 2.0f

infile = new File('path/to/file')
//return infile

name = infile.getName()

trace = new ABITrace(infile)

c = ABIFChromatogram.create(infile)

    /* build output stream */
   
outfile = new File('/Users/whoever/documents/t1.jpg')
   
//ERROR in this line
gfx = new ChromatogramGraphic(c)
gfx.setHeight(OUT_HEIGHT)
gfx.setHorizontalScale(OUT_HORIZ_SCALE)
//set some options that affect the output
// turn off filled-in "callboxes"
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_A, Boolean.FALSE)
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_C, Boolean.FALSE)
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_G, Boolean.FALSE)
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_T, Boolean.FALSE)
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_OTHER, Boolean.FALSE)
//this option controls whether each trace/callbox/etc is scaled/positioned
    // individually, or whether the scaling is done on all shapes at the level
    // of the graphics context
    // enabling this option is recommended for higher-quality output
gfx.setOption(ChromatogramGraphic.Option.USE_PER_SHAPE_TRANSFORM, Boolean.TRUE)
   
//return 888
    /* create output image */

bi = new BufferedImage( gfx.getWidth(), gfx.getHeight(), BufferedImage.TYPE_INT_RGB)
g2 = bi.createGraphics()
g2.setBackground(Color.white)
g2.clearRect(0, 0, bi.getWidth(), bi.getHeight())

    /* draw chromatogram into image */

    // turn on AA for nicer output
    //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
    // the main event
gfx.drawTo(g2)
    // work-around an OS X bug where sometimes the last Shape drawn
    // doesn't show up in the output
g2.draw(new java.awt.Rectangle(-10, -10, 5, 5))


    /* write image out */

try{
    ImageIO.write(bi, 'jpg', outfile)
} catch (e) {
    return e.getMessage()
}
return true
//OR return the image to a container
return bi

</code>

 

Edited by john renfrew
  • Like 1
Link to comment
Share on other sites

OK John, I am still getting an error…let me see what I can ferret out…

Oh, here is the error I am getting: 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script1.groovy: 18: unexpected char: 0xA0 @ line 18, column 1.

      /* build output stream */

   ^

 

1 error

 

 

Parameters:

{}

Link to comment
Share on other sites

the new forum does not have  proper code black like the older version which used to allow for copy without the extra characters...

It is the Unicode Character 'NO-BREAK SPACE' (U+00A0)

 

john

  • Like 1
Link to comment
Share on other sites

Hey gang, thanks a lot for your hep!!! That was it. When I put in my text viewer it was giving the same looking code that a regular space was so I didn't notice it at first…should have, but hell, I am a scientist !! ;) Anyways, it is perfect now, thanks so much for all the help!!!

Link to comment
Share on other sites

syntax is right

comment out the trace = new ABI trace line

I then get an EOF problem with the ab1 file though. This is >>Signals that an end of file or end of stream has been reached unexpectedly during input.

but from the Api >>Due to the non-single-pass design of the ABI format, this method will wrap the InputStream in an CachingInputStream. For this reason, create(File) should be preferred

Link to comment
Share on other sites

This topic is 3128 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.