-3

using Sam-tools Java API how i get seq. between start and end i am write following method it throws Exception . this method write to get Sequences from file .

method Goes Here

private static List<SAMRecord> scan(String chromosome, int start, int end) throws IOException {
    List<SAMRecord> records = new ArrayList<SAMRecord>();
    CloseableIterator<SAMRecord> iter = null;
    try {
      iter = inputSam.query(chromosome, start, (start+70), containsbamRecord);
System.out.println("herer : Floe");
      SAMRecord s=iter.next();
      System.out.println("Value Of Start : "+start+"\t"+"VAlue of End : "+(start+70)+"Value Of iter : "+s.getSAMString());

      while (iter.hasNext()) {
        SAMRecord rec = iter.next();
           //System.out.println("Value Of Start : "+start+"\t"+"VAlue of End : "+end+"Value Of iter : "+rec.get);

        records.add(rec);
      }
      return records;
    } catch (Exception e) {
      throw new IOException(e);
    } finally {
      if (iter != null)
        iter.close();
    }
  }

This is Stack Trace Exception Occurred

java.io.IOException: java.nio.BufferUnderflowException
    at WrapperMain.scan(WrapperMain.java:99)
    at WrapperMain.getDataforPosition(WrapperMain.java:119)
    at TzurLookupVariant.main(TzurLookupVariant.java:145)
Caused by: java.nio.BufferUnderflowException
    at java.nio.Buffer.nextGetIndex(Buffer.java:506)
    at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:677)
    at net.sf.samtools.AbstractBAMFileIndex$MemoryMappedFileBuffer.readInteger(AbstractBAMFileIndex.java:455)
    at net.sf.samtools.AbstractBAMFileIndex.readInteger(AbstractBAMFileIndex.java:406)
    at net.sf.samtools.AbstractBAMFileIndex.query(AbstractBAMFileIndex.java:266)
    at net.sf.samtools.DiskBasedBAMFileIndex.getSpanOverlapping(DiskBasedBAMFileIndex.java:60)
    at net.sf.samtools.BAMFileReader.createIndexIterator(BAMFileReader.java:719)
    at net.sf.samtools.BAMFileReader.query(BAMFileReader.java:369)
    at net.sf.samtools.SAMFileReader.query(SAMFileReader.java:381)
    at WrapperMain.scan(WrapperMain.java:86)
    ... 2 more
java.lang.NullPointerException
    at WrapperMain.getDataPoint(WrapperMain.java:199)
    at WrapperMain.getDataforPosition(WrapperMain.java:129)
    at TzurLookupVariant.main(TzurLookupVariant.java:145)
Mohasin Mujawar
  • 130
  • 1
  • 14
  • Please add a code snippet to help us understand the context of the exception. Also, obligatory reading: http://stackoverflow.com/help/how-to-ask – MigDus Oct 17 '15 at 05:55
  • `algorithm is correct it run properly` how is that true if it is giving you that exception? Post your code so we can see what is wrong with it. – Jorge Campos Oct 17 '15 at 05:55

1 Answers1

1

The javadoc for BufferUnderflowException says:

"Unchecked exception thrown when a relative get operation reaches the source buffer's limit."

So the general solution would be to avoid calling get on a buffer that has no more data in it.

We can't be more specific than that without seeing the relevant parts of your code.


You say:

... algorithm is correct ...

That is probably not true, at least at some level.

... when i create new class and make some modification it fire me the exception and now i delete created class but still it throws same Exception ....Why ????

It is likely that >>something<< has changed. But it is also possible that the root cause of your problem was there to start with, and there is something non-deterministic in the way that your application works.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216