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

Put filepaths #177

Merged
merged 5 commits into from
Jan 29, 2024
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
6 changes: 5 additions & 1 deletion src/dissectBCL/drHouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ def initClass(
muxDF = pd.read_csv(muxPath)
totalReads = int(muxDF['# Reads'].sum())
if len(muxDF[muxDF['SampleID'] == 'Undetermined']) == 1:
undReads = int(muxDF[muxDF['SampleID'] == 'Undetermined']['# Reads'])
undReads = int(
muxDF[
muxDF['SampleID'] == 'Undetermined'
]['# Reads'].iloc[0]
)
else:
undDic = dict(
muxDF[
Expand Down
141 changes: 75 additions & 66 deletions src/wd40/release.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
import os
import requests
from subprocess import check_output
import sys
import glob
from pathlib import Path
from rich import print


def fetchLatestSeqDir(pref, PI, postfix):
globStr = os.path.join(
pref,
PI,
postfix + '*'
)
globStr = os.path.join(pref, PI, postfix + "*")
if len(glob.glob(globStr)) == 1:
return glob.glob(globStr)[0]
else:
maxFolder = 0
for seqDir in glob.glob(
os.path.join(
pref,
PI,
postfix + '*'
)
):
for seqDir in glob.glob(os.path.join(pref, PI, postfix + "*")):
try:
seqInt = int(seqDir[-1])
except ValueError:
seqInt = 0
continue
if seqInt > maxFolder:
maxFolder = seqInt
return (os.path.join(
pref,
PI,
postfix + str(maxFolder)
))
return os.path.join(pref, PI, postfix + str(maxFolder))


def fetchFolders(flowcellPath, piList, prefix, postfix):
institute_PIs = piList
flowcellPath = os.path.abspath(flowcellPath)
FID = flowcellPath.split('/')[-1]
FID = flowcellPath.split("/")[-1]
projDic = {}
try:
int(FID[:6])
Expand All @@ -48,33 +36,26 @@ def fetchFolders(flowcellPath, piList, prefix, postfix):
sys.exit(
"First 6 digits of flowcellpath don't convert to an int. Exiting."
)
for projF in glob.glob(
os.path.join(
flowcellPath,
'Project_*'
)
):
proj = projF.split('/')[-1]
for projF in glob.glob(os.path.join(flowcellPath, "Project_*")):
proj = projF.split("/")[-1]
PI = proj.split("_")[-1].lower()
if PI == 'cabezas-wallscheid':
PI = 'cabezas'
if PI == "cabezas-wallscheid":
PI = "cabezas"
if PI in institute_PIs:
seqFolder = fetchLatestSeqDir(prefix, PI, postfix)
if os.path.exists(
os.path.join(seqFolder, FID)
):
if os.path.exists(os.path.join(seqFolder, FID)):
projDic[proj] = [
PI + 'grp',
PI + "grp",
[
os.path.join(seqFolder, FID),
os.path.join(seqFolder, FID, proj),
os.path.join(seqFolder, FID, 'FASTQC_' + proj),
os.path.join(seqFolder, FID, "FASTQC_" + proj),
os.path.join(
seqFolder,
FID,
'Analysis_' + proj.replace('Project_', '')
)
]
"Analysis_" + proj.replace("Project_", ""),
),
],
]
else:
print(
Expand Down Expand Up @@ -107,12 +88,8 @@ def release_folder(grp, lis):
succes_fqc = release_rights(fastqcF, grp)
if os.path.exists(analysisF):
succes_analysis = release_rights(analysisF, grp)
return (
[succes_project, succes_fqc, succes_analysis]
)
return (
[succes_project, succes_fqc]
)
return [succes_project, succes_fqc, succes_analysis]
return [succes_project, succes_fqc]


def release_rights(F, grp):
Expand All @@ -122,10 +99,7 @@ def release_rights(F, grp):
for r, dirs, files in os.walk(F):
for d in dirs:
try:
os.chmod(
os.path.join(r, d),
0o750
)
os.chmod(os.path.join(r, d), 0o750)
changed += 1
except PermissionError:
print("Permission error for {}".format(d))
Expand All @@ -136,10 +110,7 @@ def release_rights(F, grp):
if grp != Path(fil).group():
grouperror = True
try:
os.chmod(
fil,
0o750
)
os.chmod(fil, 0o750)
changed += 1
except PermissionError:
print("Permission error for {}".format(f))
Expand All @@ -151,37 +122,75 @@ def release_rights(F, grp):
F
)
)
return (successRate)
return successRate


