Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
PauAndrio committed Oct 22, 2024
1 parent 72b279f commit eff6555
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Files too big to be stored in gitTHGA_K.cdi

.gitignore
__pycache__/
*.py[cod]
Expand Down
4 changes: 2 additions & 2 deletions biobb_dna/curvesplus/biobb_canal.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def launch(self) -> int:

# change directory to temporary folder
original_directory = os.getcwd()
os.chdir(self.stage_io_dict.get("unique_dir"))
os.chdir(self.stage_io_dict.get("unique_dir", ""))

# create intructions
instructions = [
Expand Down Expand Up @@ -174,7 +174,7 @@ def launch(self) -> int:
# create zipfile and write output inside
zf = zipfile.ZipFile(
Path(self.stage_io_dict["out"]["output_zip_path"]), "w")
for canal_outfile in Path(self.stage_io_dict.get("unique_dir")).glob("canal_output*"):
for canal_outfile in Path(self.stage_io_dict.get("unique_dir", "")).glob("canal_output*"):
if canal_outfile.suffix not in (".zip"):
zf.write(
canal_outfile,
Expand Down
4 changes: 2 additions & 2 deletions biobb_dna/curvesplus/biobb_canion.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def launch(self) -> int:

# change directory to temporary folder
original_directory = os.getcwd()
os.chdir(self.stage_io_dict.get("unique_dir"))
os.chdir(self.stage_io_dict.get("unique_dir", ""))

# create intructions
instructions = [
Expand Down Expand Up @@ -187,7 +187,7 @@ def launch(self) -> int:
zf = zipfile.ZipFile(
Path(self.stage_io_dict["out"]["output_zip_path"]),
"w")
for curves_outfile in Path(self.stage_io_dict.get("unique_dir")).glob("canion_output*"):
for curves_outfile in Path(self.stage_io_dict.get("unique_dir", "")).glob("canion_output*"):
if curves_outfile.suffix not in (".zip"):
zf.write(curves_outfile, arcname=curves_outfile.name)
zf.close()
Expand Down
16 changes: 8 additions & 8 deletions biobb_dna/curvesplus/biobb_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(
def create_curvesplus_folder(self):
"""Create .curvesplus folder in the current temporal folder and copy the lib files inside."""
# Create .curvesplus directory in temporary folder
dst_dir = self.stage_io_dict.get("unique_dir") + '/.curvesplus'
dst_dir = self.stage_io_dict.get("unique_dir", "") + '/.curvesplus'
os.makedirs(dst_dir, exist_ok=True)
# Get lib files from stdlib_path
lib_files = list(Path(os.path.dirname(self.stdlib_path)).glob("*.lib"))
Expand Down Expand Up @@ -140,7 +140,7 @@ def launch(self) -> int:
if self.stdlib_path is None:
if os.getenv("CONDA_PREFIX", False):
curves_aux_path = Path(
os.getenv("CONDA_PREFIX")) / ".curvesplus"
os.getenv("CONDA_PREFIX", "")) / ".curvesplus"
# check if .curvesplus directory is in $CONDA_PREFIX
if curves_aux_path.exists():
if len(list(curves_aux_path.glob("standard_*.lib"))) != 3:
Expand All @@ -157,7 +157,7 @@ def launch(self) -> int:
"Please indicate where standard_*.lib files are "
"located with the stdlib_path property.")
# copy standard library files to temporary folder
shutil.copytree(curves_aux_path, self.stage_io_dict.get("unique_dir") + '/.curvesplus')
shutil.copytree(curves_aux_path, self.stage_io_dict.get("unique_dir", "") + '/.curvesplus')
relative_lib_path = '.curvesplus/standard'
else:
# CONDA_PREFIX undefined
Expand All @@ -171,12 +171,12 @@ def launch(self) -> int:
# create .curvesplus folder in the current temporal folder and copy the lib files inside
self.create_curvesplus_folder()
# set relative path
path_parts = self.stdlib_path.split(os.sep)
path_parts = str(self.stdlib_path).split(os.sep)
relative_lib_path = '.curvesplus/' + os.sep.join(path_parts[-1:])

# change directory to temporary folder
original_directory = os.getcwd()
os.chdir(self.stage_io_dict.get("unique_dir"))
os.chdir(self.stage_io_dict.get("unique_dir", ""))

# define temporary file names
tmp_struc_input = Path(self.stage_io_dict['in']['input_struc_path']).name
Expand Down Expand Up @@ -226,17 +226,17 @@ def launch(self) -> int:
zf = zipfile.ZipFile(
Path(self.stage_io_dict["out"]["output_zip_path"]),
"w")
for curves_outfile in Path(self.stage_io_dict.get("unique_dir")).glob("curves_output*"):
for curves_outfile in Path(self.stage_io_dict.get("unique_dir", "")).glob("curves_output*"):
if curves_outfile.suffix not in (".cda", ".lis", ".zip"):
zf.write(
curves_outfile,
arcname=curves_outfile.name)
zf.close()

# rename cda and lis files
(Path(self.stage_io_dict.get("unique_dir")) / "curves_output.cda").rename(
(Path(self.stage_io_dict.get("unique_dir", "")) / "curves_output.cda").rename(
self.stage_io_dict["out"]["output_cda_path"])
(Path(self.stage_io_dict.get("unique_dir")) / "curves_output.lis").rename(
(Path(self.stage_io_dict.get("unique_dir", "")) / "curves_output.lis").rename(
self.stage_io_dict["out"]["output_lis_path"])

# Copy files to host
Expand Down
4 changes: 2 additions & 2 deletions biobb_dna/dna/dna_bimodality.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ def launch(self) -> int:

# change directory to temporary folder
original_directory = os.getcwd()
os.chdir(self.stage_io_dict.get("unique_dir"))
os.chdir(self.stage_io_dict.get("unique_dir", ""))

# read input
if self.stage_io_dict.get("in", {}).get("input_zip_file") is not None:
# if zipfile is specified, extract to temporary folder
with zipfile.ZipFile(
self.stage_io_dict['in']['input_zip_file'],
'r') as zip_ref:
zip_ref.extractall(self.stage_io_dict.get("unique_dir"))
zip_ref.extractall(self.stage_io_dict.get("unique_dir", ""))

data = load_data(Path(self.stage_io_dict['in']['input_csv_file']).name)

Expand Down
16 changes: 8 additions & 8 deletions biobb_dna/dna/dna_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ def launch(self) -> int:
# column series
series_colfn = f"series_{self.helpar_name}_{col}"
column_data.to_csv(
Path(self.stage_io_dict.get("unique_dir")) / f"{series_colfn}.csv")
Path(self.stage_io_dict.get("unique_dir", "")) / f"{series_colfn}.csv")
# save table
zf.write(
Path(self.stage_io_dict.get("unique_dir")) / f"{series_colfn}.csv", arcname=f"{series_colfn}.csv")
Path(self.stage_io_dict.get("unique_dir", "")) / f"{series_colfn}.csv", arcname=f"{series_colfn}.csv")

fig, axs = plt.subplots(1, 1, dpi=300, tight_layout=True)
reduced_data = column_data.iloc[::self.stride]
Expand All @@ -229,32 +229,32 @@ def launch(self) -> int:
"(base pair "
f"{'step' if self.baselen==1 else ''} {col})")
fig.savefig(
Path(self.stage_io_dict.get("unique_dir")) / f"{series_colfn}.jpg", format="jpg")
Path(self.stage_io_dict.get("unique_dir", "")) / f"{series_colfn}.jpg", format="jpg")
# save plot
zf.write(
Path(self.stage_io_dict.get("unique_dir")) / f"{series_colfn}.jpg", arcname=f"{series_colfn}.jpg")
Path(self.stage_io_dict.get("unique_dir", "")) / f"{series_colfn}.jpg", arcname=f"{series_colfn}.jpg")
plt.close()

