{"id":632,"date":"2025-10-15T10:44:10","date_gmt":"2025-10-15T02:44:10","guid":{"rendered":"https:\/\/www.kz-hub.tech\/?p=632"},"modified":"2025-10-15T10:44:10","modified_gmt":"2025-10-15T02:44:10","slug":"%e4%bd%bf%e7%94%a8copykat%e8%bf%9b%e8%a1%8c%e5%8d%95%e7%bb%86%e8%83%9e%e6%81%b6%e6%80%a7%e7%bb%86%e8%83%9e%e9%89%b4%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/www.kz-hub.tech\/index.php\/2025\/10\/15\/%e4%bd%bf%e7%94%a8copykat%e8%bf%9b%e8%a1%8c%e5%8d%95%e7%bb%86%e8%83%9e%e6%81%b6%e6%80%a7%e7%bb%86%e8%83%9e%e9%89%b4%e5%ae%9a\/","title":{"rendered":"\u4f7f\u7528CopyKAT\u8fdb\u884c\u5355\u7ec6\u80de\u6076\u6027\u7ec6\u80de\u9274\u5b9a"},"content":{"rendered":"<p>github\u5b98\u7f51\uff1a<a href=\"https:\/\/github.com\/navinlabcode\/copykat\">https:\/\/github.com\/navinlabcode\/copykat<\/a><\/p>\n<ul>\n<li><strong>copykat\u5bf9\u5927\u6837\u672c\u6570\u636e\u7684\u5206\u6790\u975e\u5e38\u6162\uff0c\u9700\u8981\u5206\u6bcf\u4e2a\u6837\u672c\u5355\u72ec\u5206\u6790<\/strong><\/li>\n<\/ul>\n<h2>1. \u5206\u6837\u672c\u51c6\u5907\u8868\u8fbe\u77e9\u9635\u548c\u7ec6\u80de\u4e9a\u578b\u4fe1\u606f<\/h2>\n<pre><code class=\"language-R\">library(Seurat)\nlibrary(copykat)\nlibrary(qs)\nlibrary(data.table)\n\n# \u8bfb\u53d6\u5408\u5e76\u540e\u7684seurat\u6587\u4ef6\nseu_obj &lt;- qread(&quot;\/groups\/phyllodes\/home\/share\/Results\/transfer\/16samples_Merged_AllCells_Annotated_Final.qs&quot;)\n\nfor (id in unique(seu_obj@meta.data$orig.ident)){\n  tmp_seuobj &lt;- subset(seu_obj,orig.ident==id)\n  exp.rawdata &lt;- GetAssayData(tmp_seuobj,slot = &quot;counts&quot;)\n  exp.rawdata &lt;- as.matrix(exp.rawdata)\n  fwrite(exp.rawdata,\n         file=paste0(&quot;\/groups\/phyllodes\/home\/share\/Results\/scRNA\/copykat\/&quot;,id,&quot;.exp.rawdata.txt&quot;),\n         sep=&quot;\\t&quot;,\n         quote = FALSE,\n         row.names = TRUE)\n\n  # \u51c6\u5907\u7ec6\u80de\u4e9a\u578b\u4fe1\u606f\n  Idents(tmp_seuobj)=tmp_seuobj$CellType_Minor\n\n  #sce &lt;- SetIdent(sce, value = sce@meta.data$compare)\n  groupinfo=data.frame(v1=colnames(exp.rawdata),\n                       v2= Idents(tmp_seuobj))\n  fwrite(groupinfo,\n         file = paste0(&quot;\/groups\/phyllodes\/home\/share\/Results\/scRNA\/copykat\/&quot;,id,&quot;.groupinfo.txt&quot;),\n         sep = &#039;\\t&#039;,\n         quote = F,\n         col.names = F,\n         row.names = F)\n}<\/code><\/pre>\n<h2>2. \u8fd0\u884c CopyKAT \u7684\u6a21\u677f\u6587\u4ef6<\/h2>\n<p>RunCopyKAT_EXAMPLE.R<\/p>\n<pre><code>library(Seurat)\nlibrary(copykat)\nlibrary(qs)\nlibrary(data.table)\nmessage(&quot;Running EXAMPLE...&quot;)\n\n# \u5728\u8fd9\u91cc\u8bbe\u5b9a\u4f5c\u4e3a\u5bf9\u7167\u7684\u7ec6\u80de\u7c7b\u578b\nreference_cells &lt;- c(&quot;SELL+_CD4+_Tn&quot;,&quot;FOXP3+_Treg&quot;,&quot;CD4+_Tem&quot;,&quot;ANXA1+_CD4+_Tcm&quot;,\n                     &quot;CXCL13+_Tfh&quot;,&quot;CD8+_MAIT&quot;,&quot;GZMK+_CD8+_Tem&quot;,&quot;ZNF683+CXCR6-_CD8+_Trm&quot;,\n                     &quot;ZNF683+CXCR6+_CD8+_Trm&quot;,&quot;KLRG1+_CD8+_Temra\/Teff&quot;,&quot;SELL+_CD8+_Tn\/Tcm&quot;,&quot;RSAD2+GZMK+_CD8+_Tem&quot;,\n                     &quot;GZMK+PDCD1+_CD8+_Tex&quot;,&quot;Proliferating_CD8+_T&quot;, &quot;CD56dimCD16hi_NKT&quot;,&quot;CD56brightCD16lo_NK&quot;,\n                     &quot;CD56dimCD16hi_NK&quot;,&quot;IL41+KIT+_NK&quot;,&quot;Bn&quot;,&quot;Bm&quot;,\n                     &quot;ASCs&quot;,&quot;Bgc&quot;,&quot;ASC-like&quot;,&quot;Unknown_B&quot;,\n                     &quot;Macrophages&quot;,&quot;CD1C+_cDC2&quot;,&quot;MKI67+_Proliferating_mono\/macro&quot;,&quot;Monocytes&quot;,&quot;MastCells&quot;)\n\nexp.rawdata &lt;- fread(&quot;EXAMPLE.exp.rawdata.txt&quot;,header = TRUE)\nrownames(exp.rawdata) &lt;- exp.rawdata$V1\nexp.rawdata$V1 &lt;- NULL\ngroup.info &lt;- fread(&quot;EXAMPLE.groupinfo.txt&quot;,header = F)\ngroup.info &lt;- subset(group.info,V2 %in% reference_cells)\ncopykat_obj &lt;- copykat(rawmat=exp.rawdata,\n                       id.type=&quot;S&quot;,\n                       ngene.chr=5,\n                       win.size=25, KS.cut=0.1,\n                       sam.name=&quot;EXAMPLE&quot;,\n                       distance=&quot;euclidean&quot;,\n                       norm.cell.names=group.info$V1,\n                       output.seg=&quot;FLASE&quot;,\n                       plot.genes=&quot;TRUE&quot;,\n                       genome=&quot;hg20&quot;,\n                       n.cores=4)\n\nqsave(copykat_obj,&quot;EXAMPLE_copykat_res.qs&quot;)<\/code><\/pre>\n<h2>3. \u5bf9\u6bcf\u4e00\u4e2a\u6837\u672c\u751f\u6210\u4e00\u4e2a\u8fd0\u884c\u811a\u672c<\/h2>\n<pre><code>#!\/bin\/bash\n\n# Directory containing your .exp.rawdata.txt files\nsample_directory=&quot;.&quot;\n\n# The path to your original R script\ntemplate_script=&quot;RunCopyKAT_EXAMPLE.R&quot;\n\n# Loop through the files with .exp.rawdata.txt extension\nfor sample_file in ${sample_directory}\/FETB*.exp.rawdata.txt; do\n    # Extract the sample number from the filename (e.g., FETB01-MPT-01)\n    sample_number=$(basename $sample_file .exp.rawdata.txt)\n\n    # Copy the template script to a new file based on the sample number\n    cp $template_script &quot;RunCopyKAT_${sample_number}.R&quot;\n\n    # Replace the placeholder EXAMPLE in the new R script with the sample number\n    sed -i &quot;s\/EXAMPLE\/${sample_number}\/g&quot; &quot;RunCopyKAT_${sample_number}.R&quot;\ndone<\/code><\/pre>\n<h2>4. \u6279\u91cf\u8fd0\u884c CopyKAT<\/h2>\n<pre><code>for r_script in RunCopyKAT_FETB*.R; do echo &quot;Rscript $r_script&quot; &gt;&gt; RunCopyKAT_Individual.sh; done &amp;&amp; chmod +x RunCopyKAT_Individual.sh\n\nnohup .\/RunCopyKAT_Individual.sh &gt; RunCopyKAT_Individual.log 2&gt;&amp;1 &amp;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>github\u5b98\u7f51\uff1ahttps:\/\/github.com\/navinlabcode\/copykat copyka&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-632","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/comments?post=632"}],"version-history":[{"count":1,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/632\/revisions"}],"predecessor-version":[{"id":633,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/posts\/632\/revisions\/633"}],"wp:attachment":[{"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/media?parent=632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/categories?post=632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kz-hub.tech\/index.php\/wp-json\/wp\/v2\/tags?post=632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}