Class TwoBitParser

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class TwoBitParser
    extends java.io.InputStream
    downloaded from http://storage.bioinf.fbb.msu.ru/~roman/TwoBitParser.java Class is a parser of UCSC Genome Browser file format .2bit used to store nucleotide sequence information. This class extends InputStream and can be used as it after choosing one of names of containing sequences. This parser can be used to do some work like UCSC tool named twoBitToFa. For it just run this class with input file path as single parameter and set stdout stream into output file. If you have any problems or ideas don't hesitate to contact me through email: rsutormin[at]gmail.com.
    Author:
    Roman Sutormin
    • Constructor Summary

      Constructors 
      Constructor Description
      TwoBitParser​(java.io.File f)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()
      Method closes current sequence and it's necessary to invoke it before setting new current sequence.
      void closeParser()
      Method closes random access file descriptor.
      long getCurrentSequencePosition()  
      java.io.File getFile()  
      java.lang.String[] getSequenceNames()  
      java.lang.String loadFragment​(long seq_pos, int len)  
      static void main​(java.lang.String[] args)  
      void printFastaSequence()  
      void printFastaSequence​(long len)  
      int read()
      Method reads 1 nucleotide from sequence stream.
      void reset()
      Method resets current position to the begining of sequence stream.
      void setCurrentSequence​(java.lang.String seq_name)
      Method open nucleotide stream for sequence with given name.
      void setCurrentSequencePosition​(long pos)  
      long skip​(long n)
      Method skips n nucleotides in sequence stream.
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_BUFFER_SIZE

        public int DEFAULT_BUFFER_SIZE
    • Constructor Detail

      • TwoBitParser

        public TwoBitParser​(java.io.File f)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • getSequenceNames

        public java.lang.String[] getSequenceNames()
      • setCurrentSequence

        public void setCurrentSequence​(java.lang.String seq_name)
                                throws java.lang.Exception
        Method open nucleotide stream for sequence with given name.
        Parameters:
        seq_name - name of sequence (one of returned by getSequenceNames()).
        Throws:
        java.lang.Exception
      • reset

        public void reset()
                   throws java.io.IOException
        Method resets current position to the begining of sequence stream.
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • getCurrentSequencePosition

        public long getCurrentSequencePosition()
        Returns:
        number (starting from 0) of next readable nucleotide in sequence stream.
      • setCurrentSequencePosition

        public void setCurrentSequencePosition​(long pos)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Method reads 1 nucleotide from sequence stream. You should set current sequence before use it.
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Method skips n nucleotides in sequence stream. You should set current sequence before use it.
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Method closes current sequence and it's necessary to invoke it before setting new current sequence.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • closeParser

        public void closeParser()
                         throws java.lang.Exception
        Method closes random access file descriptor. You can't use any reading methods after it.
        Throws:
        java.lang.Exception
      • getFile

        public java.io.File getFile()
      • loadFragment

        public java.lang.String loadFragment​(long seq_pos,
                                             int len)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • printFastaSequence

        public void printFastaSequence()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • printFastaSequence

        public void printFastaSequence​(long len)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception