当前位置: 首页>>代码示例>>Python>>正文


Python NamedTemporaryFile.flush方法代码示例

本文整理汇总了Python中tempfile.NamedTemporaryFile.flush方法的典型用法代码示例。如果您正苦于以下问题:Python NamedTemporaryFile.flush方法的具体用法?Python NamedTemporaryFile.flush怎么用?Python NamedTemporaryFile.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tempfile.NamedTemporaryFile的用法示例。


在下文中一共展示了NamedTemporaryFile.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: refine_by_scanning

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
	def refine_by_scanning(motifs, fastafile):
		
		tmp_gff = NamedTemporaryFile()
		file_in = NamedTemporaryFile()
		for m in motifs:
			file_in.write("%s\n" % m.to_pfm())
		file_in.flush()
		
		cmd = "pwmscan.py -i %s -p %s -c 0.8 > %s" % (fastafile, file_in.name, tmp_gff.name)
		p = Popen(cmd, shell=True)
		stdout,stderr = p.communicate()

		aligns = {}
		for line in open(tmp_gff.name):	
			vals = line.strip().split("\t")
			motif,instance = [x.split(" ")[1].replace('"', "") for x in vals[8].split(" ; ")]
		
			if vals[6] == "+":
				aligns.setdefault(motif,[]).append(instance.upper())
			else:
				aligns.setdefault(motif,[]).append(rc(instance.upper()))

		tmp_out = NamedTemporaryFile()
		
		refined_motifs = []
		for id,align in aligns.items():
			if len(align) > 10:
				motif = motif_from_align(align)
				refined_motifs.append(motif)
		
		return refined_motifs
开发者ID:astatham,项目名称:gimmemotifs,代码行数:33,代码来源:nmer_predict.py

示例2: get_tempfile

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
 def get_tempfile(self, **kwargs):
     kwargs.setdefault('suffix', '.vrt')
     tempfile = NamedTemporaryFile(**kwargs)
     tempfile.write(self.content)
     tempfile.flush()
     tempfile.seek(0)
     return tempfile
开发者ID:trailblazr,项目名称:gdal2mbtiles,代码行数:9,代码来源:gdal.py

示例3: test_safe_md5

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def test_safe_md5(self):
        """Make sure we have the expected md5 with varied input types

        This method is ported from PyCogent (http://www.pycogent.org). PyCogent
        is a GPL project, but we obtained permission from the authors of this
        method to port it to the BIOM Format project (and keep it under BIOM's
        BSD license).
        """
        exp = 'd3b07384d113edec49eaa6238ad5ff00'

        tmp_f = NamedTemporaryFile(
            mode='w',
            prefix='test_safe_md5',
            suffix='txt')
        tmp_f.write('foo\n')
        tmp_f.flush()

        obs = safe_md5(open(tmp_f.name, 'U'))
        self.assertEqual(obs, exp)

        obs = safe_md5(['foo\n'])
        self.assertEqual(obs, exp)

        # unsupported type raises TypeError
        self.assertRaises(TypeError, safe_md5, 42)
开发者ID:Jorge-C,项目名称:biom-format,代码行数:27,代码来源:test_util.py

示例4: test_seq_pipeline_parallel_run

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def test_seq_pipeline_parallel_run(self):
        'It tests that the pipeline runs ok'
        pipeline = 'sanger_without_qual'

        fhand_adaptors = NamedTemporaryFile()
        fhand_adaptors.write(ADAPTORS)
        fhand_adaptors.flush()
        arabidopsis_genes = 'arabidopsis_genes+'
        univec = os.path.join(TEST_DATA_DIR, 'blast', arabidopsis_genes)
        configuration = {'remove_vectors': {'vectors': univec},
                         'remove_adaptors': {'adaptors': fhand_adaptors.name}}

        in_fhands = {}
        in_fhands['in_seq'] = open(os.path.join(TEST_DATA_DIR, 'seq.fasta'),
                                   'r')
        out_fhand = NamedTemporaryFile()
        writer = SequenceWriter(out_fhand, file_format='fasta')
        writers = {'seq': writer}

        seq_pipeline_runner(pipeline, configuration, in_fhands,
                            processes=4, writers=writers)
        out_fhand = open(out_fhand.name, 'r')

        result_seq = out_fhand.read()
        assert result_seq.count('>') == 6
        #are we keeping the description?
        assert 'mdust' in result_seq
