Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple changes #160

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bu_isciii/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ def bioinfo_doc(
@click.option(
"-id",
"--initial_date",
default=False,
default=None,
help="The date from which start search (format 'YYYY-MM-DD')",
)
@click.option(
"-fd",
"--final_date",
default=False,
default=None,
help="The date from which end search (format 'YYYY-MM-DD')",
)
def archive(resolution, type, option, skip_prompts, initial_date, final_date):
Expand Down
13 changes: 9 additions & 4 deletions bu_isciii/conf/configuration.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"global":{
"data_path": "/data/bi"
"data_path": "/data/bi",
"archived_path": "/archived/bi"
},
"sftp_copy": {
"protocol": "rsync",
Expand Down Expand Up @@ -43,11 +44,15 @@
"fastq_repo": "/srv/fastq_repo"
},
"scratch_copy": {
"command": "rsync -rlv --exclude 'service_info.txt' --exclude 'work' --exclude '*_NC' "
"protocol": "rsync",
"options": ["-rlpv"],
"exclusions": [
"'*_NC'",
"'service_info.txt'",
"'work'"
]
},
"archive": {
"data_path": "/data/bi",
"archived_path": "/archived/bi",
"protocol": "rsync",
"options": ["-rv"]
}
Expand Down
2 changes: 1 addition & 1 deletion bu_isciii/drylab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, server, url, password):
self.request_url = server + url
self.headers = {
"content-type": "application/json",
"authorization": "Basic " + password,
"WWW-Authenticate": "Basic " + password,
}

# TODO: this is waaay too dirty, find a way to pass variable number of parameters and values.
Expand Down
44 changes: 23 additions & 21 deletions bu_isciii/new_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def __init__(
conf_api["server"], conf_api["api_url"], api_token
)
self.resolution_info = self.rest_api.get_request(
request_info="serviceFullData", safe=False, resolution=self.resolution_id
request_info="service-data", safe=False, resolution=self.resolution_id
)
self.service_folder = self.resolution_info["resolutions"][0][
"resolutionFullNumber"
"resolution_full_number"
]
self.services_requested = self.resolution_info["resolutions"][0][
"availableServices"
"available_services"
]
self.service_samples = self.resolution_info["samples"]

Expand Down Expand Up @@ -167,18 +167,19 @@ def create_samples_id(self):
"a",
encoding="utf-8",
) as f:
line = sample["sampleName"] + "\n"
line = sample["sample_name"] + "\n"
f.write(line)

def create_symbolic_links(self):
samples_files = []
for sample in self.service_samples:
regex = os.path.join(
self.conf["fastq_repo"], sample["projectName"], "{}*"
).format(sample["sampleName"])
self.conf["fastq_repo"], sample["project_name"], "{}_*"
).format(sample["sample_name"])
sample_file = glob.glob(regex)

if sample_file:
samples_files.appned(sample_file)
samples_files.append(sample_file)
else:
stderr.print(
"[red] This regex has not output any file: %s. This maybe because the project is not yet in the fastq repo or because some of the samples are not in the project."
Expand All @@ -198,19 +199,20 @@ def create_symbolic_links(self):
):
stderr.print("Bye!")
sys.exit()
for file in samples_files:
try:
os.symlink(
file,
os.path.join(self.full_path, "RAW", os.path.basename(file)),
)
except OSError as e:
stderr.print(
"[red]ERROR: Symbolic links creation failed for sample %s."
% sample["sampleName"]
)
stderr.print("Traceback: %s" % e)
sys.exit()
for sample in samples_files:
for file in sample:
try:
os.symlink(
file,
os.path.join(self.full_path, "RAW", os.path.basename(file)),
)
except OSError as e:
stderr.print(
"[red]ERROR: Symbolic links creation failed for sample %s."
% sample["sampleName"]
)
stderr.print("Traceback: %s" % e)
sys.exit()

