de.unibi.techfak.jpredictor.sequences
Class RawReader

java.lang.Object
  extended by java.io.Reader
      extended by de.unibi.techfak.jpredictor.sequences.SequenceReader
          extended by de.unibi.techfak.jpredictor.sequences.RawReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class RawReader
extends SequenceReader

Class for adding filter functionality to the SequenceReader and, if wished, discarding of new line characters, too. While reading the file, one SequenceInformationBlock is filled, especially start and length.

Every read from the underlying reader is filtered (if a filter is installed). Due to not uppercasing the read characters, the filter can be applied for lowercase chars, too. Lowercase chars start 32 indices after the uppercase char's start.
The filter string functions the following: the characters of the string represent the uppercase and all following letters. Thus filter.charAt(0) holds the character that replaces all uppercase A's, filter.charAt(1) stands for B's to be replaced and so on.
A space in the filter string stands for discarding that character, e.g. the string "A B" lets through only A's and C's, and C's are transformed to B's.

If a filter is installed no character befor the uppercase A is left through. If no filter is installed all read chars are left unchanged but it is possible to construct the class the way, that read new-line characters are discared.

See Also:
SequenceInformationBlock

Field Summary
private  boolean discardNewLineChars
          Decides whether new-line characters are left through or not.
private  java.lang.String filter
          The file filter used in the readFiltered()-method.
 
Fields inherited from class de.unibi.techfak.jpredictor.sequences.SequenceReader
countCharsRead, mark, sequenceBlocks
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
RawReader(java.io.Reader reader, boolean discardNewLine)
          Sets reader and a rudimentary filter.
RawReader(java.io.Reader reader, java.lang.String filter)
          Sets filter and reader.
 
Method Summary
static java.lang.String createSequenceFromFile(java.lang.String filename, java.lang.String filter)
          Reads a file completely and stores the sequence in it to a String.
 java.lang.String getFilter()
          Returns the filter used to filter the read sequence befor returning it.
protected  int readFiltered()
          Reads characters from the stream until the next valid character occurs which is returned.
 void setFilter(java.lang.String filter)
          Sets a new filter.
 
Methods inherited from class de.unibi.techfak.jpredictor.sequences.SequenceReader
close, mark, markSupported, read, read, readLine, readUnfiltered, reset, sequences, skip
 
Methods inherited from class java.io.Reader
read, read, ready
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

private java.lang.String filter
The file filter used in the readFiltered()-method.

See Also:
FastaReader.setFilter(String), SequenceReader.readFiltered()

discardNewLineChars

private boolean discardNewLineChars
Decides whether new-line characters are left through or not. Works only, if no filter string is applied. Per default set to false.

Constructor Detail

RawReader

public RawReader(java.io.Reader reader,
                 boolean discardNewLine)
          throws java.lang.NullPointerException
Sets reader and a rudimentary filter. Lets you decide, whether new-line characters are discarded or not.

Parameters:
reader - The Reader to read from.
discardNewLine - true, if new-line characters should be discarded from the stream, false otherwise.
Throws:
java.lang.NullPointerException - If reader is null.

RawReader

public RawReader(java.io.Reader reader,
                 java.lang.String filter)
          throws java.lang.NullPointerException
Sets filter and reader. If filter is null all characters are left through. Otherwise, if filter is not null all characters with their order below 'A' are discarded and on the remaining chars the filter is applied.

Parameters:
reader - The Reader to read from.
filter - Filter for every character read.
Throws:
java.lang.NullPointerException - If reader is null.
Method Detail

getFilter

public java.lang.String getFilter()
Returns the filter used to filter the read sequence befor returning it.

Returns:
The filter as String.

setFilter

public void setFilter(java.lang.String filter)
Sets a new filter. Valid filters are e.g. SequenceFilter.DNA_FILTER.

Parameters:
filter - The new filter to set.
See Also:
SequenceFilter

readFiltered

protected int readFiltered()
                    throws NewSequenceBlockException
Description copied from class: SequenceReader
Reads characters from the stream until the next valid character occurs which is returned. This method also writes the sequence information block to cut a file into single sequences seperated by a predefined delimiter.

Specified by:
readFiltered in class SequenceReader
Returns:
The next valid character, -1 in case of EOF
Throws:
NewSequenceBlockException - An IOException thrown when a new sequence occurs within the file.

createSequenceFromFile

public static java.lang.String createSequenceFromFile(java.lang.String filename,
                                                      java.lang.String filter)
Reads a file completely and stores the sequence in it to a String. Without a given filter, all characters as they are read are stored in the string. For filtering the method SequenceFilter.filterString(String, String) is called.

Parameters:
filename - The name of the file to read.
filter - Used to filter the read characters.
Returns:
The sequence as String, null in case of any error.
See Also:
SequenceFilter.filterString(String, String)