Search in sources :

Example 76 with Chromosome

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());
        }
    }
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) File(java.io.File)

Example 77 with Chromosome

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;
}
Also used : ProgressListener(uk.ac.babraham.SeqMonk.DataTypes.ProgressListener) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) ReadsWithCounts(uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)

Example 78 with Chromosome

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);
    }
}
Also used : Enumeration(java.util.Enumeration) FileWriter(java.io.FileWriter) Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) IOException(java.io.IOException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) BufferedWriter(java.io.BufferedWriter) ProgressListener(uk.ac.babraham.SeqMonk.DataTypes.ProgressListener) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) PrintWriter(java.io.PrintWriter)

Aggregations

Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)78 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)47 Vector (java.util.Vector)36 Feature (uk.ac.babraham.SeqMonk.DataTypes.Genome.Feature)23 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)23 ProbeSet (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeSet)22 ProbeList (uk.ac.babraham.SeqMonk.DataTypes.Probes.ProbeList)12 DataStore (uk.ac.babraham.SeqMonk.DataTypes.DataStore)11 DataSet (uk.ac.babraham.SeqMonk.DataTypes.DataSet)8 ReadsWithCounts (uk.ac.babraham.SeqMonk.DataTypes.Sequence.ReadsWithCounts)8 Location (uk.ac.babraham.SeqMonk.DataTypes.Genome.Location)7 SplitLocation (uk.ac.babraham.SeqMonk.DataTypes.Genome.SplitLocation)7 ProgressListener (uk.ac.babraham.SeqMonk.DataTypes.ProgressListener)7 HiCHitCollection (uk.ac.babraham.SeqMonk.DataTypes.Sequence.HiCHitCollection)7 IOException (java.io.IOException)6 File (java.io.File)5 Hashtable (java.util.Hashtable)5 HiCDataStore (uk.ac.babraham.SeqMonk.DataTypes.HiCDataStore)5 QuantitationStrandType (uk.ac.babraham.SeqMonk.DataTypes.Sequence.QuantitationStrandType)5 PairedDataSet (uk.ac.babraham.SeqMonk.DataTypes.PairedDataSet)4