Advertisement
Guest User

test

a guest
Apr 4th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. #loading the original series matrix
  2. wb1 = openpyxl.load_workbook(r"C:/Users/Shaked Bruner/Desktop/GSE72056_series_matrix_shaked.xlsx")
  3. series_matrix_sheet = wb1["Sheet3"] #the transposed series matrix
  4. #loading the revised series matrix
  5. wb2= openpyxl.load_workbook(r"C:/Users/Shaked Bruner/Desktop/GSE72056_melanoma_single_cell_revised_v2.xlsx")
  6. series_matrix_revised= wb2["Sheet1"] #the transposed revised series matrix
  7. #loading the participant table
  8. wb3= openpyxl.load_workbook(r"C:/Users/Shaked Bruner/Desktop/participant.xlsx")
  9. participants_table= wb3["participant"] #the new table
  10. newTable = openpyxl.Workbook()
  11. newSheet = newTable.active
  12. newSheet.title = "name_xi_color_new"
  13.  
  14. def insert_to_list (start, stop, column, sheet): #inserting the values of selected column to list. gets starting and ending point and the required letter of column n the exel file
  15.     new_list = []
  16.     for row in range(start, stop):
  17.         pos = column + str(row)
  18.         specific_cell = sheet[pos]
  19.         new_list.append(specific_cell)
  20.     return new_list
  21.  
  22. def insert_list_to_column (start, column, list): #inserting value from list to the new column in the new table
  23.     length = len(list)
  24.     for row in range(start, length):
  25.         pos = column + str(row)
  26.         newSheet[pos].value = list(row)
  27.         newTable.save(r"C:\Users\Shaked Bruner\Desktop\GSE72056_series_matrix_new.xlsx")
  28.  
  29. #insert required future columns into list- change it  according to your needs
  30. list_of_required_column= ["!Sample_title", "!Sample_geo_accession","!Sample_source_name_ch1", "!Sample_organism_ch1", "!Sample_characteristics_ch1", "!Sample_characteristics_ch1"]
  31.  
  32. for letter in ascii_lowercase: #insert to list the right columns from the transposed series matrix
  33.     pos = (str(letter)).upper()+"1"
  34.     column_value_dict= {}
  35.     for column_title in list_of_required_column:
  36.         lst= insert_to_list(2, 4646, str(letter), series_matrix_sheet)
  37.         column_value_dict.update(column_title,lst)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement