Skip to content

Commit 3e1b10b

Browse files
ahmed-shuaibiclaude
andcommitted
fix: match browser duplicate-named tarballs (study (1).tar.gz) in Downloads
Glob <study>*.tar.gz so cohorts re-downloaded by the browser (luad_..._2018 (1).tar.gz) are found; got LUAD/LUSC/PRAD/SARC/SKCM/STAD -> 30/32 cohorts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c30e443 commit 3e1b10b

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

scripts/download_cbioportal_mafs.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,27 @@ def is_valid_maf(path: Path) -> bool:
5252

5353

5454
def from_local_tarball(cohort: str, out: Path) -> bool:
55-
"""Extract data_mutations.txt from a cohort's tarball in ~/Downloads, if present."""
55+
"""Extract data_mutations.txt from a cohort's tarball in ~/Downloads, if present.
56+
57+
Matches browser duplicate-download names too (e.g. ``luad_..._2018 (1).tar.gz``);
58+
the member path inside is always the un-suffixed study directory.
59+
"""
5660
code = STUDY_CODE_OVERRIDE.get(cohort, cohort.lower())
57-
tarball = DOWNLOADS / f"{code}_tcga_pan_can_atlas_2018.tar.gz"
58-
if not tarball.exists():
59-
return False
60-
member = f"{code}_tcga_pan_can_atlas_2018/data_mutations.txt"
61-
with out.open("wb") as fh:
62-
proc = subprocess.run(
63-
["tar", "-xzf", str(tarball), "-O", member],
64-
stdout=fh,
65-
stderr=subprocess.DEVNULL,
66-
check=False,
67-
)
68-
if proc.returncode != 0 or not is_valid_maf(out):
69-
out.unlink(missing_ok=True)
70-
return False
71-
return True
61+
study = f"{code}_tcga_pan_can_atlas_2018"
62+
candidates = sorted(DOWNLOADS.glob(f"{study}*.tar.gz"))
63+
member = f"{study}/data_mutations.txt"
64+
for tarball in candidates:
65+
with out.open("wb") as fh:
66+
proc = subprocess.run(
67+
["tar", "-xzf", str(tarball), "-O", member],
68+
stdout=fh,
69+
stderr=subprocess.DEVNULL,
70+
check=False,
71+
)
72+
if proc.returncode == 0 and is_valid_maf(out):
73+
return True
74+
out.unlink(missing_ok=True)
75+
return False
7276

7377

7478
def download(cohort: str) -> tuple[str, str]:

0 commit comments

Comments
 (0)