忘记密码   免费注册 查看新帖 |

ChinaUnix.net

  平台 论坛 博客 文库 频道自动化运维 虚拟化 储存备份 C/C++ PHP MySQL 嵌入式 Linux系统
最近访问板块 发新帖
查看: 1290 | 回复: 9

[文本处理] 如何提取fasta特定长度的序列 [复制链接]

论坛徽章:
0
发表于 2018-04-05 23:24 |显示全部楼层
>scaffold180916
ACACTTGAAATCCCTTTGTCTTTTACCAACTTGTTGTCCATTTAACCCATTTTGCCCAAAGATCCCTTCTACCGTGAATCAAATCGGCCCTACAGCAGCCTTACATAATCACCTCATAGCTTCCTTGACCTGTTTGACCCCATAGCCCAATTTATCTACATCTTGTTATCCAGTTTATGTATTTGATCAGTTTTATCCCTCACAAANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGTTTTTATAAAGAAGAGGAATTAACTACCTTATAACTTATAAGCTGACTCTTTTTTTCAAAACATTATAATATGTATTTTGAATTAATTGGTAATTTGCATTGTGTTAATGTTAAAATAAATATTTCACTTTATAATTTGCAATTATGTAGATCTCAAAAACAATGGCATAATGTATAAAGTTCTTTTTCTTTGTATGTAAGATCATAATAAAATAATGATAATTCTAAAGTACATGAATTTATTTGCATTATACATACAATTAAAATTACAATTACAATCATTTCACAATAAATTAAATATTACAATTACAA
>scaffold180920
TTTCTAAATTTTATTATGTTACAAAACTTCATATTACTCTATTTTTATTATTTTACAAGTTTACAAATTTAAATTTTTTAATAAAATCATTTCACATTATTACAATTAAATTTTTACAAA
TATTTTACATACAATTAGAATTAGAATTACAATTTCACATACAATTACAATTAAAATTACAATTACAATTTTTGAATTTTACATACAATTACAATTACAATAAAAATTTTACAATTACAATCATTTCACAGTAATACAATTAAAATTTTACAAATATTTTACATACAATTAGAATTAGAATTACAATTTTACAATTTCACGTACAATTACAATTACAATTTTAGATTTTTACATACAATTACAATTATAATTTTAGAATTTTACATAAAATTTACAATTACAATTTTAGAATTTTACAAATTTACATATATACTATTACAATTACAATTTTAGAATTTTACATACAATTAGAATTAGAATTAGAATTTTACAATTTTACATATATATATATATATATATAATTACAATTAAAATTACAATTACAATCATTTCACAATAAATTAAATATTACAATTACAATTAAAATTTTACAAATATTTTACATACAATTAAAATTACAATTACAATCATTTCACAATAAATTAAATATTACAATTACAATTTATAAAGAAGAGGAATTAACTACCACATGAATTTATTTGCATTATACATATTTGCAATTAT
如上fasta序列,我想提取每条序列上下游各100bp的长度?如何进行操作呢?

论坛徽章:
16
程序设计版块每日发帖之星
日期:2016-05-03 06:20:0015-16赛季CBA联赛之八一
日期:2018-07-05 10:34:0915-16赛季CBA联赛之八一
日期:2018-07-03 16:56:4615-16赛季CBA联赛之深圳
日期:2018-06-15 14:59:3715-16赛季CBA联赛之青岛
日期:2018-06-08 13:45:2815-16赛季CBA联赛之同曦
日期:2018-06-04 19:42:2015-16赛季CBA联赛之山东
日期:2018-05-30 12:44:59CU十四周年纪念徽章
日期:2018-05-15 11:36:3815-16赛季CBA联赛之广东
日期:2018-05-14 09:52:4215-16赛季CBA联赛之深圳
日期:2018-05-04 21:53:0815-16赛季CBA联赛之辽宁
日期:2018-04-02 14:03:3915-16赛季CBA联赛之北京
日期:2018-03-23 15:24:07
发表于 2018-04-06 01:39 |显示全部楼层
本帖最后由 wh7211 于 2018-04-06 01:44 编辑

回复 1# 小小脑


