parameters: (mutation_file_path)
return_statement: return row_number_to_feature
docstring: Extract Mutation events from MAF data file.
docstring_summary: Extract Mutation events from MAF data file.
docstring_tokens: Extract Mutation events from MAF data file .
function: def get_features(mutation_file_path):
      """Extract Mutation events from MAF data file."""
      header_elements = libImportOncokb.get_first_line_cells(libImportOncokb.open_file(mutation_file_path), '\t')
      header_indexes = {}
      for required_column in required_mutation_columns + [FIELD_ENTREZ_ID]:
          header_indexes[required_column] = header_elements.index(required_column)
      row_number_to_feature = {}
      row_counter = 0
      mutation_file = libImportOncokb.open_file(mutation_file_path)
      print("Reading features from file ...", end = '')
      for line in mutation_file:
          row_counter += 1
          if line == '\n' or line.startswith('#') or line.startswith(header_elements[0]):
              continue  # skip comment and header line
          line_elements = line.rstrip().split('\t')
          feature = {}
          for column_name, index in header_indexes.items():
              value = line_elements[index]
              if value != '':
                  if column_name == PROTEIN_CHANGE:
                      value = value.replace('p.', '')
                  feature[column_name] = value
              elif column_name != FIELD_ENTREZ_ID and column_name != PROTEIN_POSITION and column_name != PROTEIN_CHANGE:
                  raise RuntimeError("Empty value encountered in column '" +
                                     column_name + "' in row " + str(row_counter) + "." \
                                                                                    "OncoKB annotations cannot be imported. Please fix and rerun.")
  
          # skip lines that have empty protein change column
          if PROTEIN_CHANGE not in feature:
              continue
              
          # resolve gene symbols to Entrez Ids if needed
          if FIELD_ENTREZ_ID in feature and feature[FIELD_ENTREZ_ID] is not None and feature[FIELD_ENTREZ_ID] != '':
              entrez_gene_ids = [feature[FIELD_ENTREZ_ID]]
          else:
              entrez_gene_ids = portal_instance.hugo_entrez_map[feature[FIELD_HUGO_SYMBOL]]
  
          if len(entrez_gene_ids) > 1:
              logger.error(""" Multiple Entrez gene ids were found for a gene.
                               OncoKB annotations will not be imported for this gene.
                               Please fix and rerun. """,
                           extra={'symbol': feature[FIELD_HUGO_SYMBOL], 'row': str(row_counter)})
              feature[FIELD_ENTREZ_ID] = None
          elif len(entrez_gene_ids) == 0:
              logger.error(""" Could not find the Entrez gene id for a gene.
                               OncoKB annotations will not be imported for this gene.
                               Please fix and rerun. """,
                           extra={'symbol': feature[FIELD_HUGO_SYMBOL], 'row': str(row_counter)})
              feature[FIELD_ENTREZ_ID] = None
          else:
              feature[FIELD_ENTREZ_ID] = str(entrez_gene_ids[0])
              feature[INTERNAL_ID] = "_".join(
                  [feature[FIELD_ENTREZ_ID], feature[PROTEIN_CHANGE], feature[VARIANT_CLASS]])
  
          row_number_to_feature[row_counter] = feature
      mutation_file.close()
      print(" DONE")
      return row_number_to_feature
function_tokens: def get_features ( mutation_file_path ) : header_elements = libImportOncokb . get_first_line_cells ( libImportOncokb . open_file ( mutation_file_path ) , '\t' ) header_indexes = { } for required_column in required_mutation_columns + [ FIELD_ENTREZ_ID ] : header_indexes [ required_column ] = header_elements . index ( required_column ) row_number_to_feature = { } row_counter = 0 mutation_file = libImportOncokb . open_file ( mutation_file_path ) print ( "Reading features from file ..." , end = '' ) for line in mutation_file : row_counter += 1 if line == '\n' or line . startswith ( '#' ) or line . startswith ( header_elements [ 0 ] ) : continue # skip comment and header line line_elements = line . rstrip ( ) . split ( '\t' ) feature = { } for column_name , index in header_indexes . items ( ) : value = line_elements [ index ] if value != '' : if column_name == PROTEIN_CHANGE : value = value . replace ( 'p.' , '' ) feature [ column_name ] = value elif column_name != FIELD_ENTREZ_ID and column_name != PROTEIN_POSITION and column_name != PROTEIN_CHANGE : raise RuntimeError ( "Empty value encountered in column '" + column_name + "' in row " + str ( row_counter ) + "." "OncoKB annotations cannot be imported. Please fix and rerun." ) # skip lines that have empty protein change column if PROTEIN_CHANGE not in feature : continue # resolve gene symbols to Entrez Ids if needed if FIELD_ENTREZ_ID in feature and feature [ FIELD_ENTREZ_ID ] is not None and feature [ FIELD_ENTREZ_ID ] != '' : entrez_gene_ids = [ feature [ FIELD_ENTREZ_ID ] ] else : entrez_gene_ids = portal_instance . hugo_entrez_map [ feature [ FIELD_HUGO_SYMBOL ] ] if len ( entrez_gene_ids ) > 1 : logger . error ( """ Multiple Entrez gene ids were found for a gene.
                               OncoKB annotations will not be imported for this gene.
                               Please fix and rerun. """ , extra = { 'symbol' : feature [ FIELD_HUGO_SYMBOL ] , 'row' : str ( row_counter ) } ) feature [ FIELD_ENTREZ_ID ] = None elif len ( entrez_gene_ids ) == 0 : logger . error ( """ Could not find the Entrez gene id for a gene.
                               OncoKB annotations will not be imported for this gene.
                               Please fix and rerun. """ , extra = { 'symbol' : feature [ FIELD_HUGO_SYMBOL ] , 'row' : str ( row_counter ) } ) feature [ FIELD_ENTREZ_ID ] = None else : feature [ FIELD_ENTREZ_ID ] = str ( entrez_gene_ids [ 0 ] ) feature [ INTERNAL_ID ] = "_" . join ( [ feature [ FIELD_ENTREZ_ID ] , feature [ PROTEIN_CHANGE ] , feature [ VARIANT_CLASS ] ] ) row_number_to_feature [ row_counter ] = feature mutation_file . close ( ) print ( " DONE" ) return row_number_to_feature