nodes: 0, module; 1, function_definition; 2, function_name:map_uniprot_to_pdb; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# First get all UniProt IDs and check if they have PDBs; 11, expression_statement; 12, for_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, comment:# Now run the best_structures API for all genes; 17, for_statement; 18, expression_statement; 19, expression_statement; 20, identifier:seq_ident_cutoff; 21, float:0.0; 22, identifier:outdir; 23, None; 24, identifier:force_rerun; 25, False; 26, comment:"""Map all representative sequences' UniProt ID to PDB IDs using the PDBe "Best Structures" API.
          Will save a JSON file of the results to each protein's ``sequences`` folder.
  
          The "Best structures" API is available at https://www.ebi.ac.uk/pdbe/api/doc/sifts.html
          The list of PDB structures mapping to a UniProt accession sorted by coverage of the protein and,
          if the same, resolution.
  
          Args:
              seq_ident_cutoff (float): Sequence identity cutoff in decimal form
              outdir (str): Output directory to cache JSON results of search
              force_rerun (bool): Force re-downloading of JSON results if they already exist
  
          Returns:
              list: A rank-ordered list of PDBProp objects that map to the UniProt ID
  
          """; 27, assignment; 28, identifier:g; 29, attribute; 30, block; 31, call; 32, assignment; 33, assignment; 34, identifier:g; 35, call; 36, block; 37, call; 38, call; 39, identifier:all_representative_uniprots; 40, list; 41, identifier:self; 42, identifier:genes_with_a_representative_sequence; 43, expression_statement; 44, if_statement; 45, attribute; 46, argument_list; 47, identifier:uniprots_to_pdbs; 48, call; 49, identifier:counter; 50, integer:0; 51, identifier:tqdm; 52, argument_list; 53, expression_statement; 54, if_statement; 55, attribute; 56, argument_list; 57, attribute; 58, argument_list; 59, assignment; 60, identifier:uniprot_id; 61, comment:# TODO: add warning or something for isoform ids?; 62, block; 63, identifier:log; 64, identifier:info; 65, string; 66, attribute; 67, argument_list; 68, attribute; 69, assignment; 70, identifier:uniprot_id; 71, block; 72, identifier:log; 73, identifier:info; 74, call; 75, identifier:log; 76, identifier:info; 77, string:'Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.'; 78, identifier:uniprot_id; 79, attribute; 80, if_statement; 81, expression_statement; 82, string_content:Mapping UniProt IDs --> PDB IDs...; 83, identifier:bs_unip; 84, identifier:mapping; 85, keyword_argument; 86, keyword_argument; 87, keyword_argument; 88, identifier:self; 89, identifier:genes_with_a_representative_sequence; 90, identifier:uniprot_id; 91, attribute; 92, if_statement; 93, if_statement; 94, attribute; 95, argument_list; 96, attribute; 97, identifier:uniprot; 98, comparison_operator:'-' in uniprot_id; 99, block; 100, call; 101, identifier:fr; 102, string; 103, identifier:to; 104, string; 105, identifier:query; 106, identifier:all_representative_uniprots; 107, attribute; 108, identifier:uniprot; 109, comparison_operator:'-' in uniprot_id; 110, block; 111, comparison_operator:uniprot_id in uniprots_to_pdbs; 112, block; 113, else_clause; 114, string; 115, identifier:format; 116, call; 117, call; 118, attribute; 119, identifier:representative_sequence; 120, string; 121, identifier:uniprot_id; 122, expression_statement; 123, attribute; 124, argument_list; 125, string_content:ACC; 126, string_content:PDB_ID; 127, attribute; 128, identifier:representative_sequence; 129, string; 130, identifier:uniprot_id; 131, expression_statement; 132, identifier:uniprot_id; 133, identifier:uniprots_to_pdbs; 134, expression_statement; 135, if_statement; 136, block; 137, string_content:{}/{}: number of genes with at least one experimental structure; 138, identifier:len; 139, argument_list; 140, identifier:len; 141, argument_list; 142, identifier:g; 143, identifier:protein; 144, string_content:-; 145, assignment; 146, identifier:all_representative_uniprots; 147, identifier:append; 148, identifier:uniprot_id; 149, identifier:g; 150, identifier:protein; 151, string_content:-; 152, assignment; 153, assignment; 154, identifier:best_structures; 155, block; 156, expression_statement; 157, attribute; 158, attribute; 159, identifier:uniprot_id; 160, subscript; 161, identifier:uniprot_id; 162, subscript; 163, identifier:best_structures; 164, call; 165, expression_statement; 166, expression_statement; 167, call; 168, identifier:self; 169, identifier:genes_with_experimental_structures; 170, identifier:self; 171, identifier:genes; 172, call; 173, integer:0; 174, call; 175, integer:0; 176, attribute; 177, argument_list; 178, augmented_assignment; 179, call; 180, attribute; 181, argument_list; 182, attribute; 183, argument_list; 184, attribute; 185, argument_list; 186, attribute; 187, identifier:map_uniprot_to_pdb; 188, keyword_argument; 189, keyword_argument; 190, keyword_argument; 191, identifier:counter; 192, integer:1; 193, attribute; 194, argument_list; 195, identifier:log; 196, identifier:debug; 197, call; 198, identifier:uniprot_id; 199, identifier:split; 200, string; 201, identifier:uniprot_id; 202, identifier:split; 203, string; 204, identifier:g; 205, identifier:protein; 206, identifier:seq_ident_cutoff; 207, identifier:seq_ident_cutoff; 208, identifier:outdir; 209, identifier:outdir; 210, identifier:force_rerun; 211, identifier:force_rerun; 212, identifier:log; 213, identifier:debug; 214, call; 215, attribute; 216, argument_list; 217, string_content:-; 218, string_content:-; 219, attribute; 220, argument_list; 221, string; 222, identifier:format; 223, attribute; 224, identifier:uniprot_id; 225, string; 226, identifier:format; 227, attribute; 228, call; 229, string_content:{}, {}: no PDBs available; 230, identifier:g; 231, identifier:id; 232, string_content:{}: {} PDBs mapped; 233, identifier:g; 234, identifier:id; 235, identifier:len; 236, argument_list; 237, identifier:best_structures
code: def map_uniprot_to_pdb(self, seq_ident_cutoff=0.0, outdir=None, force_rerun=False):
          """Map all representative sequences' UniProt ID to PDB IDs using the PDBe "Best Structures" API.
          Will save a JSON file of the results to each protein's ``sequences`` folder.
  
          The "Best structures" API is available at https://www.ebi.ac.uk/pdbe/api/doc/sifts.html
          The list of PDB structures mapping to a UniProt accession sorted by coverage of the protein and,
          if the same, resolution.
  
          Args:
              seq_ident_cutoff (float): Sequence identity cutoff in decimal form
              outdir (str): Output directory to cache JSON results of search
              force_rerun (bool): Force re-downloading of JSON results if they already exist
  
          Returns:
              list: A rank-ordered list of PDBProp objects that map to the UniProt ID
  
          """
  
          # First get all UniProt IDs and check if they have PDBs
          all_representative_uniprots = []
          for g in self.genes_with_a_representative_sequence:
              uniprot_id = g.protein.representative_sequence.uniprot
              if uniprot_id:
                  # TODO: add warning or something for isoform ids?
                  if '-' in uniprot_id:
                      uniprot_id = uniprot_id.split('-')[0]
                  all_representative_uniprots.append(uniprot_id)
          log.info('Mapping UniProt IDs --> PDB IDs...')
          uniprots_to_pdbs = bs_unip.mapping(fr='ACC', to='PDB_ID', query=all_representative_uniprots)
  
          counter = 0
          # Now run the best_structures API for all genes
          for g in tqdm(self.genes_with_a_representative_sequence):
              uniprot_id = g.protein.representative_sequence.uniprot
              if uniprot_id:
                  if '-' in uniprot_id:
                      uniprot_id = uniprot_id.split('-')[0]
                  if uniprot_id in uniprots_to_pdbs:
                      best_structures = g.protein.map_uniprot_to_pdb(seq_ident_cutoff=seq_ident_cutoff, outdir=outdir, force_rerun=force_rerun)
                      if best_structures:
                          counter += 1
                          log.debug('{}: {} PDBs mapped'.format(g.id, len(best_structures)))
                  else:
                      log.debug('{}, {}: no PDBs available'.format(g.id, uniprot_id))
  
          log.info('{}/{}: number of genes with at least one experimental structure'.format(len(self.genes_with_experimental_structures),
                                                                                            len(self.genes)))
          log.info('Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.')