shell脚本使用小技巧-持续更新-这个值得关注因为我真的会持续更新

1.假如下面的shell脚本"2024_extractrG4_calculating_score_filternonoverlapG4.sh"

#!/bin/bash
python lin_change_gff3original.py -i iwgsc_refseqv2.1_annotation_200916_HC_LC.gff3 -o iwgsc_refseqv2.1_annotation_200916_HC_LC.gff4


# Define base filenames
fasta_base="iwgsc_refseqv2.1_annotation_200916_HC_LC_mrna.fasta"
gff_file="iwgsc_refseqv2.1_annotation_200916_HC_LC.gff4"

# Array of types
types=("G4" "C4" "A4" "T4")

# Loop through each type and process files accordingly
for type in "${types[@]}"
do
    # Python script to extract r[type] structures
    python lin_20240425_extract_r${type}.py -f1 "$fasta_base" -f2 "lijinonextended_mrna_allr${type}output.fasta"

    # R script to calculate r[type] score
    Rscript lin_20240425_calculating_r${type}score.R -i "lijinonextended_mrna_allr${type}output.fasta" -o "lijinonextended_mrna_allr${type}output1.fasta"

    # Python script to annotate with gff4
    python "lin_annotating_rG4_with_gff4.py" -g "$gff_file" -f "lijinonextended_mrna_allr${type}output1.fasta" -o "lijinonextended_mrna_allr${type}output2.fasta"
    
    less "lijinonextended_mrna_allr${type}output2.fasta" | grep -E 'Id|five' > "five_r${type}_total.txt"
    less "lijinonextended_mrna_allr${type}output2.fasta" | grep -E 'Id|CDS' > "cds_r${type}_total.txt"
    less "lijinonextended_mrna_allr${type}output2.fasta" | grep -E 'Id|three' > "three_r${type}_total.txt"
    cp "lijinonextended_mrna_allr${type}output2.fasta" "mrna_r${type}_total.txt"
    
    python lin_filter_non-overlap_rG4.py -f1 "five_r${type}_total.txt" -f2 "five_r${type}_total1.txt"
    python lin_filter_non-overlap_rG4.py -f1 "cds_r${type}_total.txt" -f2 "cds_r${type}_total1.txt"
    python lin_filter_non-overlap_rG4.py -f1 "three_r${type}_total.txt" -f2 "three_r${type}_total1.txt"
    python lin_filter_non-overlap_rG4.py -f1 "mrna_r${type}_total.txt" -f2 "mrna_r${type}_total1.txt"
done



types=("G4" "C4" "A4" "T4")

# Loop through each type and process files accordingly
for type in "${types[@]}"
do
    mv "five_r${type}_total1.txt" "five_r${type}_total.txt"
    mv "cds_r${type}_total1.txt" "cds_r${type}_total.txt"
    mv "three_r${type}_total1.txt" "three_r${type}_total.txt"
    mv "mrna_r${type}_total1.txt" "mrna_r${type}_total.txt"

    rm "lijinonextended_mrna_allr${type}output.fasta"
    rm "lijinonextended_mrna_allr${type}output1.fasta"
    rm "lijinonextended_mrna_allr${type}output2.fasta"
done

1.如果,我后台运行这个脚本之后,想取消总的进程,可以这样操作:

ps aux | grep 2024_extractrG4_calculating_score_filternonoverlapG4.sh 
kill -SIGINT 2852911

2.查看进程占用的线程数,比如查看python占用的线程数,其中,nlwp 代表 number of lightweight processes,即线程数。

ps -o nlwp,pid,cmd -C python

3.使用 sed 命令删除回车符:

sed -i 's/\r//g' tracks_analysis_multiprocessing.R

4.目录存在,立即删除再创建,不存在,直接创建

# 定义目录名称
DIRECTORY="Meta15d_output"

# 检查目录是否存在
if [ -d "$DIRECTORY" ]; then
    # 如果存在,则删除该目录
    rm -rf "$DIRECTORY"
    echo "目录 $DIRECTORY 已删除。"
fi

# 创建目录
mkdir "$DIRECTORY"
echo "目录 $DIRECTORY 已创建。"

5.如何快速回到上一个工作目录,不是返回该路径下的上一层目录

ctrl -

6.如何快速清除当前命令行后面的代码,注意不是清空屏幕

ctrl k

7.如何快速清除当前命令行前面的代码,注意不是清空屏幕

ctrl u

8.无需sort,直接对指定行去重,当然如果你有特殊要求,可以自己排序,如下:无需对第二列sort,可以直接去重

less a.txt | awk '!seen[$2]++'

在这里插入图片描述
9.如何使用id,直接从fasta文件,查看对应value的length

(py3.8) [2020200461@c65 RiboSeq]$ seqkit grep -p "TraesCS5D03G0974400.1" transcripts.fa |seqkit fx2tab -l -n
TraesCS5D03G0974400.1	1232

10.替换文件中的某些字符,直接在原文件上修改

sed -i 's/Chr//g' ZmsnoRNA.bed

11.如何注销掉shell脚本含有某些字符或者单词的行,下面是注释掉含有fastp的行

:argdo %s/^.*fastp.*$/# &/ | update
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值