# columns histogram
hist_colfn = f"hist_{self.helpar_name}_{col}"
fig, axs = plt.subplots(1, 1, dpi=300, tight_layout=True)
ybins, x, _ = axs.hist(column_data, bins=self.bins)
pd.DataFrame({self.helpar_name: x[:-1], "density": ybins}).to_csv(
Path(self.stage_io_dict.get("unique_dir")) / f"{hist_colfn}.csv",
Path(self.stage_io_dict.get("unique_dir", "")) / f"{hist_colfn}.csv",
index=False)
# save table
zf.write(
Path(self.stage_io_dict.get("unique_dir")) / f"{hist_colfn}.csv",
Path(self.stage_io_dict.get("unique_dir", "")) / f"{hist_colfn}.csv",
arcname=f"{hist_colfn}.csv")

axs.set_ylabel("Density")
axs.set_xlabel(f"{self.helpar_name.capitalize()} ({self.hp_unit})")
fig.savefig(
Path(self.stage_io_dict.get("unique_dir")) / f"{hist_colfn}.jpg",
Path(self.stage_io_dict.get("unique_dir", "")) / f"{hist_colfn}.jpg",
format="jpg")
# save plot
zf.write(
Path(self.stage_io_dict.get("unique_dir")) / f"{hist_colfn}.jpg",
Path(self.stage_io_dict.get("unique_dir", "")) / f"{hist_colfn}.jpg",
arcname=f"{hist_colfn}.jpg")
plt.close()
zf.close()
Expand Down

0 comments on commit eff6555

Please sign in to comment.