Skip to content

Commit

Permalink
Merge pull request #305 from kedhammar/fix-anglerfish-df
Browse files Browse the repository at this point in the history
Update Anglerfish parsing to handle runs w/o ONT barcodes
  • Loading branch information
kedhammar authored Jan 31, 2024
2 parents 8c2657e + 380ab38 commit 631c48a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions VERSIONLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Scilifelab_epps Version Log

## 20240130.1

Handle Anglerfish result parsing for runs W/O ONT barcodes

## 20240126.1

Discover latest anglerfish run even if embedded in subdir of run dir
Expand Down
29 changes: 19 additions & 10 deletions scripts/parse_anglerfish_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def find_latest_flowcell_run(currentStep: Process) -> str:

def find_latest_anglerfish_run(latest_flowcell_run_path: str) -> str:
anglerfish_query = f"{latest_flowcell_run_path}/**/anglerfish_run*"
anglerfish_glob = glob.glob(anglerfish_query)
anglerfish_glob = glob.glob(anglerfish_query, recursive=True)

assert (
len(anglerfish_glob) != 0
Expand Down Expand Up @@ -88,7 +88,9 @@ def parse_data(df_raw: pd.DataFrame):
# Sample reads divided by sum of all sample reads w. the same barcode
lambda row: row["num_reads"]
/ df[df["ont_barcode"] == row["ont_barcode"]]["num_reads"].sum()
* 100,
* 100
if not pd.isna(row["ont_barcode"])
else None,
axis=1,
)

Expand Down Expand Up @@ -141,17 +143,24 @@ def fill_udfs(currentStep: Process, df: pd.DataFrame):

for illumina_sample in illumina_samples:
try:
barcode_name = ont_barcode_well2name(
fetch(illumina_sample, "ONT Barcode Well")
# Get ONT barcode well, if there is one
barcode_well = fetch(
illumina_sample, "ONT Barcode Well", on_fail=None
)

# Subset df to the current ONT barcode
df_barcode = df[df["ont_barcode"] == barcode_name]
if barcode_well:
barcode_name = ont_barcode_well2name(barcode_well)

# Further subset df to the current Illumina sample
df_sample = df_barcode[
df_barcode["sample_name"] == illumina_sample.name
]
# Subset df to the current ONT barcode
df_barcode = df[df["ont_barcode"] == barcode_name]

# Subset df to the current Illumina sample
df_sample = df_barcode[
df_barcode["sample_name"] == illumina_sample.name
]

else:
df_sample = df[df["sample_name"] == illumina_sample.name]

assert (
len(df_sample) == 1
Expand Down

0 comments on commit 631c48a

Please sign in to comment.