text
stringlengths 0
828
|
---|
else:
|
self.current_id_meta = 1
|
if spectra:
|
c.execute('SELECT max(id) FROM library_spectra')
|
last_id_spectra = c.fetchone()[0]
|
if last_id_spectra:
|
self.current_id_spectra = last_id_spectra + 1
|
else:
|
self.current_id_spectra = 1
|
if spectra_annotation:
|
c.execute('SELECT max(id) FROM library_spectra_annotation')
|
last_id_spectra_annotation = c.fetchone()[0]
|
if last_id_spectra_annotation:
|
self.current_id_spectra_annotation = last_id_spectra_annotation + 1
|
else:
|
self.current_id_spectra_annotation = 1"
|
156,"def _parse_files(self, msp_pth, chunk, db_type, celery_obj=False):
|
""""""Parse the MSP files and insert into database
|
Args:
|
msp_pth (str): path to msp file or directory [required]
|
db_type (str): The type of database to submit to (either 'sqlite', 'mysql' or 'django_mysql') [required]
|
chunk (int): Chunks of spectra to parse data (useful to control memory usage) [required]
|
celery_obj (boolean): If using Django a Celery task object can be used to keep track on ongoing tasks
|
[default False]
|
""""""
|
if os.path.isdir(msp_pth):
|
c = 0
|
for folder, subs, files in sorted(os.walk(msp_pth)):
|
for msp_file in sorted(files):
|
msp_file_pth = os.path.join(folder, msp_file)
|
if os.path.isdir(msp_file_pth) or not msp_file_pth.lower().endswith(('txt', 'msp')):
|
continue
|
print('MSP FILE PATH', msp_file_pth)
|
self.num_lines = line_count(msp_file_pth)
|
# each file is processed separately but we want to still process in chunks so we save the number
|
# of spectra currently being processed with the c variable
|
with open(msp_file_pth, ""r"") as f:
|
c = self._parse_lines(f, chunk, db_type, celery_obj, c)
|
else:
|
self.num_lines = line_count(msp_pth)
|
with open(msp_pth, ""r"") as f:
|
self._parse_lines(f, chunk, db_type, celery_obj)
|
self.insert_data(remove_data=True, db_type=db_type)"
|
157,"def _parse_lines(self, f, chunk, db_type, celery_obj=False, c=0):
|
""""""Parse the MSP files and insert into database
|
Args:
|
f (file object): the opened file object
|
db_type (str): The type of database to submit to (either 'sqlite', 'mysql' or 'django_mysql') [required]
|
chunk (int): Chunks of spectra to parse data (useful to control memory usage) [required]
|
celery_obj (boolean): If using Django a Celery task object can be used to keep track on ongoing tasks
|
[default False]
|
c (int): Number of spectra currently processed (will reset to 0 after that chunk of spectra has been
|
inserted into the database
|
""""""
|
old = 0
|
for i, line in enumerate(f):
|
line = line.rstrip()
|
if i == 0:
|
old = self.current_id_meta
|
self._update_libdata(line)
|
if self.current_id_meta > old:
|
old = self.current_id_meta
|
c += 1
|
if c > chunk:
|
if celery_obj:
|
celery_obj.update_state(state='current spectra {}'.format(str(i)),
|
meta={'current': i, 'total': self.num_lines})
|
print(self.current_id_meta)
|
self.insert_data(remove_data=True, db_type=db_type)
|
self.update_source = False
|
c = 0
|
return c"
|
158,"def _update_libdata(self, line):
|
""""""Update the library meta data from the current line being parsed
|
Args:
|
line (str): The current line of the of the file being parsed
|
""""""
|
####################################################
|
# parse MONA Comments line
|
####################################################
|
# The mona msp files contain a ""comments"" line that contains lots of other information normally separated
|
# into by """"
|
if re.match('^Comment.*$', line, re.IGNORECASE):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.