Skip to content

Instantly share code, notes, and snippets.

@aofarrel
Created October 25, 2022 20:52
Show Gist options
  • Save aofarrel/a87be125aaecb657741874df7ac7aa42 to your computer and use it in GitHub Desktop.
Save aofarrel/a87be125aaecb657741874df7ac7aa42 to your computer and use it in GitHub Desktop.
Batch renaming + download of several files in google cloud. This was needed because, when downloading with the gcloud CLI (as opposed to the web interface) google just saves the file as "final.vcf" without the full gs:// path. So, trying to batch download a dozen final.vcf files doesn't work.
import os
vcfs = ["gs://your_bucket_here/call-varcall/shard-1/var_call_SRR1049633/final.vcf", "gs://your_bucket_here/call-varcall/shard-2/var_call_SRR1049634/final.vcf", "gs://your_bucket_here/call-varcall/shard-3/var_call_SRR1062904/final.vcf", "gs://your_bucket_here/call-varcall/shard-4/var_call_SRR1140590/final.vcf", "gs://your_bucket_here/call-varcall/shard-5/var_call_SRR1047996/final.vcf", "gs://your_bucket_here/call-varcall/shard-6/var_call_SRR1144759/final.vcf", "gs://your_bucket_here/call-varcall/shard-7/var_call_SRR1165658/final.vcf", "gs://your_bucket_here/call-varcall/shard-8/var_call_SRR1167377/final.vcf", "gs://your_bucket_here/call-varcall/shard-9/var_call_SRR1169242/final.vcf"]
new_vcfs = []
for vcf in vcfs:
split = vcf.split("/")
new_name_start = "/".join(split[:-1])+"/"
new_name_end = split[-2:][0] + ".vcf"
new_name = "".join([new_name_start, new_name_end])
new_vcfs.append(new_name)
os.system(f"gsutil mv {vcf} {new_name_start}{new_name_end}")
os.system(f"gsutil cp {new_name_start}{new_name_end} .")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment