def test__exit(self): "Test TemporaryFile __exit__() method" tfile = TemporaryFile() trace = """ Called tempfile.mkstemp('', 'tmp', None, False) Called os.unlink('/fake/tmp/file')""" tfile.__exit__(None, None, None) assert_same_trace(self.tt, trace)
def test__enter(self): "Test TemporaryFile __enter__() method" expected = "/fake/tmp/file" trace = """ Called tempfile.mkstemp('', 'tmp', None, False)""" tfile = TemporaryFile() f = tfile.__enter__() self.assertEqual(f.name, expected) self.assertEqual(f.handle, 42) assert_same_trace(self.tt, trace)
def test__exit(self): "Test TemporaryFile __exit__() method" tfile = TemporaryFile() trace = """ Called tempfile.mkstemp('', 'tmp', None, False) Called os.close(42) Called os.unlink('/fake/tmp/file')""" tfile.__exit__(None, None, None) assert_same_trace(self.tt, trace)
def identify_lasso_motifs( leader: str, core: str) -> Tuple[List[int], int, Dict[int, float]]: """Run FIMO to identify lasso peptide-specific motifs""" motif_file = path.get_full_path(__file__, 'data', "lasso_motifs_meme.txt") with TemporaryFile() as tempfile: out_file = open(tempfile.name, "w") out_file.write(">query\n%s%s" % (leader, core)) out_file.close() fimo_output = subprocessing.run_fimo_simple(motif_file, tempfile.name) fimo_motifs = [ int(line.partition("\t")[0]) for line in fimo_output.split("\n") if "\t" in line and line.partition("\t")[0].isdigit() ] fimo_scores = { int(line.split("\t")[0]): float(line.split("\t")[5]) for line in fimo_output.split("\n") if "\t" in line and line.partition("\t")[0].isdigit() } # Calculate score motif_score = 0 if 2 in fimo_motifs: motif_score += 4 elif fimo_motifs: motif_score += 2 else: motif_score += -1 return fimo_motifs, motif_score, fimo_scores
def _run_external_tool(self, analysisResource, SeqFeatureList): "Generate tempfile containing the extracted Feature sequences and run tool defined in XML file" # write fasta file for the features to tempfile # FastA header is aSDomain_id tempfile = "" fastafile = [] for SeqFeature in SeqFeatureList: fastaHeader = SeqFeature.qualifiers['asDomain_id'][0] fastaSeq = SeqFeature.qualifiers['translation'][0] # Never write empty fasta entries if len(fastaSeq) == 0: logging.warn("No translation for %s, skipping", fastaHeader) continue fastafile.append(">%s\n" % fastaHeader) fastafile.append("%s\n" % fastaSeq) querydata = "".join(fastafile) # DEBUG # print "\nTempfile for %s:\n" % analysisResource.attrib['name'] # print "".join(fastafile) UseSTDIN = "False" executeObj = analysisResource.find('./Execute') if 'UseSTDIN' in executeObj.attrib: UseSTDIN = executeObj.attrib['UseSTDIN'] if UseSTDIN == "False": with TemporaryFile(prefix='antiSMASH_ASP') as tempfile: out_file = open(tempfile.name, "w") out_file.write(querydata) out_file.close() if len(fastafile) == 0: logging.warn( "ASP: No features found containing feature/tag/value %s / %s / %s", analysisResource.find('./Prerequisite/primary_tag_type').text, analysisResource.find('./Prerequisite/tag').text, analysisResource.find('./Prerequisite/tag_value').text) return [] results = [] if UseSTDIN == "True": results = self._execute_tool(analysisResource, stdin_data=querydata) else: results = self._execute_tool(analysisResource, fileName=tempfile.name) return results
def test__init(self): "Test TemporaryFile object creation" tfile = TemporaryFile() self.assertEqual(tfile.handle, 42) self.assertEqual(tfile.name, '/fake/tmp/file')