开发者ID:BioinformaticsArchive,项目名称:franklin,代码行数:29,代码来源:pipeline_test.py

示例5: test_pipeline_run

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def test_pipeline_run():
        'It tests that the pipeline runs ok'
        pipeline = 'sanger_with_qual'

        fhand_adaptors = NamedTemporaryFile()
        fhand_adaptors.write(ADAPTORS)
        fhand_adaptors.flush()

        arabidopsis_genes = 'arabidopsis_genes+'

        univec = os.path.join(TEST_DATA_DIR, 'blast', arabidopsis_genes)
        configuration = {'remove_vectors_blastdb': {'vectors': univec},
                         'remove_adaptors': {'adaptors': fhand_adaptors.name}}

        seq_fhand = open(os.path.join(TEST_DATA_DIR, 'seq.fasta'), 'r')
        qual_fhand = open(os.path.join(TEST_DATA_DIR, 'qual.fasta'), 'r')

        seq_iter = seqs_in_file(seq_fhand, qual_fhand)

        filtered_seq_iter = _pipeline_builder(pipeline, seq_iter,
                                              configuration)

        seq_list = list(filtered_seq_iter)
        assert 'CGAtcgggggg' in str(seq_list[0].seq)
        assert len(seq_list) == 6
开发者ID:BioinformaticsArchive,项目名称:franklin,代码行数:27,代码来源:pipeline_test.py

示例6: get_splice_score

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
def get_splice_score(a, s_type=5):
    if s_type not in [3,5]:
        raise Exception("Invalid splice type {}, should be 3 or 5".format(s_type))
    
    maxent = config.maxentpath
    if not maxent:
        raise Exception("Please provide path to the score5.pl and score3.pl maxent scripts in config file")

    tmp = NamedTemporaryFile()
    for name,seq in a:
        tmp.write(">{}\n{}\n".format(name,seq))
    tmp.flush()
    cmd = "perl score{}.pl {}".format(s_type, tmp.name)
    p = sp.Popen(cmd, shell=True, cwd=maxent, stdout=sp.PIPE)
    score = 0
    for line in p.stdout.readlines():
        vals = line.strip().split("\t")
        if len(vals) > 1:
            try:
                score += float(vals[-1])
            except ValueError:
                logger.error("valueError, skipping: {}".format(vals))
            except:
                logger.error("Something unexpected happened")
    return score
开发者ID:simonvh,项目名称:pita,代码行数:27,代码来源:util.py

示例7: get_logs

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def get_logs(self):
        """
        Build the logs entry for the metadata 'output' section

        :return: list, Output instances
        """

        # Collect logs from server
        kwargs = {}
        if self.namespace is not None:
            kwargs['namespace'] = self.namespace
        logs = self.osbs.get_build_logs(self.build_id, **kwargs)

        # Deleted once closed
        logfile = NamedTemporaryFile(prefix=self.build_id,
                                     suffix=".log",
                                     mode='w')
        logfile.write(logs)
        logfile.flush()

        docker_logs = NamedTemporaryFile(prefix="docker-%s" % self.build_id,
                                         suffix=".log",
                                         mode='w')
        docker_logs.write("\n".join(self.workflow.build_logs))
        docker_logs.flush()

        return [Output(file=docker_logs,
                       metadata=self.get_output_metadata(docker_logs.name,
                                                         "build.log")),
                Output(file=logfile,
                       metadata=self.get_output_metadata(logfile.name,
                                                         "openshift-final.log"))]
开发者ID:twaugh,项目名称:atomic-reactor,代码行数:34,代码来源:exit_koji_promote.py

示例8: solve

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def solve(self, cnf):
        s = Solution()

        infile = NamedTemporaryFile(mode='w')
        outfile = NamedTemporaryFile(mode='r')

        io = DimacsCnf()
        infile.write(io.tostring(cnf))
        infile.flush()

        ret = call(self.command % (infile.name, outfile.name), shell=True)

        infile.close()

        if ret != 10:
            return s

        s.success = True

        lines = outfile.readlines()[1:]

        for line in lines:
            varz = line.split(" ")[:-1]
            for v in varz:
                v = v.strip()
                value = v[0] != '-'
                v = v.lstrip('-')
                vo = io.varobj(v)
                s.varmap[vo] = value

        # Close deletes the tmp files
        outfile.close()

        return s
