首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Nodejs进阶:如何玩转子进程(child_process)

Nodejs进阶:如何玩转子进程(child_process)

作者头像
IMWeb前端团队
发布于 2018-01-08 07:27:57
发布于 2018-01-08 07:27:57
4.6K00
代码可运行
举报
文章被收录于专栏:IMWeb前端团队IMWeb前端团队
运行总次数:0
代码可运行

本文作者:IMWeb 陈映平 原文出处:IMWeb社区 未经同意,禁止转载

模块概览

在node中,child_process这个模块非常重要。掌握了它,等于在node的世界开启了一扇新的大门。熟悉shell脚本的同学,可以用它来完成很多有意思的事情,比如文件压缩、增量部署等,感兴趣的同学,看文本文后可以尝试下。

举个简单的例子:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

几种创建子进程的方式

注意事项:

  • 下面列出来的都是异步创建子进程的方式,每一种方式都有对应的同步版本。
  • .exec().execFile().fork()底层都是通过.spawn()实现的。
  • .exec()execFile()额外提供了回调,当子进程停止的时候执行。

child_process.spawn(command, args) child_process.exec(command, options) child_process.execFile(file, args, callback) child_process.fork(modulePath, args)

child_process.exec(command, options)

创建一个shell,然后在shell里执行命令。执行完成后,将stdout、stderr作为参数传入回调方法。

spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete.

例子如下:

  1. 执行成功,errornull;执行失败,errorError实例。error.code为错误码,
  2. stdoutstderr为标准输出、标准错误。默认是字符串,除非options.encodingbuffer
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var exec = require('child_process').exec;

// 成功的例子
exec('ls -al', function(error, stdout, stderr){
    if(error) {
        console.error('error: ' + error);
        return;
    }
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + typeof stderr);
});

// 失败的例子
exec('ls hello.txt', function(error, stdout, stderr){
    if(error) {
        console.error('error: ' + error);
        return;
    }
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
});
参数说明:
  • cwd:当前工作路径。
  • env:环境变量。
  • encoding:编码,默认是utf8
  • shell:用来执行命令的shell,unix上默认是/bin/shwindows上默认是cmd.exe
  • timeout:默认是0。
  • killSignal:默认是SIGTERM
  • uid:执行进程的uid。
  • gid:执行进程的gid。
  • maxBuffer: 标准输出、错误输出最大允许的数据量(单位为字节),如果超出的话,子进程就会被杀死。默认是200*1024(就是200k啦)

