text
stringlengths 0
828
|
---|
The constructed YAML value from the name of the enumerated value. |
"""""" |
# mypy doesn't like indexing to construct the enumeration. |
return cls[node.value]" |
153,"def is_error(self): |
"""""" Checks to see if the job errored out. """""" |
try: |
if self._task.is_alive(): |
if len(self._task.stderr.readlines()) > 0: |
self._task.join() |
self._write_log() |
return True |
except AttributeError: |
pass |
return False" |
154,"def add_splash_ids(splash_mapping_file_pth, conn, db_type='sqlite'): |
"""""" Add splash ids to database (in case stored in a different file to the msp files like for MoNA) |
Example: |
>>> from msp2db.db import get_connection |
>>> from msp2db.parse import add_splash_ids |
>>> conn = get_connection('sqlite', 'library.db') |
>>> add_splash_ids('splash_mapping_file.csv', conn, db_type='sqlite') |
Args: |
splash_mapping_file_pth (str): Path to the splash mapping file (needs to be csv format and have no headers, |
should contain two columns. The first the accession number the second the splash. |
e.g. AU100601, splash10-0a4i-1900000000-d2bc1c887f6f99ed0f74 \n |
"""""" |
# get dictionary of accession and library_spectra_meta_id |
cursor = conn.cursor() |
cursor.execute(""SELECT id, accession FROM library_spectra_meta"") |
accession_d = {row[1]: row[0] for row in cursor} |
if db_type == 'sqlite': |
type_sign = '?' |
else: |
type_sign = '%s' |
rows = [] |
c = 0 |
# loop through splash mapping file |
with open(splash_mapping_file_pth, ""r"") as f: |
for line in f: |
c+=1 |
line = line.rstrip() |
line_l = line.split(',') |
accession = line_l[0] |
splash = line_l[1] |
try: |
aid = accession_d[accession] |
except KeyError as e: |
print(""can't find accession {}"".format(accession)) |
continue |
row = (splash, aid) |
rows.append(row) |
if c > 200: |
print(row) |
cursor.executemany(""UPDATE library_spectra_meta SET splash = {t} WHERE id = {t} "".format(t=type_sign), rows) |
conn.commit() |
rows = [] |
c = 0 |
cursor.executemany(""UPDATE library_spectra_meta SET splash = {t} WHERE id = {t} "".format(t=type_sign), rows) |
conn.commit()" |
155,"def _get_current_ids(self, source=True, meta=True, spectra=True, spectra_annotation=True): |
""""""Get the current id for each table in the database |
Args: |
source (boolean): get the id for the table ""library_spectra_source"" will update self.current_id_origin |
meta (boolean): get the id for the table ""library_spectra_meta"" will update self.current_id_meta |
spectra (boolean): get the id for the table ""library_spectra"" will update self.current_id_spectra |
spectra_annotation (boolean): get the id for the table ""library_spectra_annotation"" will update |
self.current_id_spectra_annotation |
"""""" |
# get the cursor for the database connection |
c = self.c |
# Get the last uid for the spectra_info table |
if source: |
c.execute('SELECT max(id) FROM library_spectra_source') |
last_id_origin = c.fetchone()[0] |
if last_id_origin: |
self.current_id_origin = last_id_origin + 1 |
else: |
self.current_id_origin = 1 |
if meta: |
c.execute('SELECT max(id) FROM library_spectra_meta') |
last_id_meta = c.fetchone()[0] |
if last_id_meta: |
self.current_id_meta = last_id_meta + 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.