<<<awk4.0+
  1. awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$0:$0}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c[i]);printf("%s|%s|%s|\n",b[i],substr(c[i],1,100),substr(c[i],d-99))}}' file
  2. >scaffold180916|ACACTTGAAATCCCTTTGTCTTTTACCAACTTGTTGTCCATTTAACCCATTTTGCCCAAAGATCCCTTCTACCGTGAATCAAATCGGCCCTACAGCAGCC|ATAATGATAATTCTAAAGTACATGAATTTATTTGCATTATACATACAATTAAAATTACAATTACAATCATTTCACAATAAATTAAATATTACAATTACAA|
  3. >scaffold180920|TTTCTAAATTTTATTATGTTACAAAACTTCATATTACTCTATTTTTATTATTTTACAAGTTTACAAATTTAAATTTTTTAATAAAATCATTTCACATTAT|CAATCATTTCACAATAAATTAAATATTACAATTACAATTTATAAAGAAGAGGAATTAACTACCACATGAATTTATTTGCATTATACATATTTGCAATTAT|
复制代码

论坛徽章:
0
发表于 2018-04-06 09:08 |显示全部楼层
回复 2# wh7211

厉害呀,大神!如果我还是要fasta格式的,就是不要前后的管道,又该如何操作呢

论坛徽章:
0
发表于 2018-04-06 09:28 |显示全部楼层
回复 2# wh7211

不好意思大神,我刚没仔细看,我知道如何操作了。谢谢大神

论坛徽章:
16
程序设计版块每日发帖之星
日期:2016-05-03 06:20:0015-16赛季CBA联赛之八一
日期:2018-07-05 10:34:0915-16赛季CBA联赛之八一
日期:2018-07-03 16:56:4615-16赛季CBA联赛之深圳
日期:2018-06-15 14:59:3715-16赛季CBA联赛之青岛
日期:2018-06-08 13:45:2815-16赛季CBA联赛之同曦
日期:2018-06-04 19:42:2015-16赛季CBA联赛之山东
日期:2018-05-30 12:44:59CU十四周年纪念徽章
日期:2018-05-15 11:36:3815-16赛季CBA联赛之广东
日期:2018-05-14 09:52:4215-16赛季CBA联赛之深圳
日期:2018-05-04 21:53:0815-16赛季CBA联赛之辽宁
日期:2018-04-02 14:03:3915-16赛季CBA联赛之北京
日期:2018-03-23 15:24:07
发表于 2018-04-06 12:59 |显示全部楼层
回复 3# 小小脑


  1. awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$0:$0}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c[i]);printf("%s\n%s\n%s\n",b[i],substr(c[i],1,100),substr(c[i],d-99))}}' file
  2. >scaffold180916
  3. ACACTTGAAATCCCTTTGTCTTTTACCAACTTGTTGTCCATTTAACCCATTTTGCCCAAAGATCCCTTCTACCGTGAATCAAATCGGCCCTACAGCAGCC
  4. ATAATGATAATTCTAAAGTACATGAATTTATTTGCATTATACATACAATTAAAATTACAATTACAATCATTTCACAATAAATTAAATATTACAATTACAA
  5. >scaffold180920
  6. TTTCTAAATTTTATTATGTTACAAAACTTCATATTACTCTATTTTTATTATTTTACAAGTTTACAAATTTAAATTTTTTAATAAAATCATTTCACATTAT
  7. CAATCATTTCACAATAAATTAAATATTACAATTACAATTTATAAAGAAGAGGAATTAACTACCACATGAATTTATTTGCATTATACATATTTGCAATTAT
复制代码

