Skip to content

Commit

Permalink
fix the bug in index.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cl117 committed Aug 29, 2024
1 parent ccad037 commit 383359a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion flask/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def write_fasta(sequences):

def run_uclust():
args = [usearch_binary_filename, '-cluster_fast', sequences_filename, '-id', uclust_identity, '-sort', 'length', '-uc', uclust_results_filename]
result = subprocess.run(args, capture_output=True, text=True)
# result = subprocess.run(args, capture_output=True, text=True) # Python3.7
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
logger_.log(result.stdout, True)

def analyze_uclust():
Expand Down
35 changes: 23 additions & 12 deletions flask/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ def add_roles(parts_response, term_list):
if so_term in term['id']:
keywords_list.append(term['lbl'])
synonyms = term.get('synonyms', [])
for synonym in synonyms:
# remove the annoying header from the synonyms
if 'INSDC' in synonym:
synonym = synonym.replace('INSDC_qualifier:', '')
if synonym not in keywords_list:
keywords_list.append(synonym)
if synonyms:
for synonym in synonyms:
# remove the annoying header from the synonyms
if 'INSDC' in synonym:
synonym = synonym.replace('INSDC_qualifier:', '')
if synonym not in keywords_list:
keywords_list.append(synonym)

part['keywords'] += ' ' + ' '.join(keywords_list)

Expand Down Expand Up @@ -93,16 +94,25 @@ def create_parts_index(index_name):

body = {
'mappings': {
'properties': {
'subject': {'type': 'keyword'},
'graph': {'type': 'keyword'}
index_name: {
'properties': {
'subject': {
'type': 'keyword'
},
'graph': {
'type': 'keyword'
}
},
}
},
'settings': {
'number_of_shards': 1
}
}
logger_.log("index_name: ", index_name) # empty
logger_.log("body: ", body) # empty
es.indices.create(index=index_name, body=body)

logger_.log('Index created', True)


Expand All @@ -120,6 +130,7 @@ def actions():
for part in parts_response:
yield {
'_index': index_name,
'_type': index_name,
'_id': part['subject'],
'_source': part
}
Expand Down Expand Up @@ -178,20 +189,20 @@ def delete_subject(subject):
'query': {
'bool': {
'must': [
{'ids': {'values': [subject]}}
{'ids': {'values': subject}}
]
}
},
'conflicts': 'proceed'
}
es.delete_by_query(index=index_name, body=body)
es.delete_by_query(index=index_name, doc_type=index_name, body=body)


def index_part(part):
delete_subject(part['subject'])
index_name = config['elasticsearch_index_name']
es = elasticsearch_manager.get_es()
es.index(index=index_name, id=part['subject'], body=part)
es.index(index=index_name, doc_type=index_name, id=part['subject'], body=part)


def refresh_index(subject, uri2rank):
Expand Down

0 comments on commit 383359a

Please sign in to comment.