Skip to content

Commit 4458a29

Browse files
authored
Merge pull request #1179 from fls-bioinformatics-core/transfer_data-shorten-shared-filenames
'transfer_data.py': add option to shorten shared filenames
2 parents 30db538 + a93b7a6 commit 4458a29

5 files changed

Lines changed: 122 additions & 22 deletions

File tree

auto_process_ngs/cli/transfer_data.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ def main(argv=None):
291291
help="copy the 'download_fastqs.py' utility to the "
292292
"final location")
293293
sp = p.add_argument_group("Advanced options")
294+
sp.add_argument('--short_names',action='store_true',
295+
default=None,
296+
help="use shortened base names where possible for "
297+
"shared files")
294298
sp.add_argument('--link',action='store_true',
295299
help="hard link files instead of copying")
296300
sp.add_argument('--runner',action='store',
@@ -337,6 +341,7 @@ def main(argv=None):
337341
subdir = dest.subdir
338342
zip_fastqs = dest.zip_fastqs
339343
max_zip_size = dest.max_zip_size
344+
short_names = dest.short_names
340345
include_downloader = dest.include_downloader
341346
include_qc_report = dest.include_qc_report
342347
hard_links = dest.hard_links
@@ -347,6 +352,7 @@ def main(argv=None):
347352
subdir = None
348353
zip_fastqs = False
349354
max_zip_size = None
355+
short_names = False
350356
include_downloader = False
351357
include_qc_report = False
352358
hard_links = False
@@ -361,6 +367,8 @@ def main(argv=None):
361367
zip_fastqs = True
362368
if args.max_zip_size:
363369
max_zip_size = args.max_zip_size
370+
if args.short_names:
371+
short_names = args.short_names
364372
if args.include_downloader:
365373
include_downloader = True
366374
if args.include_qc_report:
@@ -392,6 +400,7 @@ def main(argv=None):
392400
print(f"Hard link Fastqs : {hard_links}")
393401
print(f"Zip Fastqs : {zip_fastqs}")
394402
print(f"Max ZIP size : {max_zip_size}")
403+
print(f"Shorten file names : {short_names}")
395404
print(f"Dry run : {dry_run}")
396405

397406
# Check at least one artefact is being transferred
@@ -741,6 +750,7 @@ def main(argv=None):
741750
analysis_dir.metadata.run_number,
742751
analysis_dir.metadata.instrument_datestamp,
743752
analysis_dir.run_id))
753+
summary.append(f"Project '{project.name}'")
744754
summary.append("%s%s dataset" %
745755
("%s " % project.info.single_cell_platform
746756
if project.info.single_cell_platform else '',
@@ -857,13 +867,16 @@ def main(argv=None):
857867
run_number = str(analysis_dir.metadata.run_number)
858868
if analysis_dir.metadata.analysis_number is not None:
859869
run_number += "_" + str(analysis_dir.metadata.analysis_number)
860-
final_zip_basename = \
861-
"{platform}_{datestamp}.{run_number}-{project}-fastqs".\
862-
format(
863-
platform=analysis_dir.metadata.platform.upper(),
864-
datestamp=analysis_dir.metadata.instrument_datestamp,
865-
run_number=run_number,
866-
project=project.name)
870+
if short_names:
871+
final_zip_basename = f"{project.name}-fastqs"
872+
else:
873+
final_zip_basename = \
874+
"{platform}_{datestamp}.{run_number}-{project}-fastqs".\
875+
format(
876+
platform=analysis_dir.metadata.platform.upper(),
877+
datestamp=analysis_dir.metadata.instrument_datestamp,
878+
run_number=run_number,
879+
project=project.name)
867880
job_ix = 0
868881
for f in listdir(working_dir):
869882
if f == "%s.chksums" % project_name:
@@ -907,11 +920,14 @@ def main(argv=None):
907920
if qc_zips:
908921
for qc_zip in qc_zips:
909922
print("Copying '%s'" % os.path.basename(qc_zip))
923+
qc_zip_basename = os.path.basename(qc_zip)
924+
if short_names:
925+
# Hack to remove run name from QC report ZIP name
926+
qc_zip_basename = f"{'.'.join(qc_zip_basename.split('.')[:-2])}.zip"
910927
td.run_job(
911-
f"copy_qc_zip.{job_id}.{os.path.basename(qc_zip)}",
928+
f"copy_qc_zip.{job_id}.{qc_zip_basename}",
912929
copy_command(qc_zip,
913-
os.path.join(target_dir,
914-
os.path.basename(qc_zip)),
930+
os.path.join(target_dir, qc_zip_basename),
915931
link=hard_links))
916932

917933
# Tar and copy 10xGenomics outputs
@@ -920,12 +936,13 @@ def main(argv=None):
920936
print("Tar gzipping and copying '%s'" %
921937
os.path.basename(cellranger_dir))
922938
# Tar & gzip data
923-
targz = os.path.join(working_dir,
924-
"%s.%s.%s.tgz" % (
925-
os.path.basename(
926-
cellranger_dir),
927-
project_name,
928-
project.info.run))
939+
if short_names:
940+
targz = f"{os.path.basename(cellranger_dir)}.{project_name}.tgz"
941+
else:
942+
targz = "%s.%s.%s.tgz" % (os.path.basename(cellranger_dir),
943+
project_name,
944+
project.info.run)
945+
targz = os.path.join(working_dir, targz)
929946
targz_job = td.run_job(
930947
f"targz_10x_output.{job_id}.{os.path.basename(cellranger_dir)}",
931948
Command("tar",
@@ -980,11 +997,13 @@ def main(argv=None):
980997
if visium_images_dir:
981998
print(f"Tar gzipping and copying '{visium_images_dir}'")
982999
# Tar & gzip data
983-
targz = os.path.join(working_dir,
984-
"%s.%s.%s.tgz" % (
985-
os.path.basename(visium_images_dir),
986-
project_name,
987-
project.info.run))
1000+
if short_names:
1001+
targz = f"{os.path.basename(visium_images_dir)}.{project_name}.tgz"
1002+
else:
1003+
targz = "%s.%s.%s.tgz" % (os.path.basename(visium_images_dir),
1004+
project_name,
1005+
project.info.run)
1006+
targz = os.path.join(working_dir, targz)
9881007
targz_job = td.run_job(
9891008
f"targz_visium_images.{job_id}.{os.path.basename(visium_images_dir)}",
9901009
Command("tar",

auto_process_ngs/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ def __init__(self, settings_file=None, resolve_undefined=True):
10601060
"subdir": str,
10611061
"zip_fastqs": bool,
10621062
"max_zip_size": str,
1063+
"short_names": bool,
10631064
"readme_template": str,
10641065
"url": str,
10651066
"include_downloader": bool,
@@ -1083,6 +1084,7 @@ def __init__(self, settings_file=None, resolve_undefined=True):
10831084
"destination:*.include_qc_report": False,
10841085
"destination:*.hard_links": False,
10851086
"destination:*.zip_fastqs": False,
1087+
"destination:*.short_names": False,
10861088
"destination:*.include_downloader": False,
10871089
"qc.fastq_subset_size": 100000,
10881090
"qc.split_undetermined_fastqs": True,

auto_process_ngs/test/cli/test_transfer_data.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,78 @@ def test_transfer_data_dry_run(self):
664664
"--dry-run" ]), 0)
665665
# Check nothing was transferred
666666
self.assertEqual(len(os.listdir(target_dir)), 0)
667+
668+
def test_transfer_data_fastqs_with_qc_report_short_names(self):
669+
"""
670+
transfer_data: copy Fastqs and QC report with shortened names
671+
"""
672+
# Make a mock auto-process directory
673+
mockdir = MockAnalysisDirFactory.bcl2fastq2(
674+
'170901_M00879_0087_000000000-AGEW9',
675+
'miseq',
676+
metadata={ "instrument_datestamp": "170901",
677+
"run_number": "89" },
678+
project_metadata={ "AB": { "Library type": "RNA-seq",
679+
"Organism": "Human" } },
680+
top_dir=self.dirn)
681+
mockdir.create()
682+
# Add QC outputs
683+
project = AnalysisProject(os.path.join(mockdir.dirn, "AB"))
684+
UpdateAnalysisProject(project).add_qc_outputs()
685+
# Make a target directory
686+
target_dir = os.path.join(self.dirn, "shared")
687+
os.makedirs(target_dir)
688+
# Do data transfer (--include_qc_report)
689+
self.assertEqual(transfer_data(
690+
[target_dir,
691+
os.path.join(mockdir.dirn, "AB"),
692+
"--include_qc_report",
693+
"--short_names"]), 0)
694+
# Check transferred artefacts
695+
print(os.listdir(target_dir))
696+
expected_files = ("AB1_S1_R1_001.fastq.gz",
697+
"AB1_S1_R2_001.fastq.gz",
698+
"AB2_S2_R2_001.fastq.gz",
699+
"AB2_S2_R1_001.fastq.gz",
700+
"AB.chksums",
701+
"qc_report.AB.zip")
702+
for f in expected_files:
703+
self.assertTrue(os.path.exists(os.path.join(target_dir, f)),
704+
f"'{f}': missing, should be present")
705+
for f in os.listdir(target_dir):
706+
self.assertTrue(f in expected_files,
707+
f"'{f}': present, but not expected")
708+
709+
def test_transfer_data_zip_fastqs_short_names(self):
710+
"""
711+
transfer_data: put Fastqs into ZIP archive using shortened names
712+
"""
713+
# Make a mock auto-process directory
714+
mockdir = MockAnalysisDirFactory.bcl2fastq2(
715+
'170901_M00879_0087_000000000-AGEW9',
716+
'miseq',
717+
metadata={ "instrument_datestamp": "170901",
718+
"run_number": "89" },
719+
project_metadata={ "AB": { "Library type": "RNA-seq",
720+
"Organism": "Human" } },
721+
top_dir=self.dirn)
722+
mockdir.create()
723+
# Make a target directory
724+
target_dir = os.path.join(self.dirn, "shared")
725+
os.makedirs(target_dir)
726+
# Do data transfer (--zip_fastqs)
727+
self.assertEqual(transfer_data(
728+
[target_dir,
729+
os.path.join(mockdir.dirn, "AB"),
730+
"--zip_fastqs",
731+
"--short_names"]), 0)
732+
# Check transferred artefacts
733+
print(os.listdir(target_dir))
734+
expected_files = ("AB-fastqs.zip",
735+
"AB-fastqs.checksums")
736+
for f in expected_files:
737+
self.assertTrue(os.path.exists(os.path.join(target_dir, f)),
738+
f"'{f}': missing, should be present")
739+
for f in os.listdir(target_dir):
740+
self.assertTrue(f in expected_files,
741+
f"'{f}': present, but not expected")

config/auto_process.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
# * 'run_id': creates new subdir 'PLATFORM_DATESTAMP.RUN_ID-PROJECT'
183183
# - zip_fastqs: whether to bundle Fastqs into ZIP archives
184184
# - max_zip_size: maximum size for each ZIP archive
185+
# - short_names: use shorter naming scheme for shared files
185186
# - readme_template: template file to generate README file from
186187
# (either full path or the name of a file in the 'templates'
187188
# directory of the installation
@@ -199,6 +200,7 @@
199200
;subdir = random_bin
200201
;zip_fastqs = true
201202
;max_zip_size = 5G
203+
;short_names = true
202204
;readme_template = README.webserver.txt
203205
;url = http://awesome.com/data
204206
;include_downloader = true

docs/source/configuration.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,10 @@ Parameter Function
722722
``zip_fastqs`` Whether to bundle Fastqs into ZIP archives
723723
``max_zip_size`` Maximum size for each ZIP archive (if Fastqs
724724
are bundled)
725+
``short_names`` Use shortened base name where possible for the
726+
shared files
725727
``readme_template`` Template file to generate ``README`` from
726-
``url`` Base URL to access copied data at
728+
``url`` Base URL to access copied data from
727729
``include_downloader`` Whether to include ``download_fastqs.py``
728730
``include_qc_report`` Whether to include zipped QC reports
729731
``hard_links`` Whether to hard link to Fastqs rather making

0 commit comments

Comments
 (0)