def samples_json(self):
json_samples = json.dumps(self.service_samples, indent=4)
Expand All @@ -229,7 +231,7 @@ def create_new_service(self):
self.create_symbolic_links()
self.samples_json()
self.rest_api.put_request(
"updateState", "resolution", self.resolution_id, "state", "In%20Progress"
"update-state", "resolution", self.resolution_id, "state", "in_progress"
)

def get_resolution_id(self):
Expand Down
21 changes: 13 additions & 8 deletions bu_isciii/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Local imports
import bu_isciii
import bu_isciii.utils
from bu_isciii.drylab_api import RestServiceApi
import bu_isciii.drylab_api
import bu_isciii.config_json

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,18 +54,21 @@ def __init__(
self.direction = direction

# Load conf
conf_api = bu_isciii.config_json.ConfigJson().get_configuration(
"xtutatis_api_settings"
)
conf_api = bu_isciii.config_json.ConfigJson().get_configuration("api_settings")
# Obtain info from iskylims api
rest_api = RestServiceApi(conf_api["server"], conf_api["api_url"], api_token)
rest_api = bu_isciii.drylab_api.RestServiceApi(
conf_api["server"],
conf_api["api_url"],
api_token,
)
self.conf = bu_isciii.config_json.ConfigJson().get_configuration("scratch_copy")
self.rsync_command = self.conf["command"]

self.resolution_info = rest_api.get_request(
request_info="serviceFullData", safe=False, resolution=self.resolution_id
request_info="resolutionFullData", safe=False, resolution=self.resolution_id
)
self.service_folder = self.resolution_info["resolutions"][0][

self.service_folder = self.resolution_info["resolutions"][
"resolutionFullNumber"
]
self.scratch_path = os.path.join(self.tmp_dir, self.service_folder)
Expand All @@ -89,7 +92,9 @@ def __init__(
)
sys.exit()
else:
self.path = bu_isciii.utils.get_service_paths(self.resolution_info)
self.path = bu_isciii.utils.get_service_paths(
"services_and_colaborations", self.resolution_info, "non_archived_path"
)

self.full_path = os.path.join(self.path, self.service_folder)

Expand Down
37 changes: 25 additions & 12 deletions bu_isciii/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def get_service_ids(services_requested):
service_id_list = []
service_id_list_all = []
for services in services_requested:
if services["serviceId"] is not None:
service_id_list.append(services["serviceId"])
service_id_list_all.append(services["serviceId"])
if services["service_id"] is not None:
service_id_list.append(services["service_id"])
service_id_list_all.append(services["service_id"])
service_id_list_all.append("all")
stderr.print("Which selected service do you want to manage?")
services_sel = [prompt_selection("Service label:", service_id_list_all)]
Expand All @@ -170,20 +170,33 @@ def ask_password(msg):
return password


def get_service_paths(resolution_info):
def get_service_paths(service_type, resolution_info, archived_status):
"""
Given a service, a conf and a type,
get the path it would have service
"""
global_conf = bu_isciii.config_json.ConfigJson().get_configuration("global")
service_path = os.path.join(
global_conf["data_path"],
"services_and_colaborations",
resolution_info["serviceUserId"]["profile"]["profileCenter"],
resolution_info["serviceUserId"]["profile"][
"profileClassificationArea"
].lower(),
)
service_path = None

if service_type == "services_and_colaborations":
if archived_status == "archived_path":
service_path = os.path.join(
global_conf["archived_path"],
service_type,
resolution_info["serviceUserId"]["profile"]["profileCenter"],
resolution_info["serviceUserId"]["profile"][
"profileClassificationArea"
].lower(),
)
if archived_status == "non_archived_path":
service_path = os.path.join(
global_conf["data_path"],
service_type,
resolution_info["Service"]["serviceUserId"]["profile"]["profileCenter"],
resolution_info["serviceUserId"]["profile"][
"profileClassificationArea"
].lower(),
)
return service_path


Expand Down
Loading