Skip to content

Commit

Permalink
fix rename script
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimens committed Jul 10, 2024
1 parent b1c3b28 commit 3aec7da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ jobs:
shell: micromamba-shell {0}
if: always()
run: |
cp test/bam/sample1.bam test/bam/pineapple.bam && renamebam -d test/bam/pineapple.bam pineapple1
cp test/bam/sample1.bam test/bam/pineapple.bam && rename_bam -d test/bam/pineapple.bam pineapple1
harpy phase --vcf-samples -o phasevcf --vcf test/vcf/test.bcf --snakemake "--show-failed-logs" test/bam
leviathan:
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/bin/rename_bam.py → src/harpy/bin/rename_bam
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#! /usr/bin/env python
"""Rename a sam/bam file and modify the @RG tag of the alignment file to reflect the change for both ID and SM."""
import argparse
import sys
import os
import sys
import argparse

parser = argparse.ArgumentParser(
prog='rename_bam.py',
description='Rename a sam/bam file and modify the @RG tag of the alignment file to reflect the change for both ID and SM. This process creates a new file \'newname.bam\' and you may use -d to delete the original file. Requires samtools.'
)
parser.add_argument("input", type=str, metavar = "input.bam", help="input bam or sam file")
parser.add_argument("name", type=str, metavar = "new_name", help="new file/sample name")
parser.add_argument("name", type=str, metavar = "new_name", help="new sample name")
parser.add_argument("-d", "--delete", dest = "delete", action='store_true', help="delete the original file")

if len(sys.argv) == 1:
Expand All @@ -21,8 +21,10 @@
if not os.path.exists(args.input):
parser.error(f"The file {args.input} does not exist :(")

outdir = os.path.dirname(args.input)

JOB_STATUS = os.system(
f"samtools addreplacerg -r \"ID:{args.name}\\tSM:{args.name}\" -o {args.name}.bam {args.input}"
f"samtools addreplacerg -r \"ID:{args.name}\\tSM:{args.name}\" -o {outdir}/{args.name}.bam {args.input}"
)

if JOB_STATUS != 0:
Expand Down

0 comments on commit 3aec7da

Please sign in to comment.