text
stringlengths 0
828
|
---|
comments = re.findall('""([^""]*)""', line) |
for c in comments: |
self._parse_meta_info(c) |
self._parse_compound_info(c) |
#################################################### |
# parse meta and compound info lines |
#################################################### |
# check the current line for both general meta data |
# and compound information |
self._parse_meta_info(line) |
self._parse_compound_info(line) |
#################################################### |
# End of meta data |
#################################################### |
# Most MSP files have the a standard line of text before the spectra information begins. Here we check |
# for this line and store the relevant details for the compound and meta information to be ready for insertion |
# into the database |
if self.collect_meta and (re.match('^Num Peaks(.*)$', line, re.IGNORECASE) or re.match('^PK\$PEAK:(.*)', line, |
re.IGNORECASE) or re.match('^PK\$ANNOTATION(.*)', line, re.IGNORECASE)): |
self._store_compound_info() |
self._store_meta_info() |
# Reset the temp meta and compound information |
self.meta_info = get_blank_dict(self.meta_regex) |
self.compound_info = get_blank_dict(self.compound_regex) |
self.other_names = [] |
self.collect_meta = False |
# ignore additional information in the 3rd column if using the MassBank spectra schema |
if re.match('^PK\$PEAK: m/z int\. rel\.int\.$', line, re.IGNORECASE): |
self.ignore_additional_spectra_info = True |
# Check if annnotation or spectra is to be in the next lines to be parsed |
if re.match('^Num Peaks(.*)$', line, re.IGNORECASE) or re.match('^PK\$PEAK:(.*)', line, re.IGNORECASE): |
self.start_spectra = True |
return |
elif re.match('^PK\$ANNOTATION(.*)', line, re.IGNORECASE): |
self.start_spectra_annotation = True |
match = re.match('^PK\$ANNOTATION:(.*)', line, re.IGNORECASE) |
columns = match.group(1) |
cl = columns.split() |
self.spectra_annotation_indexes = {i: cl.index(i) for i in cl} |
return |
#################################################### |
# Process annotation details |
#################################################### |
# e.g. molecular formula for each peak in the spectra |
if self.start_spectra_annotation: |
self._parse_spectra_annotation(line) |
#################################################### |
# Process spectra |
#################################################### |
if self.start_spectra: |
self._parse_spectra(line)" |
159,"def get_compound_ids(self): |
""""""Extract the current compound ids in the database. Updates the self.compound_ids list |
"""""" |
cursor = self.conn.cursor() |
cursor.execute('SELECT inchikey_id FROM metab_compound') |
self.conn.commit() |
for row in cursor: |
if not row[0] in self.compound_ids: |
self.compound_ids.append(row[0])" |
160,"def _store_compound_info(self): |
""""""Update the compound_info dictionary with the current chunk of compound details |
Note that we use the inchikey as unique identifier. If we can't find an appropiate inchikey we just use |
a random string (uuid4) suffixed with UNKNOWN |
"""""" |
other_name_l = [name for name in self.other_names if name != self.compound_info['name']] |
self.compound_info['other_names'] = ' <#> '.join(other_name_l) |
if not self.compound_info['inchikey_id']: |
self._set_inchi_pcc(self.compound_info['pubchem_id'], 'cid', 0) |
if not self.compound_info['inchikey_id']: |
self._set_inchi_pcc(self.compound_info['smiles'], 'smiles', 0) |
if not self.compound_info['inchikey_id']: |
self._set_inchi_pcc(self.compound_info['name'], 'name', 0) |
if not self.compound_info['inchikey_id']: |
print('WARNING, cant get inchi key for ', self.compound_info) |
print(self.meta_info) |
print('#########################') |
self.compound_info['inchikey_id'] = 'UNKNOWN_' + str(uuid.uuid4()) |
if not self.compound_info['pubchem_id'] and self.compound_info['inchikey_id']: |
self._set_inchi_pcc(self.compound_info['inchikey_id'], 'inchikey', 0) |
if not self.compound_info['name']: |
self.compound_info['name'] = 'unknown name' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.