Advertisement
Regional_Push

currently working version

Aug 4th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. import os
  2.  
  3. import pickle
  4.  
  5. home_path = os.getcwd()
  6.  
  7. path_to_cds_pickle_files = f'{home_path}/{"CDS_pickles_sequential"}' # where the cds pickle files are, this one specifially uses the CDS_pickles_sequential folder
  8. path_to_result = f'{home_path}/{"Test_folder/Test_cds_results"}' # where the result files will be dumped
  9. path_to_algined_files = f'{home_path}/{"Test_folder/Test_peptide_input"}' # where the aligned files are kept
  10. path_to_script_accessories =f'{home_path}/{"Script_accesories"}' # where a couple of accesory scripts are
  11.  
  12. def main():
  13.  
  14. hop_to_species_shorthand = os.chdir(path_to_script_accessories) # this is the folder that has the dict in pickle format
  15.  
  16. with open('cds_identifiers.pkl','rb') as cds_shorthand: # this opens the pickle file
  17. cds_shorthand_dict = pickle.load(cds_shorthand) # open the dict
  18.  
  19. hop_to_aligned_files = os.chdir(path_to_algined_files) # hop to the peptide files
  20.  
  21. list_of_aligned_files = os.listdir(path_to_algined_files) # make a list of the files in the peptide folder
  22.  
  23. def test_species(current_peptide_header): # this is a prototype, this function is actually called inside current_peptide_header
  24. for key,value in cds_shorthand_dict.items():
  25. if key in current_peptide_header:
  26. return value
  27.  
  28. for file in list_of_aligned_files: # go through the files
  29. hop_back_to_peptide_files = os.chdir(path_to_algined_files)
  30. with open(file,'rt') as current_peptide_file: # using with to not have to bother closing the files manaully
  31. current_peptide_headers = current_peptide_file.readlines() # turning it into an iterable object
  32.  
  33.  
  34.  
  35. for current_peptide_header in current_peptide_headers: # opeing the peptide header line
  36. if current_peptide_header[0] == '>': # '>' makes sure that the header is actually a header
  37. this_file = test_species(current_peptide_header)
  38. map_sequence = key_vs_key(current_peptide_header,this_file,file)
  39.  
  40.  
  41. def key_vs_key(current_peptide_header,this_file,file):
  42.  
  43. file = os.path.splitext(file)[0]
  44. file = f'{path_to_result}/{file}.{"acds"}'
  45.  
  46. hop_to_cds_pickles = os.chdir(path_to_cds_pickle_files)
  47. with open(this_file,'rb') as current_cds_pickle:
  48. current_pickle = pickle.load(current_cds_pickle)
  49.  
  50.  
  51. for Universal_header,cds_sequence in current_pickle.items():
  52. if Universal_header == current_peptide_header:
  53. with open(file,'a') as current_acds_file:
  54. current_acds_file.write(current_peptide_header)
  55. current_acds_file.write(cds_sequence)
  56.  
  57.  
  58. main()
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement