-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsequencer_interface.py
More file actions
76 lines (66 loc) · 3.12 KB
/
Copy pathsequencer_interface.py
File metadata and controls
76 lines (66 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import logging
import os
class SequencerInterface:
"""Class to interface with DNA sequencers."""
def __init__(self, sequencer_url):
self.sequencer_url = sequencer_url
self.logger = self.setup_logging()
def setup_logging(self):
"""Set up logging for the sequencer interface."""
logger = logging.getLogger("SequencerInterface")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
def start_sequencing(self, experiment_id, sample_data):
"""Start the sequencing process for a given experiment."""
payload = {
"experiment_id": experiment_id,
"sample_data": sample_data
}
try:
response = requests.post(f"{self.sequencer_url}/start", json=payload)
response.raise_for_status() # Raise an error for bad responses
self.logger.info("Sequencing started for experiment %s", experiment_id)
return response.json()
except requests.exceptions.RequestException as e:
self.logger.error("Failed to start sequencing: %s", str(e))
return {"error": "Failed to start sequencing"}
def get_results(self, experiment_id):
"""Get the sequencing results for a given experiment."""
try:
response = requests.get(f"{self.sequencer_url}/results/{experiment_id}")
response.raise_for_status() # Raise an error for bad responses
self.logger.info("Retrieved results for experiment %s", experiment_id)
return response.json()
except requests.exceptions.RequestException as e:
self.logger.error("Failed to retrieve results: %s", str(e))
return {"error": "Failed to retrieve results"}
def check_status(self, experiment_id):
"""Check the status of a sequencing experiment."""
try:
response = requests.get(f"{self.sequencer_url}/status/{experiment_id}")
response.raise_for_status() # Raise an error for bad responses
self.logger.info("Checked status for experiment %s", experiment_id)
return response.json()
except requests.exceptions.RequestException as e:
self.logger.error("Failed to check status: %s", str(e))
return {"error": "Failed to check status"}
# Example usage
if __name__ == "__main__":
sequencer_url = os.getenv("SEQUENCER_URL", "http://localhost:5000") # Default to localhost
sequencer = SequencerInterface(sequencer_url)
# Start a sequencing experiment
experiment_id = 1
sample_data = {"DNA_sequence": "ATCGTAGCTAGCTAGCTAGC"}
start_response = sequencer.start_sequencing(experiment_id, sample_data)
print(start_response)
# Check the status of the experiment
status_response = sequencer.check_status(experiment_id)
print(status_response)
# Retrieve results of the experiment
results_response = sequencer.get_results(experiment_id)
print(results_response)