def main(argv=None):
	parser=argparse.ArgumentParser(description="Pipe out the alignments involving or excluding provided contigs ID")
	parser.add_argument('-e',dest="inverse_match",action="store_true",help="Inverse the criterion, filter out any conting in CONTIGID list (not implemented yet)")
	parser.add_argument('-r',dest="use_re",action="store_true",help="Consider CONTIGID as python regexp (not implemented yet)")
	parser.add_argument('-s',dest="remove_self",action="store_true",help="remove self alignments")

	parser.add_argument('-p',dest="pretty",action="store_true",help="Pretty print")
	parser.add_argument('-v',dest="verbose",action="store_true",help="Verbose output")
	parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
	parser.add_argument('-o', nargs='?', type=argparse.FileType('w'), default=sys.stdout,dest="outfile")
	parser.add_argument('CONTIGS',action='append',nargs="+",help='List of CONTIGS to keep. Use "*" to keep them all')
	args=parser.parse_args()

	contig_ids=args.CONTIGS[0]
	alignments=mummerParser.parse_mummerFile(args.infile)
	kept_alignments=[]
	for a in alignments:
		if "*" in contig_ids and ((args.remove_self and a['TAGQ']!=a['TAGR'])or not args.remove_self):
			kept_alignments.append(a)
		if a['TAGQ'] in contig_ids and a['TAGR'] in contig_ids:
			kept_alignments.append(a)
		elif args.verbose:
			print >>args.outfile,"Skipped",a
	for a in kept_alignments:
		mummerParser.print_alignment(a,args.outfile,args.pretty)
def is_kept(aln):
	idy_threshold = 75 #98
	cov_threshold = 99 #95
	aln_threshold = 125 
	ctg_threshold= 0
	# skip self
	if aln['TAGQ']==aln['TAGR']:
		return False

	# Skip under threshold 
	threshold_aln_OK = (int(aln["LEN1"]) > aln_threshold and int(aln["LEN2"]) > aln_threshold)
	threshold_ctg_OK = (int(aln["LENR"]) > ctg_threshold and int(aln["LENQ"]) > ctg_threshold)
	if (not threshold_ctg_OK) or (not threshold_aln_OK):
		return False

	A1, A2 = get_assembler_name (aln["TAGR"]), get_assembler_name (aln["TAGQ"])
	if (A1==A2):
		return False

	# if (aln["TAGR"] != aln["TAGQ"]) and ((aln["COVR"] > cov_threshold) or ((aln["LENR"] - aln["LEN1"]) < ctg_threshold)):
	# 	return False
	# elif (aln["TAGR"] != aln["TAGQ"]) and ((aln["COVQ"] > cov_threshold) or ((aln["LENQ"] - aln["LEN2"]) < ctg_threshold)):
	# 	return False
	if (aln["TAGR"] != aln["TAGQ"]) and (aln["IDY"] > idy_threshold) and threshold_aln_OK and threshold_ctg_OK and (A1 != A2):
		return True
	else:
		return False
	mummerParser.print_alignment(aln,sys.stderr,pretty=True)
	assert(False)
Example #3
0
def is_kept(aln):
    idy_threshold = 75  #98
    cov_threshold = 99  #95
    aln_threshold = 125
    ctg_threshold = 0
    # skip self
    if aln['TAGQ'] == aln['TAGR']:
        return False

    # Skip under threshold
    threshold_aln_OK = (int(aln["LEN1"]) > aln_threshold
                        and int(aln["LEN2"]) > aln_threshold)
    threshold_ctg_OK = (int(aln["LENR"]) > ctg_threshold
                        and int(aln["LENQ"]) > ctg_threshold)
    if (not threshold_ctg_OK) or (not threshold_aln_OK):
        return False

    A1, A2 = get_assembler_name(aln["TAGR"]), get_assembler_name(aln["TAGQ"])
    if (A1 == A2):
        return False

    # if (aln["TAGR"] != aln["TAGQ"]) and ((aln["COVR"] > cov_threshold) or ((aln["LENR"] - aln["LEN1"]) < ctg_threshold)):
    # 	return False
    # elif (aln["TAGR"] != aln["TAGQ"]) and ((aln["COVQ"] > cov_threshold) or ((aln["LENQ"] - aln["LEN2"]) < ctg_threshold)):
    # 	return False
    if (aln["TAGR"] != aln["TAGQ"]) and (
            aln["IDY"] > idy_threshold
    ) and threshold_aln_OK and threshold_ctg_OK and (A1 != A2):
        return True
    else:
        return False
    mummerParser.print_alignment(aln, sys.stderr, pretty=True)
    assert (False)
Example #4
0
def main(argv=None):
    parser = argparse.ArgumentParser(
        description=
        "Pipe out the alignments involving or excluding provided contigs ID")
    parser.add_argument(
        '-e',
        dest="inverse_match",
        action="store_true",
        help=
        "Inverse the criterion, filter out any conting in CONTIGID list (not implemented yet)"
    )
    parser.add_argument(
        '-r',
        dest="use_re",
        action="store_true",
        help="Consider CONTIGID as python regexp (not implemented yet)")
    parser.add_argument('-s',
                        dest="remove_self",
                        action="store_true",
                        help="remove self alignments")

    parser.add_argument('-p',
                        dest="pretty",
                        action="store_true",
                        help="Pretty print")
    parser.add_argument('-v',
                        dest="verbose",
                        action="store_true",
                        help="Verbose output")
    parser.add_argument('infile',
                        nargs='?',
                        type=argparse.FileType('r'),
                        default=sys.stdin)
    parser.add_argument('-o',
                        nargs='?',
                        type=argparse.FileType('w'),
                        default=sys.stdout,
                        dest="outfile")
    parser.add_argument(
        'CONTIGS',
        action='append',
        nargs="+",
        help='List of CONTIGS to keep. Use "*" to keep them all')
    args = parser.parse_args()

    contig_ids = args.CONTIGS[0]
    alignments = mummerParser.parse_mummerFile(args.infile)
    kept_alignments = []
    for a in alignments:
        if "*" in contig_ids and ((args.remove_self and a['TAGQ'] != a['TAGR'])
                                  or not args.remove_self):
            kept_alignments.append(a)
        if a['TAGQ'] in contig_ids and a['TAGR'] in contig_ids:
            kept_alignments.append(a)
        elif args.verbose:
            print >> args.outfile, "Skipped", a
    for a in kept_alignments:
        mummerParser.print_alignment(a, args.outfile, args.pretty)