help='USEARCH8 EXE') parser.add_argument('--debug', action='store_true', help='Remove Intermediate Files') args = parser.parse_args() if not args.out: #get base name of files base = args.otu_table.split(".otu_table") base = base[0] else: base = args.out #remove logfile if exists log_name = base + '.ufits-filter.log' ufitslib.removefile(log_name) ufitslib.setupLogging(log_name) FNULL = open(os.devnull, 'w') cmd_args = " ".join(sys.argv) + '\n' ufitslib.log.debug(cmd_args) print "-------------------------------------------------------" #initialize script, log system info and usearch version ufitslib.SystemInfo() #Do a version check usearch = args.usearch ufitslib.versionDependencyChecks(usearch) #check if otu_table is empty ufitslib.log.info("Loading OTU table: %s" % args.otu_table)
def getAvgLength(input): AvgLength = [] for title, seq, qual in FastqGeneralIterator(open(input)): AvgLength.append(len(seq)) Average = sum(AvgLength) / float(len(AvgLength)) Min = min(AvgLength) Max = max(AvgLength) a = np.array(AvgLength) nintyfive = np.percentile(a, 5) return (Average, Min, Max, int(nintyfive)) #remove logfile if exists log_name = args.out + '.ufits-dada2.log' if os.path.isfile(log_name): ufitslib.removefile(log_name) ufitslib.setupLogging(log_name) FNULL = open(os.devnull, 'w') cmd_args = " ".join(sys.argv)+'\n' ufitslib.log.debug(cmd_args) print "-------------------------------------------------------" #initialize script, log system info and usearch version ufitslib.SystemInfo() #Do a version check usearch = args.usearch ufitslib.versionDependencyChecks(usearch) #check dependencies programs = ['Rscript'] ufitslib.CheckDependencies(programs)
ufitslib.log.error("Blast taxonomy is not compatible with BIOM output, use a different method") #create OTU phylogeny for downstream processes ufitslib.log.info("Generating phylogenetic tree") tree_out = base + '.tree.phy' cmd = [usearch, '-cluster_agg', args.fasta, '-treeout', tree_out] ufitslib.runSubprocess(cmd, ufitslib.log) #print some summary file locations ufitslib.log.info("Taxonomy finished: %s" % taxFinal) if args.otu_table and not args.method == 'blast': ufitslib.log.info("Classic OTU table with taxonomy: %s" % taxTable) #output final OTU table in Biom v1.0 (i.e. json format if biom installed) outBiom = base + '.biom' if ufitslib.which('biom'): ufitslib.removefile(outBiom) cmd = ['biom', 'convert', '-i', tmpTable, '-o', outBiom+'.tmp', '--table-type', "OTU table", '--to-json'] ufitslib.runSubprocess(cmd, ufitslib.log) if args.mapping_file: cmd = ['biom', 'add-metadata', '-i', outBiom+'.tmp', '-o', outBiom, '--observation-metadata-fp', qiimeTax, '-m', args.mapping_file, '--sc-separated', 'taxonomy'] ufitslib.runSubprocess(cmd, ufitslib.log) else: cmd = ['biom', 'add-metadata', '-i', outBiom+'.tmp', '-o', outBiom, '--observation-metadata-fp', qiimeTax, '--sc-separated', 'taxonomy'] ufitslib.runSubprocess(cmd, ufitslib.log) ufitslib.removefile(outBiom+'.tmp') ufitslib.log.info("BIOM OTU table created: %s" % outBiom) else: ufitslib.log.info("biom program not installed, install via `pip install biom-format`") ufitslib.log.info("OTUs with taxonomy: %s" % otuTax) ufitslib.log.info("OTU phylogeny: %s" % tree_out)
parser.add_argument('-o','--out', help='Base output name') parser.add_argument('--min_reads_otu', default=2, type=int, help='Minimum number of reads per OTU for experiment') parser.add_argument('-u','--usearch', dest="usearch", default='usearch9', help='USEARCH8 EXE') parser.add_argument('--debug', action='store_true', help='Remove Intermediate Files') args=parser.parse_args() if not args.out: #get base name of files base = args.otu_table.split(".otu_table") base = base[0] else: base = args.out #remove logfile if exists log_name = base + '.ufits-filter.log' ufitslib.removefile(log_name) ufitslib.setupLogging(log_name) FNULL = open(os.devnull, 'w') cmd_args = " ".join(sys.argv)+'\n' ufitslib.log.debug(cmd_args) print "-------------------------------------------------------" #initialize script, log system info and usearch version ufitslib.SystemInfo() #Do a version check usearch = args.usearch ufitslib.versionDependencyChecks(usearch) #check if otu_table is empty ufitslib.log.info("Loading OTU table: %s" % args.otu_table)