论坛徽章:
0
发表于 2018-04-12 14:24 |显示全部楼层
回复 5# wh7211
awk是4.01 version的
我进行如下代码:
awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$00}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c);printf("%s\n%s%s\n",b,substr(c,1,100),substr(c,d-99))}}' ptaeda_unpaired_filter.fasta|less -S
>C30462902_9_1183
aaccccaaattttgggcgccgcatggaaaccccaaattttgtgcgccgggtggaaacccc
aaattttgggtgccgggtggaaaccccaaattttgggcgaaa
ttttgggcgccgcatggaaaccccaaattttgggcgctaggtgcaaaccccaaattttgg
gcgccgcatggaaaccccaaattttgggcgctagg
>C30487642_123_1263
cccaaattttgggcgctgggtgaaaaccccaaattttgtgcgccgcatggaaaccccaaa
ttttgggcgctcggtggaaaccccaaattttgggcgccgttttggccgccgcatggaaaccccaaattttgggcgc
cgagtggaaaccccaaattttgagcaccgcatggaaaccccaaatttcgggcgccgggtg
g
>C30492480_19_1274
gcgccgcatggaaaccccaaattttggtcgccgagtggaaaccccaaatttgggcgcggc
tggaaaccccaaattttgggcgccgggtggaaaccccaagggtggaaaccccaaattttgggcgccggttggaaaccccaaa
ttttgggcgccgcatggaaaccccaaattttgggcaccgagtggaaaccccaaatt
随后计算长度
awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$00}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c);printf("%s\n%s%s\n",b,substr(c,1,100),substr(c,d-99))}}' ptaeda_unpaired_filter.fasta|awk '{print $1}' | awk '/^>/&&NR>1{print "";}{ printf "%s",/^>/ ? $0" "0 }END{printf("%s\n", $0)}' |awk '{print $1"\t"length($2)}'|less -S
>C30462902_9_1183       197
>C30487642_123_1263     197
>C30492480_19_1274      198

很奇怪不能得到一样的结果。
以下是序列,比较长
>C30462902_9_1183
aaccccaaattttgggcgccgcatggaaaccccaaattttgtgcgccgggtggaaacccc
aaattttgggtgccgggtggaaaccccaaattttgggcgccatggcgctgcatggaaacc
ccaaattctgggtgctctgtggaaaccccaaattttggctgcggcatgcaaaccccaaat
tttgggcgccgagtggaaaccccaaatttggccgtggcatggaatccccaaattttgggc
accggggggaaaccccaaattttgagcgccgcatggaaaccccaaattttgggcgctgga
tggaaaccccaaattttacgcgccgggtggaaaccccaagttttgggcgcagcatggaaa
cccgaaatcttgggcgccgggtggaaaccccaaattttgggcgctctgtggaaacccaaa
attttggccgccacatggaaaccccaaattttcggcgccgagtggaagcctaaattttgg
gcgccgcatggaaaccccaaattttgggcgccggttggaaagcccaaattttgggcgcta
ggtggaaaccctaaatttttggccccgcatggaaaccccaaattttcggcgccgagtcga
aaccccaaatcttgggcgccatgtcgaaaccccaaatttttggcgctgggtggaaacccc
aaattttgggcgccgcatagaaaccccaaattttgggcgccgcatggaaacaccaaattt
tgggcgttgagtggaaaccccaaattttgggcggaaaccccgaattttgtgcggaaaccc
caaattttgggtggaaaccccgaatttgggcgcggcatggaaaacccaaattttgggtgc
cgggtggaaaccccaaatttagggcgctgaggcgccgcatggaaaccccaaattttgggc
gctgggggaaaccccaaattttgggtgccgcatggaaaccccaaattttgggcgttgagt
ggaaaccccaaattttgggcaccgggtggaaacccaaaattttgggcgctgggtggaaac
cccaaattttggccaccgcatagaaaccccaaattttggacaccaagtggaaagcccaaa
ttttgggcgccgcatggaaaccccaaattttgggcgctaggtgcaaaccccaaattttgg
gcgccgcatggaaaccccaaattttgggcgctagg

