Skip to content

Commit 935a84e

Browse files
committed
added CLI options for bamrc2af
1 parent 29f6379 commit 935a84e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

hometools/hometools.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -1776,19 +1776,15 @@ def pbamrc(args):
17761776
def bamrc2af(args):
17771777
"""
17781778
Reads the output of pbamrc and a corresponding VCF file and returns the allele frequencies of the alt alleles.
1779-
Currently, working for only SNPs
1779+
Currently, working for SNPs only
17801780
"""
17811781
from gzip import open as gzopen
17821782
logger = mylogger("bamrc2af")
17831783
rcfin = args.bamrc.name
17841784
vcffin = args.vcf.name
17851785
outfin = 'bamrc_af.txt' if args.out is None else args.out.name
17861786

1787-
## Get alt SNP lists
1788-
rcfin = "C:\\Users\\ra98jam\\potato_hap_example\\dm_all_sample_snp_Otava_genotype.bamrc"
1789-
vcffin = "C:\\Users\\ra98jam\\potato_hap_example\\dm_all_sample_chr2.merged.vcf.gz"
1790-
outfin = "C:\\Users\\ra98jam\\potato_hap_example\\tmp.txt"
1791-
1787+
logger.info('Reading VCF')
17921788
posdict = dict()
17931789
op = gzopen if isgzip(vcffin) else open
17941790
with op(vcffin, 'r') as vcf:
@@ -1800,6 +1796,7 @@ def bamrc2af(args):
18001796
if line[4].upper() not in 'ACGT' : continue
18011797
posdict[tuple(line[:2])] = line[3], line[4]
18021798

1799+
logger.info('Reading bamrc')
18031800
# Get AF from bam readcount
18041801
basedict = dict(zip('ACGT', range(4, 8)))
18051802
with open(rcfin, 'r') as rc, open(outfin, 'w') as out:
@@ -1812,13 +1809,10 @@ def bamrc2af(args):
18121809
refi = basedict[ref]
18131810
alti = basedict[alt]
18141811
out.write(f'{line[0]}\t{line[1]}\t{ref}\t{alt}\t{round(int(line[refi])/int(line[3]) , 2)}\t{round(int(line[alti])/int(line[3]), 2)}\n')
1815-
1816-
1817-
1812+
logger.info('Finishe')
18181813
# END
18191814

18201815

1821-
18221816
def run_ppileup(locs, out, bam, pars):
18231817
from subprocess import Popen, PIPE
18241818
with open(out, 'w') as fout:
@@ -2622,7 +2616,7 @@ def main(cmd):
26222616
parser_ppileup = subparsers.add_parser("ppileup", help="BAM: Currently it is slower than just running mpileup on 1 CPU. Might be possible to optimize later. Run samtools mpileup in parallel when pileup is required for specific positions by dividing the input bed file.", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26232617
# </editor-fold>
26242618

2625-
# <editor-fold desc="syri">
2619+
# <editor-fold desc="syri CLI">
26262620
parser_runsyri = subparsers.add_parser("runsyri", help=hyellow("syri: Parser to align and run syri on two genomes"),
26272621
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26282622
parser_syriidx = subparsers.add_parser("syriidx", help=hyellow(
@@ -2632,11 +2626,12 @@ def main(cmd):
26322626
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26332627
# </editor-fold>
26342628

2635-
2636-
## Plotting
2629+
# <editor-fold desc="Plotting">
26372630
parser_plthist = subparsers.add_parser("plthist", help="Plot: Takes frequency output (like from uniq -c) and generates a histogram plot", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26382631
parser_plotal = subparsers.add_parser("plotal", help="Plot: Visualise pairwise-whole genome alignments between multiple genomes", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26392632
parser_plotbar = subparsers.add_parser("pltbar", help="Plot: Generate barplot. Input: a two column file with first column as features and second column as values", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
2633+
# </editor-fold>
2634+
26402635

26412636
## Assembly graphs
26422637
parser_asmreads = subparsers.add_parser("asmreads", help=hyellow("GFA: For a given genomic region, get reads that constitute the corresponding assembly graph"), formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -2659,6 +2654,12 @@ def main(cmd):
26592654
parser.print_help()
26602655
sys.exit()
26612656

2657+
# bamrc2af
2658+
parser_bamrc2af.set_defaults(func=bamrc2af)
2659+
parser_bamrc2af.add_argument("bamrc", help="BAM readcount file generated using bamrc", type=argparse.FileType('r'))
2660+
parser_bamrc2af.add_argument("vcf", help="VCF file", type=argparse.FileType('r'))
2661+
parser_bamrc2af.add_argument("out", help="Output file", type=argparse.FileType('w'))
2662+
26622663
# xls2csv
26632664
parser_xls2tsv.set_defaults(func=xls2csv)
26642665
parser_xls2tsv.add_argument("xls", help="Input excel file", type=argparse.FileType('r'))

0 commit comments

Comments
 (0)