def main(recordFilenames, fastaFilename, title, xRange, bitRange): """ Print reads that match in a specified X-axis and bit score range. @param recordFilenames: A C{list} of C{str} file names contain results of a BLAST run, in JSON format. @param fastaFilename: The C{str} name of the FASTA file that was originally BLASTed. @param title: The C{str} title of the subject sequence, as output by BLAST. @param xRange: A (start, end) list of C{int}s, giving an X-axis range or C{None} if the entire X axis range should be printed. @param bitRange: A (start, end) list of C{int}s, giving a bit score range or C{None} if the entire bit score range should be printed. """ reads = FastaReads(fastaFilename) blastReadsAlignments = BlastReadsAlignments(reads, recordFilenames) filtered = blastReadsAlignments.filter(whitelist=set([title]), negativeTitleRegex='.') titlesAlignments = TitlesAlignments(filtered) if title not in titlesAlignments: print('%s: Title %r not found in BLAST output' % (sys.argv[0], title)) sys.exit(3) for titleAlignment in titlesAlignments[title]: for hsp in titleAlignment.hsps: if ((xRange is None or (xRange[0] <= hsp.subjectEnd and xRange[1] >= hsp.subjectStart)) and (bitRange is None or (bitRange[0] <= hsp.score.score <= bitRange[1]))): print(('query: %s, start: %d, end: %d, score: %d' % (titleAlignment.read.id, hsp.subjectStart, hsp.subjectEnd, hsp.score.score)))
def main(recordFilenames, fastaFilename, title, xRange, bitRange): """ Print reads that match in a specified X-axis and bit score range. @param recordFilenames: A C{list} of C{str} file names contain results of a BLAST run, in JSON format. @param fastaFilename: The C{str} name of the FASTA file that was originally BLASTed. @param title: The C{str} title of the subject sequence, as output by BLAST. @param xRange: A (start, end) list of C{int}s, giving an X-axis range or C{None} if the entire X axis range should be printed. @param bitRange: A (start, end) list of C{int}s, giving a bit score range or C{None} if the entire bit score range should be printed. """ reads = FastaReads(fastaFilename) blastReadsAlignments = BlastReadsAlignments(reads, recordFilenames) filtered = blastReadsAlignments.filter(whitelist=set([title]), negativeTitleRegex='.') titlesAlignments = TitlesAlignments(filtered) if title not in titlesAlignments: print('%s: Title %r not found in BLAST output' % (sys.argv[0], title)) sys.exit(3) for titleAlignment in titlesAlignments[title]: for hsp in titleAlignment.hsps: if ((xRange is None or (xRange[0] <= hsp.subjectEnd and xRange[1] >= hsp.subjectStart)) and (bitRange is None or (bitRange[0] <= hsp.score.score <= bitRange[1]))): print(('query: %s, start: %d, end: %d, score: %d' % ( titleAlignment.read.id, hsp.subjectStart, hsp.subjectEnd, hsp.score.score)))
args.diamondSqliteDatabaseFilename is None): print('--diamondDatabaseFastaFilename and ' '--diamondSqliteDatabaseFilename cannot both be used with ' '--matcher diamond.', file=sys.stderr) sys.exit(1) from dark.diamond.alignments import DiamondReadsAlignments readsAlignments = DiamondReadsAlignments( reads, jsonFiles, databaseFilename=args.diamondDatabaseFastaFilename, databaseDirectory=args.diamondDatabaseFastaDirectory, sqliteDatabaseFilename=args.diamondSqliteDatabaseFilename) readsAlignments.filter( maxAlignmentsPerRead=args.maxAlignmentsPerRead, minSequenceLen=args.minSequenceLen, maxSequenceLen=args.maxSequenceLen, minStart=args.minStart, maxStop=args.maxStop, oneAlignmentPerRead=args.oneAlignmentPerRead, maxHspsPerHit=args.maxHspsPerHit, scoreCutoff=args.scoreCutoff, whitelist=whitelist, blacklist=blacklist, titleRegex=args.titleRegex, negativeTitleRegex=args.negativeTitleRegex, truncateTitlesAfter=args.truncateTitlesAfter, taxonomy=args.taxonomy) format_ = 'fasta' if args.fasta else 'fastq' write = sys.stdout.write for readAlignments in readsAlignments: write(readAlignments.read.toString(format_=format_))