>C30487642_123_1263
cccaaattttgggcgctgggtgaaaaccccaaattttgtgcgccgcatggaaaccccaaa
ttttgggcgctcggtggaaaccccaaattttgggcgccgggtgtaaaccccaaatttggc
cgcagcatggaaacaccaaattttgggcaccggacggaaaccccaaattttgagcgccgc
atggaaaccccaaattgtgggcaccgggtggaaacctcaaattttgggcgccgggtggaa
accccaaattttgggcgccgggtggaaaccccaaattttgggcgccggggcgccgaatgg
aaacaccaaattttgggcgccaggtggaaaccccaaatttttggcgctaggtgaaagccc
caaattttgggtgccgcatggaaaccccaaattttgggcgccgagtggaaaccccaaatt
ttgggtgctgggtggaagccccaaattttgggcgctgggtggaagccccaaattttgggc
atcgagtgaaaaccccaaagtttgggcgccgcatggaaaccccaaattttgggcaccggg
ttaaaaccccaaattttgggagccgcatggaaaccccaaattttgggcgccgcatgcaaa
ccccaatttttggtcgttggatggaaacgccaaatttgggcgcggcatggaaaccccaaa
ttttgggcgtcgggtggaaaccccaaattttggggccgggtggaaaccccaaattttggg
cgccggctggaaaccccaaattttggcgcgggctggaaaccccaaatttgggcgtggggt
ggaaaccccaaattttgggagccgggtggaaaccccaaattttgggcgctaggtggaaac
cccaaattttgggtgccaggtggaaattgcaaattttgagcaccggatggaaacccccaa
ttttgggtgccgcgtggaaaccccaaattttgggcgccttatggaaatcccaaattttgg
gcggcgggtggaaaccccaaattttcagcgccgtggcgccgcatggaaaccccaaatttt
gggcgctcggcggaaaccccaaattttggccgccgcatggaaaccccaaattttgggcgc
cgagtggaaaccccaaattttgagcaccgcatggaaaccccaaatttcgggcgccgggtg
g

>C30492480_19_1274
gcgccgcatggaaaccccaaattttggtcgccgagtggaaaccccaaatttgggcgcggc
tggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcgccggctagaaa
ccccaaatttttggcgccagctggaaaccccaaatttgggcgcggggtggaaaccccaaa
cttggggcgcctggtggaaaccccaaattttgggtgccgggtggaaaccccaaaatttga
gcgctgcatggaaaccccaaattttgggcgtcagatggaaaccccaaattttggggccga
gtggaaaccccaatttttgggcgcagggtggaaaccccaaatttgggcgccaggtggaaa
ccccaaattttgggcgccgagtggaaaccccaaattttaggcgccaggtggaaacccgaa
attttgggtgccaagtggaaaccccaaattttgtgtgccgagtggaaaccccaagttttg
ggcgccgcatggaaaccccaaattttgggcgctcggtgggaaccccaaattttggccgcc
gcatggaaaccccaaattttggccaccgagtggaaaccccaaattttgggcgccgcatgt
aaaccccaaattttgggcgccaggtggaagccccaagttttgggcgctaggaggaaagct
caaattttcggccgcatggaaaccccaaattttgggcgccgggtggaaacccaaaatttt
gggcgccacatggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcac
cgcgtgcaaaccccaaattttgggcgctggctggaaaccccaaattttgggcgccacatg
gaaaccccaaattttgggcgtcgcacggaaaccctaaatttcgggcgccgcatggaaacc
ccaaatttgggcgcggcatggaaaccccaaatgttgggcgcggcatggaaaccccaaatg
ttgggcgcctaggggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggc
accgcatggaaaccccaaattttgggtgcagggtggaaaccccaaattttgggcgcaggg
tggaaaccccaaattttgggcgctgggtggaaaccccaaattttgggcgccgggtggaaa
ccccaaatttgggcacagggtggaaaccccaaattttgggcgccggttggaaaccccaaa
ttttgggcgccgcatggaaaccccaaattttgggcaccgagtggaaaccccaaatt

论坛徽章:
16
程序设计版块每日发帖之星
日期:2016-05-03 06:20:0015-16赛季CBA联赛之八一
日期:2018-07-05 10:34:0915-16赛季CBA联赛之八一
日期:2018-07-03 16:56:4615-16赛季CBA联赛之深圳
日期:2018-06-15 14:59:3715-16赛季CBA联赛之青岛
日期:2018-06-08 13:45:2815-16赛季CBA联赛之同曦
日期:2018-06-04 19:42:2015-16赛季CBA联赛之山东
日期:2018-05-30 12:44:59CU十四周年纪念徽章
日期:2018-05-15 11:36:3815-16赛季CBA联赛之广东
日期:2018-05-14 09:52:4215-16赛季CBA联赛之深圳
日期:2018-05-04 21:53:0815-16赛季CBA联赛之辽宁
日期:2018-04-02 14:03:3915-16赛季CBA联赛之北京
日期:2018-03-23 15:24:07
发表于 2018-04-12 14:43 |显示全部楼层
如果你的需求变了,就把需求写清楚再帮你看

