本文整理汇总了Python中track.Track.ucsc_targets方法的典型用法代码示例。如果您正苦于以下问题:Python Track.ucsc_targets方法的具体用法?Python Track.ucsc_targets怎么用?Python Track.ucsc_targets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类track.Track
的用法示例。
在下文中一共展示了Track.ucsc_targets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: output_aligns
# 需要导入模块: from track import Track [as 别名]
# 或者: from track.Track import ucsc_targets [as 别名]
def output_aligns(outfile, aligns, track_name=None, contigs=None, append=False,
header=True, genome=None, refseq=None, color=None, by_fasta=False, annodir=None):
"""Outputs alignments to file"""
ext = os.path.splitext(outfile)[1]
if append:
out = open(outfile, 'a')
else:
out = open(outfile, 'w')
# desc == name
track_desc = track_name
if aligns:
if track_name and genome:
Track.ucsc_targets(genome, aligns, annodir)
if header and track_name:
header_line = "track name=\"%s\" description=\"%s\" visibility=%d itemRgb=\"On\"" % (track_name, track_desc, 3)
if color is not None:
header_line += ' color=\"%s\"' % (color)
out.write("%s\n" % (header_line))
# map contig to contig name
contig_dict = None
if contigs:
contig_dict = dict((contig.num, contig) for contig in contigs)
# sort alignments by contig order in original input fasta file
if by_fasta:
count = 0
ordered = {}
for contig in contigs:
ordered[contig.num] = count
count += 1
aligns.sort(lambda x,y: ordered[x.query] - ordered[y.query])
for align in aligns:
contig = align.query
if ' ' in contig:
contig = align.query.split(" ")[0]
if contig_dict and contig_dict.has_key(contig):
align.contig = contig_dict[contig]
if ext == ".gff":
out.write(align.gff("exon"))
elif ext == ".psl":
out.write(align.psl(refseq=refseq, genome=genome))
out.close()