use of uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome in project SeqMonk by s-andrews.
the class PairedDataSet method run.
public void run() {
// We need to delete any cache files we're still holding
// Clear out the DataSet
super.run();
// Now clean up our own mess
Enumeration<Chromosome> e = readData.keys();
while (e.hasMoreElements()) {
Chromosome c = e.nextElement();
File f = readData.get(c).tempFile;
if (f != null) {
if (!f.delete())
System.err.println("Failed to delete cache file " + f.getAbsolutePath());
}
}
}
use of uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome in project SeqMonk by s-andrews.
the class SeqMonkDataWriter method printStandardDataSet.
private boolean printStandardDataSet(DataSet set, PrintStream p, int index, int indexTotal) throws IOException {
p.println(set.getTotalReadCount() + "\t" + set.name());
// Go through one chromosome at a time.
Chromosome[] chrs = data.genome().getAllChromosomes();
for (int c = 0; c < chrs.length; c++) {
ReadsWithCounts reads = set.getReadsForChromosome(chrs[c]);
p.println(chrs[c].name() + "\t" + reads.totalCount());
for (int j = 0; j < reads.reads.length; j++) {
if (cancel) {
cancelled(p);
return false;
}
if ((j % (1 + (reads.reads.length / 10))) == 0) {
Enumeration<ProgressListener> e2 = listeners.elements();
while (e2.hasMoreElements()) {
e2.nextElement().progressUpdated("Writing data for " + set.name(), index * chrs.length + c, indexTotal * chrs.length);
}
}
p.println(reads.reads[j] + "\t" + reads.counts[j]);
}
}
// Print a blank line after the last chromosome
p.println("");
return true;
}
use of uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome in project SeqMonk by s-andrews.
the class BedGraphDataWriter method run.
public void run() {
/*
* We need to sort the chromosomes alphabetically rather than by their
* natural order
*/
Chromosome[] chrs = SeqMonkApplication.getInstance().dataCollection().genome().getAllChromosomes();
Arrays.sort(chrs, new Comparator<Chromosome>() {
public int compare(Chromosome o1, Chromosome o2) {
return (o1.name().compareTo(o2.name()));
}
});
PrintWriter pr = null;
for (int i = 0; i < data.length; i++) {
try {
pr = new PrintWriter(new BufferedWriter(new FileWriter(files[i])));
} catch (IOException ex) {
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressExceptionReceived(ex);
}
pr.close();
return;
}
try {
for (int c = 0; c < chrs.length; c++) {
// Tell the listeners how far we've got
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressUpdated("Saving BedGraph Files", (i * chrs.length) + c, chrs.length * data.length);
}
Probe[] probes = list.getProbesForChromosome(chrs[c]);
for (int p = 0; p < probes.length; p++) {
// See if we need to bail out early
if (cancel) {
pr.close();
files[i].delete();
Enumeration<ProgressListener> el = listeners.elements();
while (el.hasMoreElements()) {
el.nextElement().progressCancelled();
}
return;
}
pr.println("chr" + probes[p].chromosome().name() + "\t" + probes[p].start() + "\t" + probes[p].end() + "\t" + data[i].getValueForProbe(probes[p]));
}
}
} catch (SeqMonkException ex) {
pr.close();
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressExceptionReceived(ex);
}
return;
}
pr.close();
}
// Write out the chromsome sizes file.
try {
pr = new PrintWriter(new BufferedWriter(new FileWriter(chrSizeFile)));
for (int c = 0; c < chrs.length; c++) {
pr.println("chr" + chrs[c].name() + "\t" + chrs[c].length());
}
pr.close();
} catch (IOException ex) {
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressExceptionReceived(ex);
}
pr.close();
return;
}
Enumeration<ProgressListener> e = listeners.elements();
while (e.hasMoreElements()) {
e.nextElement().progressComplete("save_bedgraph", null);
}
}
Aggregations