【问题标题】:From the concatenated fasta file, how to find individual range of locations in each protein sequence从连接的 fasta 文件中,如何找到每个蛋白质序列中的各个位置范围
【发布时间】:2016-08-18 19:40:40
【问题描述】:

可能是这个问题太笼统了,但我完全被困在这个问题上。感谢任何类型的帮助:

我有一个蛋白质 fasta 文件 (protein.txt),例如:

>a
mnspq
>b
rstuvw
>c
mnqa

注意a、b、c蛋白的长度分别为5,6和4(总长度=15)

现在我已经提取了一些随机范围(计算基于总长度)并将其保存(file1.txt)为:

2-3
4-10
11-14

蛋白质文件中看到的每个蛋白质的长度(在总长度内)保存在另一个文件(file2.txt)中为:

a  1-5
b  6-11
c  12-15

现在从 file1 的值,我想修改 file2 的值并尝试计算每个蛋白质序列的单独范围,对于上述输入,输出将是:

a   2-3,4-5
b   1-5, 6
c   2-5

换句话说,如果我首先连接所有序列并从连接文件中确定一些范围,我如何在每个蛋白质序列中找到单独的位置范围

谢谢

【问题讨论】:

  • 不应该是c 1-3吗?
  • upps.. 是我的错.. 先生,您说的完全正确..

标签: bioinformatics fasta


【解决方案1】:

我猜答案的最后一行应该是c 1-3

|---a---| |---b-----| |--c--|
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  |-| |-----------| |-----|
1 2 3 4 5 1 2 3 4 5 6 1 2 3 4

Perl 来救援!首先,将 file1 中的范围读入一个数组。然后,从 file2 中读取蛋白质,对于与该范围重叠的每个范围,计算并打印“开始”和“结束”。

#!/usr/bin/perl
use warnings;
use strict;

my @ranges;
open my $f1, '<', 'file1.txt' or die $!;
while (<$f1>) {
    chomp;
    push @ranges, [ split /-/ ];
}

open my $f2, '<', 'file2.txt' or die $!;
while (<$f2>) {
    my ($protein, $range) = split;
    print "$protein";
    my $separator = ' ';
    my ($from, $to) = split /-/, $range;

    shift @ranges while @ranges && $ranges[0][1] < $from;
    last unless @ranges;

    while (@ranges && $ranges[0][0] <= $to) {
        my $start = $ranges[0][0];
        $start = $from if $from > $start;
        my $end = $ranges[0][1];
        $end = $to if $end > $to;
        $_ -= $from - 1 for $start, $end;

        print $separator, $start == $end ? $start : "$start-$end";
        $separator = ',';

        if ($ranges[0][1] < $to) {
            shift @ranges;
        } else {
            $ranges[0][0] = $to + 1;
        }
    }
    print "\n";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多