def main_align(args, stdout, stderr) : if args.outDir is None : args.outDir = "." for fastaFile in args.input : pyalign.ungapFastaFile(fastaFile, fastaFile + ".ungap.tmp") pyalign.runMafft(fastaFile + ".ungap.tmp", fastaFile + ".tmp", args.nthreads) out = os.path.join(args.outDir, os.path.basename(fastaFile)) os.rename(fastaFile + ".tmp", out) os.remove(fastaFile + ".ungap.tmp")
def main_ungap(args, stdout, stderr) : if args.all : assert args.position is None and args.seq is None and args.syncNtDir is None for inputFile in args.input : stderr.write("Processing file " + inputFile + "\n") outFile = os.path.join(args.outDir, inputFile) pyalign.ungapFastaFile(inputFile, outFile) if args.position is not None or args.seq is not None : if args.position is None : args.position = 1 if args.seq is None : args.seq = 0 for inputFile in args.input : stderr.write("Processing file " + inputFile + "\n") if args.outDir is None : outFile = inputFile else : outFile = os.path.join(args.outDir, os.path.basename(inputFile)) try : inputAln = AlignIO.read(inputFile, "fasta") loaded = True except ValueError : loaded = False if args.outDir == "." : os.remove(outFile) if loaded : ungapResult = pyalign.ungapAln(inputAln, args.position, args.seq) outputAln = ungapResult["ungappedAln"] with open(outFile, "w") as fo : for seq in outputAln : fo.write(">" + seq.description + "\n") fo.write(str(seq.seq) + "\n") if args.syncNtDir is not None : ntFile = os.path.join(args.syncNtDir, os.path.basename(inputFile) + ".alnNt") pyalign.ungapNtAlnFile(ntFile, ungapResult["removedSeq"], ungapResult["removedPos"], ntFile)
def test_gapInSeqs_000(self) : mod.ungapFastaFile(tf("inputFile3.fa"), tf("_testFile3.fa")) self.assertFileEqual(tf("_testFile3.fa"), tf("outputFile3.fa"))
def test_noGap_000(self) : mod.ungapFastaFile(tf("inputFile1.fa"), tf("_testFile1.fa")) self.assertFileEqual(tf("_testFile1.fa"), tf("outputFile1.fa"))