论坛徽章:
0
发表于 2018-04-12 15:08 |显示全部楼层
回复 7# wh7211
麻烦了大神。是这样的我在想截取如下序列上下游各100bp,并计算长度时发现长度不对。
之前的序列截取时并无问题。就很疑惑
>C30462902_9_1183
aaccccaaattttgggcgccgcatggaaaccccaaattttgtgcgccgggtggaaacccc
aaattttgggtgccgggtggaaaccccaaattttgggcgccatggcgctgcatggaaacc
ccaaattctgggtgctctgtggaaaccccaaattttggctgcggcatgcaaaccccaaat
tttgggcgccgagtggaaaccccaaatttggccgtggcatggaatccccaaattttgggc
accggggggaaaccccaaattttgagcgccgcatggaaaccccaaattttgggcgctgga
tggaaaccccaaattttacgcgccgggtggaaaccccaagttttgggcgcagcatggaaa
cccgaaatcttgggcgccgggtggaaaccccaaattttgggcgctctgtggaaacccaaa
attttggccgccacatggaaaccccaaattttcggcgccgagtggaagcctaaattttgg
gcgccgcatggaaaccccaaattttgggcgccggttggaaagcccaaattttgggcgcta
ggtggaaaccctaaatttttggccccgcatggaaaccccaaattttcggcgccgagtcga
aaccccaaatcttgggcgccatgtcgaaaccccaaatttttggcgctgggtggaaacccc
aaattttgggcgccgcatagaaaccccaaattttgggcgccgcatggaaacaccaaattt
tgggcgttgagtggaaaccccaaattttgggcggaaaccccgaattttgtgcggaaaccc
caaattttgggtggaaaccccgaatttgggcgcggcatggaaaacccaaattttgggtgc
cgggtggaaaccccaaatttagggcgctgaggcgccgcatggaaaccccaaattttgggc
gctgggggaaaccccaaattttgggtgccgcatggaaaccccaaattttgggcgttgagt
ggaaaccccaaattttgggcaccgggtggaaacccaaaattttgggcgctgggtggaaac
cccaaattttggccaccgcatagaaaccccaaattttggacaccaagtggaaagcccaaa
ttttgggcgccgcatggaaaccccaaattttgggcgctaggtgcaaaccccaaattttgg
gcgccgcatggaaaccccaaattttgggcgctagg
>C30487642_123_1263
cccaaattttgggcgctgggtgaaaaccccaaattttgtgcgccgcatggaaaccccaaa
ttttgggcgctcggtggaaaccccaaattttgggcgccgggtgtaaaccccaaatttggc
cgcagcatggaaacaccaaattttgggcaccggacggaaaccccaaattttgagcgccgc
atggaaaccccaaattgtgggcaccgggtggaaacctcaaattttgggcgccgggtggaa
accccaaattttgggcgccgggtggaaaccccaaattttgggcgccggggcgccgaatgg
aaacaccaaattttgggcgccaggtggaaaccccaaatttttggcgctaggtgaaagccc
caaattttgggtgccgcatggaaaccccaaattttgggcgccgagtggaaaccccaaatt
ttgggtgctgggtggaagccccaaattttgggcgctgggtggaagccccaaattttgggc
atcgagtgaaaaccccaaagtttgggcgccgcatggaaaccccaaattttgggcaccggg
ttaaaaccccaaattttgggagccgcatggaaaccccaaattttgggcgccgcatgcaaa
ccccaatttttggtcgttggatggaaacgccaaatttgggcgcggcatggaaaccccaaa
ttttgggcgtcgggtggaaaccccaaattttggggccgggtggaaaccccaaattttggg
cgccggctggaaaccccaaattttggcgcgggctggaaaccccaaatttgggcgtggggt
ggaaaccccaaattttgggagccgggtggaaaccccaaattttgggcgctaggtggaaac
cccaaattttgggtgccaggtggaaattgcaaattttgagcaccggatggaaacccccaa
ttttgggtgccgcgtggaaaccccaaattttgggcgccttatggaaatcccaaattttgg
gcggcgggtggaaaccccaaattttcagcgccgtggcgccgcatggaaaccccaaatttt
gggcgctcggcggaaaccccaaattttggccgccgcatggaaaccccaaattttgggcgc
cgagtggaaaccccaaattttgagcaccgcatggaaaccccaaatttcgggcgccgggtg
g
>C30492480_19_1274
gcgccgcatggaaaccccaaattttggtcgccgagtggaaaccccaaatttgggcgcggc
tggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcgccggctagaaa
ccccaaatttttggcgccagctggaaaccccaaatttgggcgcggggtggaaaccccaaa
cttggggcgcctggtggaaaccccaaattttgggtgccgggtggaaaccccaaaatttga
gcgctgcatggaaaccccaaattttgggcgtcagatggaaaccccaaattttggggccga
gtggaaaccccaatttttgggcgcagggtggaaaccccaaatttgggcgccaggtggaaa
ccccaaattttgggcgccgagtggaaaccccaaattttaggcgccaggtggaaacccgaa
attttgggtgccaagtggaaaccccaaattttgtgtgccgagtggaaaccccaagttttg
ggcgccgcatggaaaccccaaattttgggcgctcggtgggaaccccaaattttggccgcc
gcatggaaaccccaaattttggccaccgagtggaaaccccaaattttgggcgccgcatgt
aaaccccaaattttgggcgccaggtggaagccccaagttttgggcgctaggaggaaagct
caaattttcggccgcatggaaaccccaaattttgggcgccgggtggaaacccaaaatttt
gggcgccacatggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcac
cgcgtgcaaaccccaaattttgggcgctggctggaaaccccaaattttgggcgccacatg
gaaaccccaaattttgggcgtcgcacggaaaccctaaatttcgggcgccgcatggaaacc
ccaaatttgggcgcggcatggaaaccccaaatgttgggcgcggcatggaaaccccaaatg
ttgggcgcctaggggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggc
accgcatggaaaccccaaattttgggtgcagggtggaaaccccaaattttgggcgcaggg
tggaaaccccaaattttgggcgctgggtggaaaccccaaattttgggcgccgggtggaaa
ccccaaatttgggcacagggtggaaaccccaaattttgggcgccggttggaaaccccaaa
ttttgggcgccgcatggaaaccccaaattttgggcaccgagtggaaaccccaaatt