def rel(flowcellPath, piList, prefix, postfix):
projDic = fetchFolders(
flowcellPath,
piList,
prefix,
postfix
)
def rel(
flowcellPath,
piList,
prefix,
postfix,
parkourURL,
parkourAuth,
parkourCert,
fexBool,
fromAddress,
):
projDic = fetchFolders(flowcellPath, piList, prefix, postfix)
print("Print number of changed/(changed+unchanged)!")
for proj in projDic:
'''
"""
every projDic[proj] is a nested list of:
[grp, [flowcell, project, fastqc]]
'''
"""
successes = release_folder(projDic[proj][0], projDic[proj][1])
if len(successes) == 2:
print(
"[green]Project[/green] {},{} proj,{} fqc".format(
proj,
successes[0],
successes[1]
proj, successes[0], successes[1]
)
)
else:
print(
"[green]Project[/green] {},{} proj,{} fqc,{} analysis".format(
proj,
successes[0],
successes[1],
successes[2]
proj, successes[0], successes[1], successes[2]
)
)
projectPath = projDic[proj][1][1].split("/")[-1]
PI = (
projectPath.split("_")[-1]
.lower()
.replace("cabezas-wallscheid", "cabezas")
)
d = None
if PI in piList:
d = {
"data": projDic[proj][1][1],
"metadata": projDic[proj][1][1] + "/multiqc_report.html",
}
elif fexBool:
fexList = (
check_output(["fexsend", "-l", fromAddress])
.decode("utf-8")
.replace("\n", " ")
.split(" ")
)
tar_lane, tar_proj = projDic[proj][1][1].split("/")[-2:]
tarBall = tar_lane + "_" + tar_proj + ".tar"
if tarBall in fexList:
d = {"data": tarBall, "metadata": None}
else:
print("fexLink: ", tarBall, " not found!")
if d:
print(
"Adding filepaths to Parkour2:",
requests.post(
parkourURL
+ "/api/requests/"
+ proj.split("_")[1]
+ "/put_filepaths/",
auth=parkourAuth,
data=d,
verify=parkourCert,
),
) # print the returned answer from the API
15 changes: 14 additions & 1 deletion src/wd40/wd40.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def cli(ctx, configpath, debug):
ctx.obj['postfixDir'] = cnf['Internals']['seqDir']
ctx.obj['fastqDir'] = cnf['Dirs']['outputDir']
ctx.obj['solDir'] = cnf['Dirs']['baseDir']
ctx.obj['parkourURL'] = cnf['parkour']['URL']
ctx.obj['parkourAuth'] = (
cnf['parkour']['user'],
cnf['parkour']['password']
)
ctx.obj['parkourCert'] = cnf['parkour']['cert']
ctx.obj['fexBool'] = cnf['Internals'].getboolean('fex')
ctx.obj['fromAddress'] = cnf['communication']['fromAddress']


@cli.command()
Expand All @@ -88,7 +96,12 @@ def rel(ctx, flowcell):
flowcell,
ctx.obj['piList'],
ctx.obj['prefixDir'],
ctx.obj['postfixDir']
ctx.obj['postfixDir'],
ctx.obj['parkourURL'],
ctx.obj['parkourAuth'],
ctx.obj['parkourCert'],
ctx.obj['fexBool'],
ctx.obj['fromAddress']
)


Expand Down
Loading