Skip to content

Commit

Permalink
change Epinano_Variants.py! no sliding windown analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Huanle committed Oct 5, 2020
1 parent 3accdcb commit 0535bdf
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Epinano_Variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,20 @@ def df_groupy(df, out):

#~~~~~~~~~~~~~~~~~~~~~~~ main () ~~~~~~~~~~~~~~~~~~~~~~~
parser = argparse.ArgumentParser()
#parser.add_argument ('-r','--reads',help='fastq(a) reads input')
parser.add_argument ('-R','--reference', help='samtools faidx indexed reference file')
parser.add_argument ('-b', '--bam', type=str, help='bam file; if given; no need to offer reads file; mapping will be skipped')
required_args = parser.add_argument_group ('Required Arguments')
required_args.add_argument ('-R','--reference', help='samtools faidx indexed reference file')
required_args.add_argument ('-b', '--bam', type=str, help='bam file; if given; no need to offer reads file; mapping will be skipped')
required_args.add_argument ('-s', '--sam2tsv',type=str, default='',help='/path/to/sam2tsv.jar; needed unless a sam2tsv.jar produced file is already given')
parser.add_argument ('-f','--file', type=str, help='tsv file generated by sam2tsv.jar; if given, reads mapping and sam2tsv conversion will be skipped')
parser.add_argument ('-t', '--threads', type=int, default=4, help='number of threads')
parser.add_argument ('-s', '--sam2tsv',type=str, default='',help='/path/to/sam2tsv.jar; needed unless a sam2tsv.jar produced file is already given')
parser.add_argument ('-T', '--type', type=str, default="t" ,help="reference types, which is either g(enome) or t(ranscriptome);")
parser.add_argument ('-w', '--window', type=int, default=0, help= """specify a windown/kmer size to re-organize per site variants on kmer/window basis;
By default, this is not performed;
It is recommended to do it seperately with EpiNano/misc/Slide_Variants.py """)

parser.add_argument ('-p','--per_read_variants', action='store_true', help='compute per reads variants statistics')
args=parser.parse_args()

#~~~~~~~~~~~~~~~~~~~~~~~ prepare for analysis ~~~~~~~~~~~~~~
tsv_gen = None # generator
prefix = ''
Expand All @@ -161,7 +166,7 @@ def _tsv_gen ():
exit()
else:
if not file_exist (args.sam2tsv):
sys.stderr.write (" can not find {} java program\n".format(args.sam2tsv))
sys.stderr.write ("Please offer correctly path to sam2tsv.jar\n".format(args.sam2tsv))
exit()
if not os.path.exists (bam_file+'.bai'):
os.system ('samtools index ' + bam_file + '.bai')
Expand Down Expand Up @@ -265,15 +270,18 @@ def _tsv_gen ():
tmp_files = glob.glob("{}/small*".format(tmp_dir))
pool.map(_rm, tmp_files)
shutil.rmtree(tmp_dir)

#print ("per site variants frequencies table has been generated", file = sys.stderr)
#3 sliding window per site variants --> for making predicitons
if len (var_files) == 1:
slide_per_site_var(var_files[0])
elif len (var_files) == 2:
pool = mp.Pool(2)
pool.map(slide_per_site_var, var_files)
pool.close(); pool.join()

if args.window:
print (args.window,'mer')
kmer = args.window
print ("slice per site variants frequencies table on {}mer basis".format (kmer), file=sys.stderr)
if len (var_files) == 1:
slide_per_site_var(var_files[0], kmer)
elif len (var_files) == 2:
pool = mp.Pool(2)
pool.starmap(slide_per_site_var, (var_files,kmer))
pool.close(); pool.join()

# per read variants
if args.per_read_variants:
Expand Down

0 comments on commit 0535bdf

Please sign in to comment.