Exemple #1
0
 def set_object(self, obj, path, plain_text=False):
     from nesoni import io
     temp_filename = self._object_filename('tempfile')
     if plain_text:
         f = open(temp_filename, 'wb')
         f.write(repr(obj))
         f.close()
     else:
         f = io.Pipe_writer(temp_filename, ['gzip'])
         cPickle.dump(obj, f, 2)
         f.close()
     
     os.rename(temp_filename, self._object_filename(path))
Exemple #2
0
    def run(self):
        workspace = working_directory.Working(self.output_dir)        
        workspace.setup_reference(self.reference)
        workspace.update_param(snp_cost = self.snp_cost)
        
        #assert os.path.exists(self.reference), 'Reference file does not exist'
        #reference_filename = workspace._object_filename('reference.fa')
        #if os.path.exists(reference_filename):
        #   os.unlink(reference_filename)
        #os.symlink(os.path.relpath(self.reference, self.output_dir), reference_filename)
        
        bam_filename = io.abspath(self.output_dir, 'alignments.bam')
        bam_prefix = io.abspath(self.output_dir, 'alignments')

        if sam.is_bam(self.input):
            sort_input_filename = self.input
            temp_filename = None
        else:
            temp_filename = io.abspath(self.output_dir, 'temp.bam')
            sort_input_filename = temp_filename
            writer = io.Pipe_writer(temp_filename, ['samtools', 'view', '-S', '-b', '-'])
            f = open(self.input, 'rb')
            while True:
                data = f.read(1<<20)
                if not data: break
                writer.write(data)
            writer.close()
            f.close()
        
        grace.status('Sort')
        
        #io.execute([
        #    'samtools', 'sort', '-n', sort_input_filename, bam_prefix
        #])
        sam.sort_bam(sort_input_filename, bam_prefix, by_name=True)
        
        if temp_filename is not None:
            os.unlink(temp_filename)
        
        grace.status('')
Exemple #3
0
 def __init__(self, filename, headers=''):
     self.writer = io.Pipe_writer(filename, ['samtools', 'view', '-S', '-b', '-'])
     self.writer.write(headers)