use of htsjdk.samtools.util.RuntimeIOException in project jvarkit by lindenb.
the class SimplePlot method doWork.
@Override
public int doWork(final Stage primaryStage, final List<String> args) {
Chart chart = null;
try {
final BufferedReader br;
if (args.isEmpty()) {
// open stdin
br = IOUtils.openStdinForBufferedReader();
} else if (args.size() == 1) {
br = IOUtils.openURIForBufferedReading(args.get(0));
} else {
LOG.error("Illegal Number of arguments: " + args);
return -1;
}
this.lineSupplier = () -> {
try {
for (; ; ) {
String L = br.readLine();
if (L == null)
return null;
return L;
}
} catch (final IOException err) {
throw new RuntimeIOException(err);
}
};
switch(this.chartType) {
case BEDGRAPH:
{
chart = new BedGraphSupplier().get();
break;
}
case PIE:
chart = new PieChartSupplier().get();
break;
case SIMPLE_HISTOGRAM:
chart = new SimpleHistogramSupplier().get();
break;
case HISTOGRAM:
chart = new HistogramSupplier().get();
break;
case STACKED_HISTOGRAM:
chart = new StackedHistogramSupplier().get();
break;
case XYV:
case STACKED_XYV:
chart = new XYVHistogramSupplier().setStacked(this.chartType == PlotType.STACKED_XYV).get();
break;
default:
{
LOG.error("Bad chart type : " + this.chartType);
return -1;
}
}
CloserUtil.close(br);
} catch (final Exception err) {
LOG.error(err);
return -1;
} finally {
}
if (chart == null) {
LOG.error("No chart was generated");
return -1;
}
if (StringUtil.isBlank(this.chartTitle)) {
chart.setLegendVisible(false);
} else {
chart.setTitleSide(this.titleSide);
chart.setTitle(this.chartTitle);
}
chart.setLegendSide(this.legendSide);
chart.setLegendVisible(!this.hide_legend);
if (this.outputFile != null) {
chart.setAnimated(false);
LOG.info("saving as " + this.outputFile + " and exiting.");
final Chart theChart = chart;
primaryStage.setOnShown(WE -> {
try {
saveImageAs(theChart, this.outputFile);
} catch (final IOException err) {
LOG.error(err);
setExitStatus(-1);
}
Platform.exit();
});
}
final Screen scr = Screen.getPrimary();
Scene scene = new Scene(chart, scr.getBounds().getWidth() - 100, scr.getBounds().getHeight() - 100);
primaryStage.setScene(scene);
primaryStage.show();
return 0;
}
use of htsjdk.samtools.util.RuntimeIOException in project jvarkit by lindenb.
the class TrapIndexer method decode.
public static TrapRecord decode(final String contig, byte[] array) {
if (array.length != RECORD_SIZOF)
throw new IllegalStateException("byte.length " + array.length + "!=" + RECORD_SIZOF);
try {
final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(array));
final int pos = dis.readInt();
if (pos < 0)
throw new IOException("pos<0 : " + pos);
final byte ref = dis.readByte();
final byte alt = dis.readByte();
int ensgId = dis.readInt();
final String ensg = String.format("ENSG%0" + (ENSG_STRLEN - 4) + "d", ensgId);
byte[] score_bytes = new byte[SCORE_SIZEOF];
dis.readFully(score_bytes);
final float score;
if (score_bytes[0] == (byte) 1) {
score = 1.0f;
} else {
score = Float.parseFloat("0." + new String(score_bytes));
}
return new TrapRecord() {
@Override
public int getStart() {
return pos;
}
@Override
public int getEnd() {
return pos;
}
@Override
public String getContig() {
return contig;
}
@Override
public String getChr() {
return getContig();
}
@Override
public float getScore() {
return score;
}
@Override
public char getRef() {
return (char) ref;
}
@Override
public String getGene() {
return ensg;
}
@Override
public char getAlt() {
return (char) alt;
}
@Override
public String toString() {
return contig + ":" + pos + ":" + (char) ref + "/" + (char) alt + " " + ensg + " " + score;
}
};
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of htsjdk.samtools.util.RuntimeIOException in project jvarkit by lindenb.
the class ContigNameConverter method fromFile.
public static ContigNameConverter fromFile(final File mappingFile) {
IOUtil.assertFileIsReadable(mappingFile);
final MapBasedContigNameConverter mapper = new MapBasedContigNameConverter();
mapper.name = mappingFile.getName();
BufferedReader in = null;
try {
in = IOUtils.openFileForBufferedReading(mappingFile);
String line;
while ((line = in.readLine()) != null) {
if (line.isEmpty() || line.startsWith("#"))
continue;
final String[] tokens = line.split("[\t]");
if (tokens.length != 2 || tokens[0].trim().isEmpty() || tokens[1].trim().isEmpty()) {
in.close();
in = null;
throw new IOException("Bad mapping line: \"" + line + "\"");
}
tokens[0] = tokens[0].trim();
tokens[1] = tokens[1].trim();
if (mapper.map.containsKey(tokens[0])) {
in.close();
throw new IOException("Mapping defined twice for: \"" + tokens[0] + "\"");
}
mapper.map.put(tokens[0], tokens[1]);
}
return mapper;
} catch (final IOException err) {
throw new RuntimeIOException(err);
} finally {
CloserUtil.close(in);
}
}
use of htsjdk.samtools.util.RuntimeIOException in project jvarkit by lindenb.
the class FastaSequenceReader method read.
protected FastaSequence read(final PushbackReader reader) throws IOException {
boolean at_begin = true;
StringBuilder name = null;
ByteArrayOutputStream sequence = null;
try {
int c;
while ((c = reader.read()) != -1) {
if (at_begin && c == '>') {
if (name != null) {
reader.unread(c);
return this.fastaSequenceCreator.apply(name.toString(), sequence.toByteArray());
}
name = new StringBuilder();
sequence = new ByteArrayOutputStream(this.sequenceCapacity);
/* consume header */
while ((c = reader.read()) != -1 && c != '\n') {
name.append((char) c);
}
at_begin = true;
} else if (Character.isWhitespace(c)) {
at_begin = (c == '\n');
} else if (sequence == null) {
throw new IOException("Illegal character " + (char) c);
} else {
sequence.write(c);
while ((c = reader.read()) != -1 && c != '\n') {
sequence.write(c);
}
at_begin = true;
}
}
/* eof met */
if (name != null) {
return this.fastaSequenceCreator.apply(name.toString(), sequence.toByteArray());
}
return null;
} catch (final IOException e) {
throw new RuntimeIOException(e);
}
}
use of htsjdk.samtools.util.RuntimeIOException in project jvarkit by lindenb.
the class IOUtils method cat.
/**
* write something in a file
*/
public static void cat(final Object o, final File out, boolean append) {
PrintWriter w = null;
try {
w = new PrintWriter(new FileWriter(out, append));
w.print(o);
w.flush();
w.close();
w = null;
} catch (final IOException err) {
throw new RuntimeIOException(err);
} finally {
if (w != null)
w.close();
}
}
Aggregations