Skip to content

Commit

Permalink
sorted out argparsing issues, now able to have sub commands. Also mad…
Browse files Browse the repository at this point in the history
…e modules directory with first module is read_dist
  • Loading branch information
serine committed Aug 10, 2016
1 parent 9f7045e commit ed86ed1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
Binary file removed rseqc/modules/read_dist/.read_dist.py.swp
Binary file not shown.
36 changes: 14 additions & 22 deletions rseqc/modules/read_dist/read_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,23 @@ def process_gene_model(gene_model):
int_up1k_size,int_up5k_size,int_up10k_size,\
int_down1k_size,int_down5k_size,int_down10k_size)

def main():
usage="%prog [options]" + '\n' + __doc__ + "\n"
parser = OptionParser(usage,version="%prog " + __version__)
parser.add_option("-i","--input-file",action="store",type="string",dest="input_file",help="Alignment file in BAM or SAM format.")
parser.add_option("-r","--refgene",action="store",type="string",dest="ref_gene_model",help="Reference gene model in bed format.")
(options,args)=parser.parse_args()

if not (options.input_file and options.ref_gene_model):
parser.print_help()
sys.exit(0)
if not os.path.exists(options.ref_gene_model):
print >>sys.stderr, '\n\n' + options.ref_gene_model + " does NOT exists" + '\n'
#parser.print_help()
sys.exit(0)
if not os.path.exists(options.input_file):
print >>sys.stderr, '\n\n' + options.input_file + " does NOT exists" + '\n'
sys.exit(0)
def main(input_file, gene_models):

#if not os.path.exists(gene_models):
# print >>sys.stderr, '\n\n' + gene_models + " does NOT exists" + '\n'
# #parser.print_help()
# sys.exit(0)
#if not os.path.exists(input_file):
# print >>sys.stderr, '\n\n' + input_file + " does NOT exists" + '\n'
# sys.exit(0)

#build bitset
(cds_exon_r, intron_r, utr_5_r, utr_3_r,\
intergenic_up_1kb_r,intergenic_up_5kb_r,intergenic_up_10kb_r,\
intergenic_down_1kb_r,intergenic_down_5kb_r,intergenic_down_10kb_r,\
cds_exon_base,intron_base,utr_5_base,utr_3_base,\
intergenic_up1kb_base,intergenic_up5kb_base,intergenic_up10kb_base,\
intergenic_down1kb_base,intergenic_down5kb_base,intergenic_down10kb_base) = process_gene_model(options.ref_gene_model)
intergenic_down1kb_base,intergenic_down5kb_base,intergenic_down10kb_base) = process_gene_model(gene_models)

intron_read=0
cds_exon_read=0
Expand All @@ -197,14 +189,14 @@ def main():
totalReads=0
totalFrags=0
unAssignFrags=0
obj = SAM.ParseBAM(options.input_file)
obj = SAM.ParseBAM(input_file)

R_qc_fail=0
R_duplicate=0
R_nonprimary=0
R_unmap=0

print >>sys.stderr, "processing " + options.input_file + " ...",
print >>sys.stderr, "processing " + input_file + " ...",
try:
while(1):
aligned_read = obj.samfile.next()
Expand Down Expand Up @@ -290,5 +282,5 @@ def main():
print "%-20s%-20d%-20d%-18.2f" % ("TES_down_10kb",intergenic_down10kb_base, intergenic_down10kb_read, intergenic_down10kb_read*1000.0/(intergenic_down10kb_base+1))
print "====================================================================="

if __name__ == '__main__':
main()
#if __name__ == '__main__':
# main()
41 changes: 28 additions & 13 deletions scripts/rseqc
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@
import os
import argparse

from modules import read_dist
#from modules import read_dist

# create the top-level parser
parser = argparse.ArgumentParser(add_help=True)

subparsers = parser.add_subparsers(help='sub-command help')
parser = argparse.ArgumentParser(add_help=True)

parser_read_dist = subparsers.add_parser('bam_stats',
subparsers = parser.add_subparsers(help='sub-command help',
dest = 'command'
)
# bam_stats options
parser_bam_stats = subparsers.add_parser('bam_stats',
help = 'Summarizing mapping statistics of a BAM or SAM file'
)
parser_read_dist.add_argument('-i', '--input_file',
parser_bam_stats.add_argument('-i', '--input_file',
required = True,
help = 'specify your alignment file in SAM or BAM format'
)
parser_read_dist.add_argument('-q', '--mapq',
parser_bam_stats.add_argument('-q', '--mapq',
default = 30,
help = 'Minimum mapping quality to determine uniquely mapped read'
)

# read_distribution options
parser_read_dist = subparsers.add_parser('read_dist',
help = 'This will be help description for read_dist option'
help = 'Get read distribution amongst gene feature, e.g exon, intron etc.'
)
parser_read_dist.add_argument('-i', '--input_file',
required = True,
Expand All @@ -32,9 +37,19 @@ parser_read_dist.add_argument('-g', '--gene_models',
required = True,
help = 'specify your gene_models file in BED12 or GTF format'
)

args = parser.parse_args()
#dir = args.dir
#coord = args.coord
#host_name = args.host_name
#igvFile = args.igvFile
#genome = args.genome

print args.command

input_file = args.input_file

#TODO pass args.command into a function and let function to decide which sub-function to invoke for data processing

if args.command == 'bam_stats':
mapq = args.mapq
if args.command == 'read_dist':
gene_models = args.gene_models

print input_file

0 comments on commit ed86ed1

Please sign in to comment.