【发布时间】:2015-04-26 04:20:56
【问题描述】:
我有序列文件和条形码文件。条形码文件可能具有任何长度的条形码,例如“ATTG、AGCT、ACGT”。例如,序列文件看起来像“ATTGCCCCCCCGGGGG, ATTGTTTTTTT, AGCTAAAA”。我需要将条形码与开头包含它们的序列进行匹配。然后对于具有相同条形码的每组序列,我必须使用程序的其余部分(已经编写)对它们进行计算。我只是不知道如何让他们匹配。我已经使用了打印语句,它被搞砸的部分是“potential_barcode = line(:len(barcode)”行。此外,它说#simple to fasta 那是我应该在匹配序列中阅读的地方。我对此很陌生,所以我可能犯了很多错误。感谢您的帮助!
bcodefname = sys.argv[1]
infname = sys.argv[2]
barcodefile = open(bcodefname, "r")
for barcode in barcodefile:
barcode = barcode.strip()
print "barcode: %s" % barcode
outfname = "%s.%s" % (bcodefname,barcode)
# print outfname
outf = open("outfname", "w")
handle = open(infname, "r")
for line in handle:
potential_barcode = line[:len(barcode)]
print potential_barcode
if potential_barcode == barcode:
outseq = line[len(barcode):]
sys.stdout.write(outseq)
outf.write(outseq)
fastafname = infname + ".fasta"
print fastafname
mafftfname = fastafname + ".mafft"
stfname = mafftfname + ".stock"
print stfname
#simp to fasta#
# handle = open(infname, "r")
outf2 = open(fastafname, "w")
for line in handle:
linearr = line.split()
seqid = linearr[0]
seq = linearr[1]
outf2.write(">%s\n%s\n" % (seqid,seq))
# handle.close()
# outf.close()
#mafft#
cmd = "mafft %s > %s" % (fastafname,mafftfname)
sys.stderr.write("command: %s\n" % cmd)
os.system(cmd)
sys.stderr.write("command done\n")
【问题讨论】:
-
我没有看到
potential_barcode = line[:len(barcode)]行有问题,它适用于我所有的简单测试用例。您能否提供一些产生错误结果的示例条形码/行对? -
贾斯汀,由于您是新用户并且尚未发布更新,我会提一下,如果下面的答案对您有所帮助,您应该考虑将其标记为“已接受”。