开发者ID:cocuh,项目名称:satispy,代码行数:36,代码来源:minisat.py

示例9: test_dup_bin

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def test_dup_bin(self):
        seqs = '@seq1.f\naaaa\n+\nHHHH\[email protected]\naaaa\n+\nHHHH\n'
        seqs += '@seq2.f\naaab\n+\nHHHH\[email protected]\naaaa\n+\nHHHH\n'
        in_fhand = NamedTemporaryFile()
        in_fhand.write(seqs)
        in_fhand.flush()

        filter_bin = os.path.join(BIN_DIR, 'filter_duplicates')
        assert 'usage' in check_output([filter_bin, '-h'])
        result = check_output([filter_bin, in_fhand.name])
        assert'@seq1.f\naaaa\n+\nHHHH\[email protected]\naaab\n+\nHHHH\n' in result
        result = check_output([filter_bin], stdin=in_fhand)
        assert'@seq1.f\naaaa\n+\nHHHH\[email protected]\naaab\n+\nHHHH\n' in result
        assert'@seq1.f\naaaa\n+\nHHHH\[email protected]\naaab\n+\nHHHH\n' in result
        result = check_output([filter_bin, in_fhand.name, '-m', '3'])
        assert'@seq1.f\naaaa\n+\nHHHH\[email protected]\naaab\n+\nHHHH\n' in result
        result = check_output([filter_bin, in_fhand.name, '--paired_reads'])
        assert seqs in result
        result = check_output([filter_bin, in_fhand.name, '-l', '1'])
        assert result == '@seq1.f\naaaa\n+\nHHHH\n'

        return  # TODO Fallo sin arreglar
        in_fhand = open(os.path.join(TEST_DATA_DIR, 'illum_fastq.fastq'))
        try:
            result = check_output([filter_bin], stdin=in_fhand)
            # print result
            self.fail()
        except UndecidedFastqVersionError:
            pass
开发者ID:pziarsolo,项目名称:seq_crumbs,代码行数:31,代码来源:test_bulk_filters.py

示例10: get_pairwise_distances

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
def get_pairwise_distances(seq_series, tree_file = None, seq_file = None):
    
    if seq_file is None:
        fasta_handle = NTF()
    if tree_file is None:
        tree_handle = NTF()
    else:
        tree_handle = open(tree_file, 'w')
    for (pat, visit), seq in zip(seq_series.index, seq_series.values):
        nheader = '%s-%s' % (pat, visit)
        fasta_handle.write('>%s\n%s\n' % (nheader, ''.join(seq)))
    fasta_handle.flush()
    os.fsync(fasta_handle.fileno())
    cmd = 'muscle -in %(ifile)s -tree2 %(treefile)s -gapopen -2.9'
    cmdlist = shlex.split(cmd % {
                                 'ifile':fasta_handle.name, 
                                 'treefile':tree_handle.name
                                 })
    t = check_call(cmdlist)
    tree = Phylo.read(open(tree_handle.name), 'newick')
    seq_names = tree.get_terminals()
    dmat = {}
    for p1, p2 in combinations(seq_names, 2):
        d = tree.distance(p1, p2)
        dmat[(p1.name, p2.name)] = d
        dmat[(p2.name, p1.name)] = d
        
    return dmat
开发者ID:JudoWill,项目名称:ResearchNotebooks,代码行数:30,代码来源:TreeingFunctions.py

示例11: TestPipeline

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
class TestPipeline(unittest.TestCase):
    """ Class to test a pipeline with an iterative node
    """
    def setUp(self):
        """ In the setup construct the pipeline and set some input parameters.
        """
        # Construct the pipelHine
        self.pipeline = MyPipeline()

        # Set some input parameters
        self.parallel_processes = 10
        self.input_file = NamedTemporaryFile(delete = False)
        self.input_file.write('\x00\x00' * self.parallel_processes)
        self.input_file.flush()
        self.input_file.close()
        self.pipeline.input_image = self.input_file.name
        self.output_file = NamedTemporaryFile()
        self.output_file.close()
        self.pipeline.output_image = self.output_file.name

    def test_iterative_pipeline_connection(self):
        """ Method to test if an iterative node and built in iterative
        process are correctly connected.
        """

        # Test the output connection
        self.pipeline()
        result = open(self.pipeline.output_image,'rb').read()
        numbers = struct.unpack_from('H' * self.parallel_processes, result)
        self.assertEqual(numbers, tuple(range(self.parallel_processes)))
