def run(self):
def load_evals(tx_mode):
"""Loads the error tracks from the database"""
cds_table = tools.sqlInterface.tables['CDS'][tx_mode]['evaluation']
mrna_table = tools.sqlInterface.tables['mRNA'][tx_mode]['evaluation']
cds_df = pd.read_sql_table(cds_table.__tablename__, engine).set_index('AlignmentId')
mrna_df = pd.read_sql_table(mrna_table.__tablename__, engine).set_index('AlignmentId')
return {'CDS': cds_df, 'mRNA': mrna_df}
pipeline_args = self.get_pipeline_args()
track, trackdb = self.output()
chrom_sizes = GenomeFiles.get_args(pipeline_args, self.genome).sizes
engine = tools.sqlInterface.create_engine('sqlite:///' + pipeline_args.dbs[self.genome])
evals = {tx_mode: load_evals(tx_mode) for tx_mode in self.tx_modes}
consensus_args = Consensus.get_args(pipeline_args, self.genome)
consensus_gp_info = pd.read_csv(consensus_args.consensus_gp_info, sep='\t',
header=0, na_filter=False).set_index('transcript_id')
aln_ids = set(consensus_gp_info.alignment_id)
rows = []
for aln_id in aln_ids:
tx_mode = tools.nameConversions.alignment_type(aln_id)
if tx_mode not in ['transMap', 'augTM', 'augTMR']:
continue
mode = 'CDS'
df = tools.misc.slice_df(evals[tx_mode][mode], aln_id)
if len(df) == 0:
mode = 'mRNA'
df = tools.misc.slice_df(evals[tx_mode][mode], aln_id)
for tx_id, s in df.iterrows():
bed = s.tolist()
bed[3] = '/'.join([tx_id, bed[3], mode])
rows.append(bed)
tmp = luigi.LocalTarget(is_tmp=True)
with tmp.open('w') as tmp_handle:
tools.fileOps.print_rows(tmp_handle, rows)
tools.procOps.run_proc(['bedSort', tmp.path, tmp.path])
with track.open('w') as outf:
cmd = ['bedToBigBed', '-type=bed12', '-tab', tmp.path, chrom_sizes, '/dev/stdout']
tools.procOps.run_proc(cmd, stdout=outf, stderr='/dev/null')
with trackdb.open('w') as outf:
outf.write(error_template.format(genome=self.genome, path=os.path.basename(track.path)))
__init__.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录