Class IOUtils
- java.lang.Object
-
- org.biojava.nbio.core.sequence.io.util.IOUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
IOUtils.ReaderProcessor
Closure interface used when working withIOUtils#processReader(String)
.
-
Constructor Summary
Constructors Constructor Description IOUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
close(Closeable c)
Closes any Object which implements the interfaceCloseable
and sending any error to the logger but not forcing any explicit catching of stream errors.static void
copy(InputStream input, OutputStream output)
Moves the bytes from input to output using a 4KB byte array.static <S extends Sequence<C>,C extends Compound>
intgetGCGChecksum(List<S> sequences)
Calculates GCG checksum for entire list of sequencesstatic <S extends Sequence<C>,C extends Compound>
intgetGCGChecksum(S sequence)
Calculates GCG checksum for a given sequencestatic <S extends Sequence<C>,C extends Compound>
StringgetGCGHeader(List<S> sequences)
Assembles a GCG file headerstatic <C extends Compound>
StringgetGCGType(CompoundSet<C> cs)
Determines GCG typestatic <S extends Sequence<C>,C extends Compound>
StringgetIDFormat(List<S> sequences)
Creates format String for accession IDsstatic List<String>
getList(BufferedReader br)
Returns the contents of a buffered reader as a list of stringsstatic List<String>
getList(File file)
Delegates togetList(InputStream)
by wrapping the File in a valid stream.static List<String>
getList(InputStream is)
Delegates togetList(BufferedReader)
by wrapping the InputStream in a valid reader.static String
getPDBCharacter(boolean web, char c1, char c2, boolean similar, char c)
Creates formatted String for a single character of PDB outputstatic String
getPDBConservation(boolean web, char c1, char c2, boolean similar)
Creates formatted String for displaying conservation in PDB outputstatic String
getPDBLegend()
Creates formatted String for displaying conservation legend in PDB outputstatic InputStream
openFile(File file)
For a filename this code will check the extension of the file for a .gz extension.static void
print(String string, File file)
Printsstring
tofile
.static void
processReader(BufferedReader br, IOUtils.ReaderProcessor processor)
Takes in a reader and a processor, reads every line from the given file and then invokes the processor.
-
-
-
Constructor Detail
-
IOUtils
public IOUtils()
-
-
Method Detail
-
close
public static void close(Closeable c)
Closes any Object which implements the interfaceCloseable
and sending any error to the logger but not forcing any explicit catching of stream errors.- Parameters:
c
- The stream to close
-
copy
public static void copy(InputStream input, OutputStream output) throws IOException
Moves the bytes from input to output using a 4KB byte array.- Parameters:
input
- Input stream of bytesoutput
- Output stream of bytes- Throws:
IOException
- If anything occurs in the case of the reads and writes
-
processReader
public static void processReader(BufferedReader br, IOUtils.ReaderProcessor processor) throws ParserException
Takes in a reader and a processor, reads every line from the given file and then invokes the processor. What you do with the lines is dependent on your processor. The code will automatically close the given BufferedReader.- Parameters:
br
- The reader to processprocessor
- The processor to invoke on all lines- Throws:
ParserException
- Can throw this if we cannot parse the given reader
-
getList
public static List<String> getList(BufferedReader br) throws ParserException
Returns the contents of a buffered reader as a list of strings- Parameters:
br
- BufferedReader to read from; will be closed- Returns:
- List of Strings
- Throws:
ParserException
- Can throw this if we cannot parse the given reader
-
getList
public static List<String> getList(InputStream is) throws ParserException
Delegates togetList(BufferedReader)
by wrapping the InputStream in a valid reader. No encoding is mentioned so if you need anything more advanced then use the other version of this method.- Parameters:
is
- InputStream which is a text file- Returns:
- List of Strings representing the lines of the files
- Throws:
ParserException
- Can throw this if the file is not a file or we cannot parse it
-
getList
public static List<String> getList(File file) throws IOException
Delegates togetList(InputStream)
by wrapping the File in a valid stream. No encoding is mentioned so if you need anything more advanced then use the other version of this method. Since this usesopenFile(File)
this code can support GZipped and plain files.- Parameters:
file
- File which is a text file- Returns:
- List of Strings representing the lines of the files
- Throws:
IOException
-
openFile
public static InputStream openFile(File file) throws IOException
For a filename this code will check the extension of the file for a .gz extension. If it finds one then the InputStream given back is aGZIPInputStream
. Otherwise we return a normalFileInputStream
.- Parameters:
file
- File which may or may not be GZipped- Returns:
- The final stream
- Throws:
IOExceptio
- nIOException
-
getGCGChecksum
public static <S extends Sequence<C>,C extends Compound> int getGCGChecksum(List<S> sequences)
Calculates GCG checksum for entire list of sequences- Parameters:
sequences
- list of sequences- Returns:
- GCG checksum
-
getGCGChecksum
public static <S extends Sequence<C>,C extends Compound> int getGCGChecksum(S sequence)
Calculates GCG checksum for a given sequence- Parameters:
sequence
- given sequence- Returns:
- GCG checksum
-
getGCGHeader
public static <S extends Sequence<C>,C extends Compound> String getGCGHeader(List<S> sequences)
Assembles a GCG file header- Parameters:
sequences
- list of sequences- Returns:
- GCG header
-
getGCGType
public static <C extends Compound> String getGCGType(CompoundSet<C> cs)
Determines GCG type- Parameters:
cs
- compound set of sequences- Returns:
- GCG type
-
getIDFormat
public static <S extends Sequence<C>,C extends Compound> String getIDFormat(List<S> sequences)
Creates format String for accession IDs- Parameters:
sequences
- list of sequences- Returns:
- format String for accession IDs
-
getPDBCharacter
public static String getPDBCharacter(boolean web, char c1, char c2, boolean similar, char c)
Creates formatted String for a single character of PDB output- Parameters:
web
- true for HTML displayc1
- character in first sequencec2
- character in second sequencesimilar
- true if c1 and c2 are considered similar compoundsc
- character to display- Returns:
- formatted String
-
getPDBConservation
public static String getPDBConservation(boolean web, char c1, char c2, boolean similar)
Creates formatted String for displaying conservation in PDB output- Parameters:
web
- true for HTML displayc1
- character in first sequencec2
- character in second sequencesimilar
- true if c1 and c2 are considered similar compounds- Returns:
- formatted String
-
getPDBLegend
public static String getPDBLegend()
Creates formatted String for displaying conservation legend in PDB output- Returns:
- legend String
-
print
public static void print(String string, File file) throws IOException
Printsstring
tofile
.- Throws:
IOException
- If any I/O exception occurs while printing; this method does not catch any exceptions
-
-