开发者ID:VincentFrouin,项目名称:capsul,代码行数:32,代码来源:test_process_iteration.py

示例12: save

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def save(self, filename, mtime=1300507380.0):
        """
        Serialize this RingData instance to disk.

        :param filename: File into which this instance should be serialized.
        :param mtime: time used to override mtime for gzip, default or None
                      if the caller wants to include time
        """
        # Override the timestamp so that the same ring data creates
        # the same bytes on disk. This makes a checksum comparison a
        # good way to see if two rings are identical.
        #
        # This only works on Python 2.7; on 2.6, we always get the
        # current time in the gzip output.
        tempf = NamedTemporaryFile(dir=".", prefix=filename, delete=False)
        if 'mtime' in inspect.getargspec(GzipFile.__init__).args:
            gz_file = GzipFile(filename, mode='wb', fileobj=tempf,
                               mtime=mtime)
        else:
            gz_file = GzipFile(filename, mode='wb', fileobj=tempf)
        self.serialize_v1(gz_file)
        gz_file.close()
        tempf.flush()
        os.fsync(tempf.fileno())
        tempf.close()
        os.chmod(tempf.name, 0o644)
        os.rename(tempf.name, filename)
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:29,代码来源:ring.py

示例13: make_fasta

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
 def make_fasta(self):
     'it returns a fasta fhand'
     fhand = NamedTemporaryFile()
     fhand.write('>seq{0:d}\nACTATCATGGCAGATA\n'.format(self.counter))
     fhand.flush()
     self.counter += 1
     return fhand
开发者ID:milw,项目名称:seq_crumbs,代码行数:9,代码来源:test_small_bins.py

示例14: from_wav

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def from_wav(cls, fileName):
        """
        params
        :param fileName: file name to read
        """
        outputFile = NamedTemporaryFile(mode='w+b', delete=False)
        command = [
            converter, '-y',
            '-i', fileName,  # specifying input file
            '-vn',  # drop any video streams in the file
            '-sn',  # drop any subtitles present in the file
            '-f', 'wav',  # specify the output file format needed
            '-ar', '44100',  # uniform sample rate for all audio files
            outputFile.name
        ]

        # now use ffmpeg for conversion
        subprocess.call(command, stdout=open(os.devnull), stderr=open(os.devnull))

        outputFile.flush()
        obj = cls(outputFile.name)
        outputFile.close()
        os.unlink(outputFile.name)

        return obj
开发者ID:BhuvanAnand,项目名称:PW035,代码行数:27,代码来源:sonusreader.py

示例15: xtest_infile_outfile_condor

# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import flush [as 别名]
    def xtest_infile_outfile_condor():
        'It tests that we can set an input file and an output file'
        bin = create_test_binary()
        #with infile
        in_file = NamedTemporaryFile()
        content = 'hola1\nhola2\nhola3\nhola4\nhola5\nhola6\nhola7\nhola8\n'
        content += 'hola9\nhola10|n'
        in_file.write(content)
        in_file.flush()
        out_file = NamedTemporaryFile()

        cmd = [bin]
        cmd.extend(['-i', in_file.name, '-t', out_file.name])
        stdout = NamedTemporaryFile()
        stderr = NamedTemporaryFile()
        cmd_def = [{'options': ('-i', '--input'), 'io': 'in', 'splitter':''},
                   {'options': ('-t', '--output'), 'io': 'out'}]
        from psubprocess import CondorPopen
        popen = Popen(cmd, stdout=stdout, stderr=stderr, cmd_def=cmd_def,
                      runner=CondorPopen,
                      runner_conf={'transfer_executable':True})
        assert popen.wait() == 0 #waits till finishes and looks to the retcode
        assert not open(stdout.name).read()
        assert not open(stderr.name).read()
        assert open(out_file.name).read() == content
        in_file.close()
        os.remove(bin)
开发者ID:JoseBlanca,项目名称:psubprocess,代码行数:29,代码来源:prunner_test.py


注:本文中的tempfile.NamedTemporaryFile.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。