备注:

  1. 如果timeout大于0,那么,当子进程运行超过timeout毫秒,那么,就会给进程发送killSignal指定的信号(比如SIGTERM)。
  2. 如果运行没有出错,那么errornull。如果运行出错,那么,error.code就是退出代码(exist code),error.signal会被设置成终止进程的信号。(比如CTRL+C时发送的SIGINT
风险项

传入的命令,如果是用户输入的,有可能产生类似sql注入的风险,比如

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
exec('ls hello.txt; rm -rf *', function(error, stdout, stderr){
    if(error) {
        console.error('error: ' + error);
        // return;
    }
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
});
备注事项

Note: Unlike the exec(3) POSIX system call, child_process.exec() does not replace the existing process and uses a shell to execute the command.

child_process.execFile(file, args, callback)

.exec()类似,不同点在于,没有创建一个新的shell。至少有两点影响

  1. child_process.exec()效率高一些。(实际待测试)
  2. 一些操作,比如I/O重定向,文件glob等不支持。

similar to child_process.exec() except that it spawns the command directly without first spawning a shell.

file: 可执行文件的名字,或者路径。

例子:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');

child_process.execFile('node', ['--version'], function(error, stdout, stderr){
    if(error){
        throw error;
    }
    console.log(stdout);
});

child_process.execFile('/Users/a/.nvm/versions/node/v6.1.0/bin/node', ['--version'], function(error, stdout, stderr){
    if(error){
        throw error;
    }
    console.log(stdout);
});

====== 扩展阅读 =======

从node源码来看,exec()execFile()最大的差别,就在于是否创建了shell。(execFile()内部,options.shell === false),那么,可以手动设置shell。以下代码差不多是等价的。win下的shell设置有所不同,感兴趣的同学可以自己试验下。

备注:execFile()内部最终还是通过spawn()实现的, 如果没有设置 {shell: '/bin/bash'},那么 spawm() 内部对命令的解析会有所不同,execFile('ls -al .') 会直接报错。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');
var execFile = child_process.execFile;
var exec = child_process.exec;

exec('ls -al .', function(error, stdout, stderr){
    if(error){
        throw error;
    }
    console.log(stdout);
});

execFile('ls -al .', {shell: '/bin/bash'}, function(error, stdout, stderr){
    if(error){
        throw error;
    }
    console.log(stdout);
});

child_process.fork(modulePath, args)

modulePath:子进程运行的模块。

参数说明:(重复的参数说明就不在这里列举)

  • execPath: 用来创建子进程的可执行文件,默认是/usr/local/bin/node。也就是说,你可通过execPath来指定具体的node可执行文件路径。(比如多个node版本)
  • execArgv: 传给可执行文件的字符串参数列表。默认是process.execArgv,跟父进程保持一致。
  • silent: 默认是false,即子进程的stdio从父进程继承。如果是true,则直接pipe向子进程的child.stdinchild.stdout等。
  • stdio: 如果声明了stdio,则会覆盖silent选项的设置。

例子1:silent

parent.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');

// 例子一:会打印出 output from the child
// 默认情况,silent 为 false,子进程的 stdout 等
// 从父进程继承
child_process.fork('./child.js', {
    silent: false
});

// 例子二:不会打印出 output from the silent child
// silent 为 true,子进程的 stdout 等
// pipe 向父进程
child_process.fork('./silentChild.js', {
    silent: true
});

// 例子三:打印出 output from another silent child
var child = child_process.fork('./anotherSilentChild.js', {
    silent: true
});

child.stdout.setEncoding('utf8');
child.stdout.on('data', function(data){
    console.log(data);
});

child.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log('output from the child');

silentChild.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log('output from the silent child');

anotherSilentChild.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log('output from another silent child');

例子二:ipc

parent.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');

var child = child_process.fork('./child.js');

child.on('message', function(m){
    console.log('message from child: ' + JSON.stringify(m));
});

child.send({from: 'parent'});
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
process.on('message', function(m){
    console.log('message from parent: ' + JSON.stringify(m));
});

process.send({from: 'child'});

运行结果

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
?  ipc git:(master) ? node parent.js
message from child: {"from":"child"}
message from parent: {"from":"parent"}

例子三:execArgv

首先,process.execArgv的定义,参考这里。设置execArgv的目的一般在于,让子进程跟父进程保持相同的执行环境。

比如,父进程指定了--harmony,如果子进程没有指定,那么就要跪了。

parent.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');

console.log('parent execArgv: ' + process.execArgv);

child_process.fork('./child.js', {
    execArgv: process.execArgv
});

child.js

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
console.log('child execArgv: ' + process.execArgv);

运行结果

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
?  execArgv git:(master) ? node --harmony parent.js
parent execArgv: --harmony
child execArgv: --harmony

例子3:execPath(TODO 待举例子)

child_process.spawn(command, args)

command:要执行的命令

options参数说明:

  • argv0:String 这货比较诡异,在uninx、windows上表现不一样。有需要再深究。
  • stdio:Array | String 子进程的stdio。参考这里
  • detached:Boolean 让子进程独立于父进程之外运行。同样在不同平台上表现有差异,具体参考这里
  • shell:Boolean | String 如果是true,在shell里运行程序。默认是false。(很有用,比如 可以通过 /bin/sh -c xxx 来实现 .exec() 这样的效果)

例子1:基础例子

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;
var ls = spawn('ls', ['-al']);

ls.stdout.on('data', function(data){
    console.log('data from child: ' + data);
});


ls.stderr.on('data', function(data){
    console.log('error from child: ' + data);
});

ls.on('close', function(code){
    console.log('child exists with code: ' + code);
});

例子2:声明stdio

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;
var ls = spawn('ls', ['-al'], {
    stdio: 'inherit'
});

ls.on('close', function(code){
    console.log('child exists with code: ' + code);
});

例子3:声明使用shell

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;

// 运行 echo "hello nodejs" | wc
var ls = spawn('bash', ['-c', 'echo "hello nodejs" | wc'], {
    stdio: 'inherit',
    shell: true
});

ls.on('close', function(code){
    console.log('child exists with code: ' + code);
});

例子4:错误处理,包含两种场景,这两种场景有不同的处理方式。

  • 场景1:命令本身不存在,创建子进程报错。
  • 场景2:命令存在,但运行过程报错。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;
var child = spawn('bad_command');

child.on('error', (err) => {
  console.log('Failed to start child process 1.');
});

var child2 = spawn('ls', ['nonexistFile']);

child2.stderr.on('data', function(data){
    console.log('Error msg from process 2: ' + data);
});

child2.on('error', (err) => {
  console.log('Failed to start child process 2.');
});

运行结果如下。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
?  spawn git:(master) ? node error/error.js
Failed to start child process 1.
Error msg from process 2: ls: nonexistFile: No such file or directory

例子5:echo "hello nodejs" | grep "nodejs"

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
// echo "hello nodejs" | grep "nodejs"
var child_process = require('child_process');

var echo = child_process.spawn('echo', ['hello nodejs']);
var grep = child_process.spawn('grep', ['nodejs']);

grep.stdout.setEncoding('utf8');

echo.stdout.on('data', function(data){
    grep.stdin.write(data);
});

echo.on('close', function(code){
    if(code!==0){
        console.log('echo exists with code: ' + code);
    }
    grep.stdin.end();
});

grep.stdout.on('data', function(data){
    console.log('grep: ' + data);
});

grep.on('close', function(code){
    if(code!==0){
        console.log('grep exists with code: ' + code);
    }
});

运行结果:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
?  spawn git:(master) ? node pipe/pipe.js
grep: hello nodejs

关于options.stdio

默认值:'pipe', 'pipe', 'pipe',这意味着:

  1. child.stdin、child.stdout 不是undefined
  2. 可以通过监听 data 事件,来获取数据。

基础例子

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;
var ls = spawn('ls', ['-al']);

ls.stdout.on('data', function(data){
    console.log('data from child: ' + data);
});

ls.on('close', function(code){
    console.log('child exists with code: ' + code);
});

通过child.stdin.write()写入

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var spawn = require('child_process').spawn;
var grep = spawn('grep', ['nodejs']);

setTimeout(function(){
    grep.stdin.write('hello nodejs \n hello javascript');
    grep.stdin.end();
}, 2000);

grep.stdout.on('data', function(data){
    console.log('data from grep: ' + data);
});

grep.on('close', function(code){
    console.log('grep exists with code: ' + code);
});

异步 vs 同步

大部分时候,子进程的创建是异步的。也就是说,它不会阻塞当前的事件循环,这对于性能的提升很有帮助。

当然,有的时候,同步的方式会更方便(阻塞事件循环),比如通过子进程的方式来执行shell脚本时。

node同样提供同步的版本,比如:

  • spawnSync()
  • execSync()
  • execFileSync()

关于options.detached

由于木有在windows上做测试,于是先贴原文

On Windows, setting options.detached to true makes it possible for the child process to continue running after the parent exits. The child will have its own console window. Once enabled for a child process, it cannot be disabled.

在非window是平台上的表现

On non-Windows platforms, if options.detached is set to true, the child process will be made the leader of a new process group and session. Note that child processes may continue running after the parent exits regardless of whether they are detached or not. See setsid(2) for more information.

默认情况:父进程等待子进程结束。

子进程。可以看到,有个定时器一直在跑

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var times = 0;
setInterval(function(){
    console.log(++times);
}, 1000);

运行下面代码,会发现父进程一直hold着不退出。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');
child_process.spawn('node', ['child.js'], {
    // stdio: 'inherit'
});

通过child.unref()让父进程退出

调用child.unref(),将子进程从父进程的事件循环中剔除。于是父进程可以愉快的退出。这里有几个要点

  1. 调用child.unref()
  2. 设置detachedtrue
  3. 设置stdioignore(这点容易忘)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');
var child = child_process.spawn('node', ['child.js'], {
    detached: true,
    stdio: 'ignore'  // 备注:如果不置为 ignore,那么 父进程还是不会退出
    // stdio: 'inherit'
});

child.unref();

stdio重定向到文件

除了直接将stdio设置为ignore,还可以将它重定向到本地的文件。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var child_process = require('child_process');
var fs = require('fs');

var out = fs.openSync('./out.log', 'a');
var err = fs.openSync('./err.log', 'a');

var child = child_process.spawn('node', ['child.js'], {
    detached: true,
    stdio: ['ignore', out, err]
});

child.unref();

exec()与execFile()之间的区别

首先,exec() 内部调用 execFile() 来实现,而 execFile() 内部调用 spawn() 来实现。

exec() -> execFile() -> spawn()

其次,execFile() 内部默认将 options.shell 设置为false,exec() 默认不是false。

Class: ChildProcess

  • 通过child_process.spawn()等创建,一般不直接用构造函数创建。
  • 继承了EventEmitters,所以有.on()等方法。

各种事件

close

当stdio流关闭时触发。这个事件跟exit不同,因为多个进程可以共享同个stdio流。

参数:code(退出码,如果子进程是自己退出的话),signal(结束子进程的信号) 问题:code一定是有的吗?(从对code的注解来看好像不是)比如用kill杀死子进程,那么,code是?

exit

参数:code、signal,如果子进程是自己退出的,那么code就是退出码,否则为null;如果子进程是通过信号结束的,那么,signal就是结束进程的信号,否则为null。这两者中,一者肯定不为null。 注意事项:exit事件触发时,子进程的stdio stream可能还打开着。(场景?)此外,nodejs监听了SIGINT和SIGTERM信号,也就是说,nodejs收到这两个信号时,不会立刻退出,而是先做一些清理的工作,然后重新抛出这两个信号。(目测此时js可以做清理工作了,比如关闭数据库等。)

SIGINT:interrupt,程序终止信号,通常在用户按下CTRL+C时发出,用来通知前台进程终止进程。 SIGTERM:terminate,程序结束信号,该信号可以被阻塞和处理,通常用来要求程序自己正常退出。shell命令kill缺省产生这个信号。如果信号终止不了,我们才会尝试SIGKILL(强制终止)。

Also, note that Node.js establishes signal handlers for SIGINT and SIGTERM and Node.js processes will not terminate immediately due to receipt of those signals. Rather, Node.js will perform a sequence of cleanup actions and then will re-raise the handled signal.

error

当发生下列事情时,error就会被触发。当error触发时,exit可能触发,也可能不触发。(内心是崩溃的)

  • 无法创建子进程。
  • 进程无法kill。(TODO 举例子)
  • 向子进程发送消息失败。(TODO 举例子)

message

当采用process.send()来发送消息时触发。 参数:message,为json对象,或者primitive value;sendHandle,net.Socket对象,或者net.Server对象(熟悉cluster的同学应该对这个不陌生)

.connected:当调用.disconnected()时,设为false。代表是否能够从子进程接收消息,或者对子进程发送消息。

.disconnect():关闭父进程、子进程之间的IPC通道。当这个方法被调用时,disconnect事件就会触发。如果子进程是node实例(通过child_process.fork()创建),那么在子进程内部也可以主动调用process.disconnect()来终止IPC通道。参考process.disconnect

非重要的备忘点

windows平台上的cmdbat

The importance of the distinction between child_process.exec() and child_process.execFile() can vary based on platform. On Unix-type operating systems (Unix, Linux, OSX) child_process.execFile() can be more efficient because it does not spawn a shell. On Windows, however, .bat and .cmd files are not executable on their own without a terminal, and therefore cannot be launched using child_process.execFile(). When running on Windows, .bat and .cmd files can be invoked using child_process.spawn() with the shell option set, with child_process.exec(), or by spawning cmd.exe and passing the .bat or .cmd file as an argument (which is what the shell option and child_process.exec() do).

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
// On Windows Only ...
const spawn = require('child_process').spawn;
const bat = spawn('cmd.exe', ['/c', 'my.bat']);

bat.stdout.on('data', (data) => {
  console.log(data);
});

bat.stderr.on('data', (data) => {
  console.log(data);
});

bat.on('exit', (code) => {
  console.log(`Child exited with code ${code}`);
});

// OR...
const exec = require('child_process').exec;
exec('my.bat', (err, stdout, stderr) => {
  if (err) {
    console.error(err);
    return;
  }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
单细胞专题 | 9.如何人工注释单细胞类群?
单细胞专题 | 1.单细胞测序(10×genomics技术)的原理 单细胞专题 | 2.如何开始单细胞RNASeq数据分析 单细胞专题 | 3.单细胞转录组的上游分析-从BCL到FASTQ 单细胞专题 | 4.单细胞转录组的上游分析-从SRA到FASTQ 单细胞专题 | 5.单细胞转录组的上游分析-从FASTQ到count矩阵 单细胞专题 | 6.单细胞下游分析——不同类型的数据读入 单细胞专题 | 7.单细胞下游分析——常规分析流程案例一 单细胞专题 | 8.单细胞类型注释之SingleR包详解
DoubleHelix
2022/12/16
7.8K0
单细胞专题 | 9.如何人工注释单细胞类群?
单细胞测序最好的教程(六):细胞类型注释
作者按 本教程将是本系列教程中最重要的一章,我们后续所有的单细胞分析,都要基于准确的细胞类型注释。本系列教程首发于“[单细胞最好的中文教程](single_cell_tutorial Readthedocs[1])”,未经授权许可,禁止转载。 全文字数|预计阅读时间: 4500|5min ——Starlitnightly
生信技能树jimmy
2023/08/31
4.7K0
单细胞测序最好的教程(六):细胞类型注释
单细胞转录组探索乳腺癌来源的内皮细胞
文章发表于:Oncotarget. 2018; 题目是:Single-cell RNA sequencing reveals gene expression signatures of breast cancer-associated endothelial cells
生信技能树jimmy
2020/03/27
6950
什么,你想要的单细胞亚群比例太少了?
本专辑将会系统性介绍单细胞图谱研究的标准数据分析思路,前面提到了:肿瘤样品的单细胞需要提取上皮细胞继续细分,眼尖的小伙伴们发现了一个问题, 就是它这个肝癌数据集里面的fibroblasts等细胞亚群占比非常少,如果真的要每个细胞亚群都继续细分, 对比例少的细胞分析起来会有误差。 我们再回顾一下这个发表于2020的文章,标题 是:《Single-cell transcriptomic architecture and intercellular crosstalk of human intrahepatic
生信技能树jimmy
2021/10/20
1.1K0
什么,你想要的单细胞亚群比例太少了?
单细胞测序揭示阿尔兹海默症的B细胞相关标志物
(3)然后文章对每一种细胞类型的进行了AD/Normal差异基因分析,以B细胞为例。
生信技能树jimmy
2022/03/14
1.3K0
单细胞测序揭示阿尔兹海默症的B细胞相关标志物
huARdb:单细胞水平克隆型-转录组分析的人类抗原受体数据库
人类适应性免疫系统是免疫系统的一个分支,负责特定抗原识别和清除。通过与特定抗原的相互作用,适应性免疫系统被激活,并可以存储针对目标抗原的长期免疫记忆。因此,具有高抗原特异性的长期免疫记忆可以在随后暴露于抗原期间产生更强大的反应。适应性免疫反应激活需要 T 或 B 细胞上表达的受体识别抗原,分别称为 T 细胞受体 (TCR) 或 B 细胞受体 (BCR)。
生信技能树jimmy
2022/03/14
9730
huARdb:单细胞水平克隆型-转录组分析的人类抗原受体数据库
CancerSEA ,一个上古时代的癌症单细胞数据库资源
可以看到, 在这个CancerSEA发表之后,他们居然还更新了两个数据集,有意思,一般来说大家发文章后“逃之夭夭”了,很少会继续维护的。(也算是数据库资源网页工具领域的一股清流)
生信技能树
2022/03/03
1.8K0
CancerSEA ,一个上古时代的癌症单细胞数据库资源
人类乳腺癌单细胞及空间分辨率图谱
乳腺癌可以根据雌激素受体(estrogen receptor, ER)、孕激素受体(progesterone receptor, PR)的表达以及人表皮生长因子受体2(HER2)的过度表达或HER2基因ERBB2的扩增,分为三种广泛的亚型:luminal (ER+,PR+/−);HER2+(HER2+,ER+/−,PR+/−);和三阴性乳腺癌(TNBC;ER−PR−HER2−)。乳腺癌还根据使用PAM50分为五种“内在”分子亚型:luminal(LumA和LumB)、HER2富集(HER2E)、基底样basal-like和正常样normal-like。
生信技能树jimmy
2023/11/18
6550
人类乳腺癌单细胞及空间分辨率图谱
CNS子刊思路大放送
参考我前面介绍过 CNS图表复现08—肿瘤单细胞数据第一次分群通用规则,这3大单细胞亚群构成了肿瘤免疫微环境的复杂。绝大部分文章都是抓住免疫细胞亚群进行细分,包括淋巴系(T,B,NK细胞)和髓系(单核,树突,巨噬,粒细胞)的两大类作为第二次细分亚群。但是也有不少文章是抓住stromal 里面的fibo 和endo进行细分,并且编造生物学故事的。而且这些亚群都可以继续细分:
生信技能树
2023/02/27
5380
CNS子刊思路大放送
读文献06-纯生信挖掘找到与黑色素瘤预后相关的T细胞亚型及肿瘤激活相关基因集
In this study, we utilized scRNA-seq profiles of CD8+ T cells in melanoma to derive a cluster of tumor-reactive T cells, and further developed a tumor-reactive signature (TRS) to indicate the tumor reactivity of tumor samples. We validated the ability of distinguishing tumor-reactive cells or cell groups of the TRS in multiple cohorts. Furthermore, we demonstrated significant correlation of the TRS with clinical outcomes and response to immunotherapy of melanoma patients
北野茶缸子
2022/12/10
5980
读文献06-纯生信挖掘找到与黑色素瘤预后相关的T细胞亚型及肿瘤激活相关基因集
胃上皮细胞单细胞亚群
参考我前面介绍过 CNS图表复现08—肿瘤单细胞数据第一次分群通用规则,这3大单细胞亚群构成了肿瘤免疫微环境的复杂。比如 Clin Cancer Res 2021; 的文章《Spatially Distinct Reprogramming of the Tumor Microenvironment Based On Tumor Invasion in Diffuse-Type Gastric Cancers 》,就是如此的第一层次降维聚类分群:
生信技能树jimmy
2022/04/18
1.5K0
胃上皮细胞单细胞亚群
免疫治疗前后T细胞亚群比例变化真的重要吗?准确吗?
全部的7个癌症相关样品的10x单细胞转录组数据的整合后走单细胞标准流程,降维聚类分群,一般来说肿瘤样品的单细胞就应该是首先是按照如下所示的标记基因进行第一次分群 :
生信技能树jimmy
2021/10/20
1K0
免疫治疗前后T细胞亚群比例变化真的重要吗?准确吗?
不应该让细胞数量成为你单细胞项目的限制
不应该是盲目追求细胞数量的增加,普通的单细胞数据分析其实并不受细胞数量的影响而有所不同。让我们看看同济大学最近发表的文章 Cell Death and Disease (2022)13:23 ; https://doi.org/10.1038/s41419-021-04477-y ,标题是:《Single-cell transcriptomic analysis reveals the critical molecular pattern of UV-induced cutaneous squamous cell carcinoma》
生信技能树
2022/03/03
7760
不应该让细胞数量成为你单细胞项目的限制
单细胞转录组数据处理之细胞亚群注释
因为参数需要自己摸索和调整,所以其实拿到细胞亚群数量是因而而异的,取决于你前面降维的程度,分群的算法和参数。不过最重要的是拿到了不同细胞亚群后需要对它进行命名,给出生物学的解释。不同的人分析同一个数据集,有略微不同的结果是可以接受的,保证自己的生物学故事圆满即可。
生信技能树jimmy
2020/03/27
5.6K0
现在单细胞还想“水”CNS恐怕得多组学了
两年前大家仍的都是一些图谱类的研究,不同的物种不同的器官组织测个十万左右的单细胞就是CNS文章啦,因为都是开创性的研究啊。微信群的大伙都是酸这些CNS说,只有有经费就可以“水”几篇。
生信技能树
2020/10/26
9760
现在单细胞还想“水”CNS恐怕得多组学了
单细胞亚群的生物学命名的4个规则
参考我前面介绍过 CNS图表复现08—肿瘤单细胞数据第一次分群通用规则,这3大单细胞亚群构成了肿瘤免疫微环境的复杂。绝大部分文章都是抓住免疫细胞亚群进行细分,包括淋巴系(T,B,NK细胞)和髓系(单核,树突,巨噬,粒细胞)的两大类作为第二次细分亚群。但是也有不少文章是抓住stromal 里面的 fibro 和endo进行细分,并且编造生物学故事的。
生信技能树
2024/04/13
9200
单细胞亚群的生物学命名的4个规则
【生信文献200篇】28 单细胞又发oncotarget了
英文标题: Single-cell RNA sequencing reveals gene expression signatures of breast cancer-associated endothelial cells
生信菜鸟团
2021/04/29
4900
【生信文献200篇】28 单细胞又发oncotarget了
人类胸腺发育的细胞图谱揭示了T细胞组库的形成
INTRODUCTION:胸腺(thymus)是 T 细胞发育和 T 细胞受体(T cell receptor, TCR)组库形成的重要器官,塑造了机体的适应性免疫。T 细胞的胸腺内发育有空间协调性,受胸腺微环境(thymic microenvironment)多种细胞类型的精细调节。尽管胸腺在多种动物模型中被广泛研究,目前尚缺少一份完整的人类胸腺图谱帮助我们理解人体免疫系统。
生信技能树jimmy
2021/04/16
4K1
人类胸腺发育的细胞图谱揭示了T细胞组库的形成
跟着小鱼头学单细胞测序-scRNA-seq数据的预处理与质控
前两期scRNA-seq分享讲到了测序的原理、应用以及测序方法,今天就进入了数据分析阶段了。scRNA-seq 与 bulk -RNA-seq 同样是RNA的通量测序数据,在前期质控与后期分析都有什么异同?今天就先聊一聊scRNA-seq的质控,让你对scRNA-seq质控有个基础而又详实的了解,避免掉坑。
作图丫
2022/03/29
9590
跟着小鱼头学单细胞测序-scRNA-seq数据的预处理与质控
肿瘤样品的单细胞需要提取上皮细胞继续细分
然后每个亚群进行第二层次细分亚群,甚至第三层次,第四次分群,结构清晰明了。我们以上皮细胞亚群的 细分来举例说明每个分析点的工作量:
生信技能树jimmy
2021/10/20
4.7K0
肿瘤样品的单细胞需要提取上皮细胞继续细分
推荐阅读
相关推荐
单细胞专题 | 9.如何人工注释单细胞类群?
更多 >
LV.0
这个人很懒,什么都没有留下~
目录
  • 模块概览
  • 几种创建子进程的方式
    • child_process.exec(command, options)
      • 参数说明:
      • 风险项
      • 备注事项
    • child_process.execFile(file, args, callback)
    • child_process.fork(modulePath, args)
    • child_process.spawn(command, args)
  • 关于options.stdio
    • 基础例子
    • 通过child.stdin.write()写入
  • 异步 vs 同步
  • 关于options.detached
    • 默认情况:父进程等待子进程结束。
    • 通过child.unref()让父进程退出
    • 将stdio重定向到文件
  • exec()与execFile()之间的区别
  • Class: ChildProcess
    • 各种事件
    • close
    • exit
    • error
    • message
  • 非重要的备忘点
    • windows平台上的cmd、bat
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档