header=None) pd.Series(dataset.barcode).to_csv(imputed_dir + 'barcode.txt', sep='\t', index=False, header=None) elif args.impute: print("Saving imputed data") recon_x = pd.DataFrame(recon_x.T, index=dataset.peaks, columns=dataset.barcode) recon_x.to_csv(os.path.join(outdir, 'imputed_data.txt'), sep='\t') # torch.save(model.to('cpu').state_dict(), os.path.join(outdir, 'model.pt')) # save model # if not args.no_tsne: print("Plotting embedding") if args.reference: ref = pd.read_csv(args.reference, sep='\t', header=None, index_col=0)[1] labels = ref.reindex(dataset.barcode, fill_value='unknown') else: labels = pred plot_embedding(feature, labels, method=args.emb, save=os.path.join(outdir, 'emb_{}.pdf'.format(args.emb)), save_emb=os.path.join(outdir, 'emb_{}.txt'.format(args.emb))) # plot_embedding(feature, labels, # save=os.path.join(outdir, 'tsne.pdf'), save_emb=os.path.join(outdir, 'tsne.txt'))
# 3. imputed data if args.impute or args.binary: recon_x = model.encodeBatch(testloader, device, out='x', transforms=[normalizer.inverse_transform]) if args.binary: import scipy print("Saving binary imputed data") recon_x = binarization(recon_x, dataset.data).T imputed_dir = outdir+'/binary_imputed/' os.makedirs(imputed_dir, exist_ok=True) scipy.io.mmwrite(imputed_dir+'count.mtx', recon_x) pd.Series(dataset.peaks).to_csv(imputed_dir+'peak.txt', sep='\t', index=False, header=None) pd.Series(dataset.barcode).to_csv(imputed_dir+'barcode.txt', sep='\t', index=False, header=None) elif args.impute: print("Saving imputed data") recon_x = pd.DataFrame(recon_x.T, index=dataset.peaks, columns=dataset.barcode) recon_x.to_csv(os.path.join(outdir, 'imputed_data.txt'), sep='\t') # torch.save(model.to('cpu').state_dict(), os.path.join(outdir, 'model.pt')) # save model if not args.no_tsne: print("Plotting tSNE embedding") if args.reference: ref = pd.read_csv(args.reference, sep='\t', header=None, index_col=0)[1] labels = ref.reindex(dataset.barcode, fill_value='unknown') else: labels = pred plot_embedding(feature, labels, save=os.path.join(outdir, 'tsne.pdf'), save_emb=os.path.join(outdir, 'tsne.txt'))