def _create_composite_file_names(): file_names = {} names = [("tsv_file", ".tsv"), ("yaml_file", ".yaml"), ("json_file", ".json")] time_stamp = now_utc() time_stamped_base = "".join(["uni_composite.", time_stamp]) for name, ext in names: file_names[name] = "".join([time_stamped_base, ext]) return file_names
def test_new_filenames_pass(self): estimated_time = now_utc() result_names = ss._new_filenames() json_base, json_time, json_ext = result_names.json.split('.') raw_base, raw_time, raw_ext = result_names.raw.split('.') self.assertEqual(json_time, raw_time) self.assertAlmostEquals(json_time, estimated_time) self.assertEqual({json_base, raw_base, 'ss_dis'}, {'ss_dis'}) self.assertEqual(json_ext, 'json') self.assertEqual(raw_ext, 'txt') return None
def test_generate_json(self): time_stamp = now_utc() json_file_name = ( "{}.{}.{}".format( 'ss_dis', time_stamp, 'json' ) ) json_file_path = os.path.join(self.temp_dir, json_file_name) self.write_fasta(time_stamp) self.assertFalse(os.path.isfile(json_file_path)) ss.fetch_ss_dis(self.temp_dir) self.assertTrue(os.path.isfile(json_file_path)) return None
def test_generate_json_and_return_dic(self): # TODO: Value of expected updated to include '\r' after from __future__ import unicode_literals and from io import os. Validate this data. expected = { u'1DBO_A': { u'disorder': u'', u'secstr': u'', u'sequence': u'MKMLNKLAGYLLPIMVLLNVAPCLGQVVASNETLYQVVKEVKPGGLVQIADGTYKDVQLIVSNSGKSGLPITIKALNPGKVFFTGDAKVELRGEHLILEGIWFKDGNRAIQAWKSHGPGLVAIYGSYNRITACVFDCFDEANSAYITTSLTEDGKVPQHCRIDHCSFTDKITFDQVINLNNTARAIKDGSVGGPGMYHRVDHCFFSNPQKPGNAGGGIRIGYYRNDIGRCLVDSNLFMRQDSEAEIITSKSQENVYYGNTYLNCQGTMNFRHGDHQVAINNFYIGNDQRFGYGGMFVWGSRHVIACNYFELSETIKSRGNAALYLNPGAMASEHALAFDMLIANNAFINVNGYAIHFNPLDERRKEYCAANRLKFETPHQLMLKGNLFFKDKPYVYPFFKDDYFIAGKNSWTGNVALGVEKGIPVNISANRSAYKPVKIKDIQPIEGIALDLNALISKGITGKPLSWDEVRPYWLKEMPGTYALTARLSADRAAKFKAVIKRNKEH' }, u'5C1Z_B': { u'disorder': u'', u'secstr': u' EEEEESSSSS EEEE TT BHHHHHHHHHHHHTS GGGEEEEETTEEE TT BHHHHT TT EEEEEE TT EEEETTTT EEEEEEEEEEETTT SS EEESS SHHHHHSTT SBEEE STT BEEEEEEESSS TT EE TTEE TT B TTT B SSEEE STT BEEEHHHHHHHHHHHHHTT EEETTTEEE TT TT S GGGGGG', u'sequence': u'MIVFVRFNSSHGFPVEVDSDTSIFQLKEVVAKRQGVPADQLRVIFAGKELRNDWTVQNCDLDQQSIVHIVQRPWRKGQEMNATNSFYVYCKGPCQRVQPGKLRVQCSTCRQATLTLTQGPSCWDDVLIPNRMSGECQSPHCPGTSAEFFFKCGAHPTSDKETSVALHLIATNSRNITCITCTDVRSPVLVFQCNSRHVICLDCFHLYCVTRLNDRQFVHDPQLGYSLPCVAGCPNSLIKELHHFRILGEEQYNRYQQYGAEECVLQMGGVLCPRPGCGAGLLPEPDQRKVTCEGGNGLGCGFAFCRECKEAYHEGECSAVFEASGTTTQAYRVDERAAEQARWEAASKETIKKTTKPCPRCHVPVEKNGGCMHMKCPQPQCRLEWCWNCGCEWNRVCMGDHWFDV' } } time_stamp = now_utc() self.write_fasta(time_stamp) result = ss.fetch_ss_dis(self.temp_dir) self.assertEqual(expected, result) return None
def backup_file(original_file_path): log_pdb = getLogger('pdb_app_logger') if not os.path.abspath(original_file_path): raise RuntimeError("Please pass an absolute file path.") name_segments = original_file_path.split('.') if len(name_segments) > 2: original_fn = ''.join(name_segments[:-1]) extension = ''.join( ['.', name_segments[-1]] ) elif len(name_segments) == 2: original_fn = name_segments[0] extension = ''.join( ['.', name_segments[1]] ) else: assert len(name_segments) == 1 original_fn = name_segments[0] extension = '' timestamp = now_utc() new_fn = ''.join([ original_fn, '.', timestamp, extension ]) new_fp = os.path.join( os.path.basename(original_file_path), new_fn ) copy2(original_file_path, new_fp) assert isfile(new_fp) assert cmp(original_file_path, new_fp, shallow=False) log_pdb.info( "Created a backup of \'{}\' at the following location:\n" "\t{}".format(original_file_path, new_fp) ) return None
def _new_filenames(): """Create text and json filenames with matching timestamps. Returns: new_filenames (SS_Names): A named 2-tuple where raw is the filename of the new text file and json is the name of the matching (datetime) json file. """ timestamp = now_utc() rfn = "{}.{}.{}".format( 'ss_dis', timestamp, 'txt' ) yfn = "{}.{}.{}".format( 'ss_dis', timestamp, 'json' ) new_filenames = SS_File_Names(raw=rfn, json=yfn) return new_filenames