论坛徽章:
16
程序设计版块每日发帖之星
日期:2016-05-03 06:20:0015-16赛季CBA联赛之八一
日期:2018-07-05 10:34:0915-16赛季CBA联赛之八一
日期:2018-07-03 16:56:4615-16赛季CBA联赛之深圳
日期:2018-06-15 14:59:3715-16赛季CBA联赛之青岛
日期:2018-06-08 13:45:2815-16赛季CBA联赛之同曦
日期:2018-06-04 19:42:2015-16赛季CBA联赛之山东
日期:2018-05-30 12:44:59CU十四周年纪念徽章
日期:2018-05-15 11:36:3815-16赛季CBA联赛之广东
日期:2018-05-14 09:52:4215-16赛季CBA联赛之深圳
日期:2018-05-04 21:53:0815-16赛季CBA联赛之辽宁
日期:2018-04-02 14:03:3915-16赛季CBA联赛之北京
日期:2018-03-23 15:24:07
发表于 2018-04-12 16:16 |显示全部楼层
本帖最后由 wh7211 于 2018-04-12 16:18 编辑

回复 8# 小小脑


麻烦了大神。是这样的我在想截取如下序列上下游各100bp,并计算长度时发现长度不对。
之前的序列截取时并无问题。就很疑惑

你提供的源fasta序列不是一行,都断行了,我帮你连起来了。通过下面的计算,新的fasta序列满足你的需求

  1. cat 1
  2. >C30462902_9_1183
  3. aaccccaaattttgggcgccgcatggaaaccccaaattttgtgcgccgggtggaaaccccaaattttgggtgccgggtggaaaccccaaattttgggcgccatggcgctgcatggaaaccccaaattctgggtgctctgtggaaaccccaaattttggctgcggcatgcaaaccccaaattttgggcgccgagtggaaaccccaaatttggccgtggcatggaatccccaaattttgggcaccggggggaaaccccaaattttgagcgccgcatggaaaccccaaattttgggcgctggatggaaaccccaaattttacgcgccgggtggaaaccccaagttttgggcgcagcatggaaacccgaaatcttgggcgccgggtggaaaccccaaattttgggcgctctgtggaaacccaaaattttggccgccacatggaaaccccaaattttcggcgccgagtggaagcctaaattttgggcgccgcatggaaaccccaaattttgggcgccggttggaaagcccaaattttgggcgctaggtggaaaccctaaatttttggccccgcatggaaaccccaaattttcggcgccgagtcgaaaccccaaatcttgggcgccatgtcgaaaccccaaatttttggcgctgggtggaaaccccaaattttgggcgccgcatagaaaccccaaattttgggcgccgcatggaaacaccaaattttgggcgttgagtggaaaccccaaattttgggcggaaaccccgaattttgtgcggaaaccccaaattttgggtggaaaccccgaatttgggcgcggcatggaaaacccaaattttgggtgccgggtggaaaccccaaatttagggcgctgaggcgccgcatggaaaccccaaattttgggcgctgggggaaaccccaaattttgggtgccgcatggaaaccccaaattttgggcgttgagtggaaaccccaaattttgggcaccgggtggaaacccaaaattttgggcgctgggtggaaaccccaaattttggccaccgcatagaaaccccaaattttggacaccaagtggaaagcccaaattttgggcgccgcatggaaaccccaaattttgggcgctaggtgcaaaccccaaattttgggcgccgcatggaaaccccaaattttgggcgctagg
  4. >C30487642_123_1263
  5. cccaaattttgggcgctgggtgaaaaccccaaattttgtgcgccgcatggaaaccccaaattttgggcgctcggtggaaaccccaaattttgggcgccgggtgtaaaccccaaatttggccgcagcatggaaacaccaaattttgggcaccggacggaaaccccaaattttgagcgccgcatggaaaccccaaattgtgggcaccgggtggaaacctcaaattttgggcgccgggtggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcgccggggcgccgaatggaaacaccaaattttgggcgccaggtggaaaccccaaatttttggcgctaggtgaaagccccaaattttgggtgccgcatggaaaccccaaattttgggcgccgagtggaaaccccaaattttgggtgctgggtggaagccccaaattttgggcgctgggtggaagccccaaattttgggcatcgagtgaaaaccccaaagtttgggcgccgcatggaaaccccaaattttgggcaccgggttaaaaccccaaattttgggagccgcatggaaaccccaaattttgggcgccgcatgcaaaccccaatttttggtcgttggatggaaacgccaaatttgggcgcggcatggaaaccccaaattttgggcgtcgggtggaaaccccaaattttggggccgggtggaaaccccaaattttgggcgccggctggaaaccccaaattttggcgcgggctggaaaccccaaatttgggcgtggggtggaaaccccaaattttgggagccgggtggaaaccccaaattttgggcgctaggtggaaaccccaaattttgggtgccaggtggaaattgcaaattttgagcaccggatggaaacccccaattttgggtgccgcgtggaaaccccaaattttgggcgccttatggaaatcccaaattttgggcggcgggtggaaaccccaaattttcagcgccgtggcgccgcatggaaaccccaaattttgggcgctcggcggaaaccccaaattttggccgccgcatggaaaccccaaattttgggcgccgagtggaaaccccaaattttgagcaccgcatggaaaccccaaatttcgggcgccgggtgg
  6. >C30492480_19_1274
  7. gcgccgcatggaaaccccaaattttggtcgccgagtggaaaccccaaatttgggcgcggctggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcgccggctagaaaccccaaatttttggcgccagctggaaaccccaaatttgggcgcggggtggaaaccccaaacttggggcgcctggtggaaaccccaaattttgggtgccgggtggaaaccccaaaatttgagcgctgcatggaaaccccaaattttgggcgtcagatggaaaccccaaattttggggccgagtggaaaccccaatttttgggcgcagggtggaaaccccaaatttgggcgccaggtggaaaccccaaattttgggcgccgagtggaaaccccaaattttaggcgccaggtggaaacccgaaattttgggtgccaagtggaaaccccaaattttgtgtgccgagtggaaaccccaagttttgggcgccgcatggaaaccccaaattttgggcgctcggtgggaaccccaaattttggccgccgcatggaaaccccaaattttggccaccgagtggaaaccccaaattttgggcgccgcatgtaaaccccaaattttgggcgccaggtggaagccccaagttttgggcgctaggaggaaagctcaaattttcggccgcatggaaaccccaaattttgggcgccgggtggaaacccaaaattttgggcgccacatggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcaccgcgtgcaaaccccaaattttgggcgctggctggaaaccccaaattttgggcgccacatggaaaccccaaattttgggcgtcgcacggaaaccctaaatttcgggcgccgcatggaaaccccaaatttgggcgcggcatggaaaccccaaatgttgggcgcggcatggaaaccccaaatgttgggcgcctaggggaaaccccaaattttgggcgccgggtggaaaccccaaattttgggcaccgcatggaaaccccaaattttgggtgcagggtggaaaccccaaattttgggcgcagggtggaaaccccaaattttgggcgctgggtggaaaccccaaattttgggcgccgggtggaaaccccaaatttgggcacagggtggaaaccccaaattttgggcgccggttggaaaccccaaattttgggcgccgcatggaaaccccaaattttgggcaccgagtggaaaccccaaatt

  8. 打印新的fasta序列
  9. awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$0:$0}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c[i]);printf("%s\n%s\n%s\n",b[i],substr(c[i],1,100),substr(c[i],d-99))}}' 1                     
  10. >C30462902_9_1183
  11. aaccccaaattttgggcgccgcatggaaaccccaaattttgtgcgccgggtggaaaccccaaattttgggtgccgggtggaaaccccaaattttgggcgc
  12. ccaaattttgggcgccgcatggaaaccccaaattttgggcgctaggtgcaaaccccaaattttgggcgccgcatggaaaccccaaattttgggcgctagg
  13. >C30487642_123_1263
  14. cccaaattttgggcgctgggtgaaaaccccaaattttgtgcgccgcatggaaaccccaaattttgggcgctcggtggaaaccccaaattttgggcgccgg
  15. aattttggccgccgcatggaaaccccaaattttgggcgccgagtggaaaccccaaattttgagcaccgcatggaaaccccaaatttcgggcgccgggtgg
  16. >C30492480_19_1274
  17. gcgccgcatggaaaccccaaattttggtcgccgagtggaaaccccaaatttgggcgcggctggaaaccccaaattttgggcgccgggtggaaaccccaaa
  18. agggtggaaaccccaaattttgggcgccggttggaaaccccaaattttgggcgccgcatggaaaccccaaattttgggcaccgagtggaaaccccaaatt

  19. 计算长度
  20. awk '/^>/{a=NR;b[a]=$0;next}{c[a]=c[a]?c[a]"\n"$0:$0}END{PROCINFO["sorted_in"]="@ind_num_asc";for(i in c){d=length(c[i]);printf("%s\n%s\n%s\n",b[i],substr(c[i],1,100),substr(c[i],d-99))}}' 1|awk -F "" '{print NF}'
  21. 17
  22. 100
  23. 100
  24. 19
  25. 100
  26. 100
  27. 18
  28. 100
  29. 100
复制代码

论坛徽章:
0
发表于 2018-04-12 20:08 |显示全部楼层
回复 9# wh7211

嗯嗯,我明白了。谢谢大神
您需要登录后才可以回帖 登录 | 注册

本版积分规则

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号 北京市公安局海淀分局网监中心备案编号:11010802020122
广播电视节目制作经营许可证(京) 字第1234号 中国互联网协会会员  联系我们:wangnan@it168.com
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP