フィルターのクリア

Add Letters in a sequence

1 回表示 (過去 30 日間)
A C
A C 2022 年 11 月 15 日
コメント済み: David Hill 2022 年 11 月 15 日
I want to add Letters in a sequence
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c - - - ghi - - - - n o p q - - - - - - x y -
I got it to work with one gap but the sequence can have more than one gap.
I know the location n = [4 5 6 10 11 12 13 18 19 20 21 22 23 26] and the letters gap = [d e f j k l m r s t u v w z]
I do not know how to make it run for more in gap.
clc;clear;
% sequence we want to add because the sequence have gaps
% We have the amino acids however the position is unknow
% So the Letters are not include
% This a problem when there is over 300 amino acids
sequence = 'ABCGHIJ';
n = [4,5,6];
gap = 'DEF';
% loop
store = [];
% We want the gaps to be filled
for K = 1
% removing the letters where the gap needs
% to go
store = [sequence(n(K)):sequence(end)]
num = [n(end)+1:n(end)+1+numel(gap)]
for L = 1:numel(n)
% filling the gap
sequence(n(L)) = gap(L)
end
for M = 1:numel(num)
% Replacing the reoved letters
sequence(num(M)) = store(M)
end
end
sequence

採用された回答

David Hill
David Hill 2022 年 11 月 15 日
編集済み: David Hill 2022 年 11 月 15 日
l='abcdefghijklmnopqrstuvwxyz';
gap='defjklmrstuvwz'-96;
l(gap)='-'
l = 'abc---ghi----nopq------xy-'
  2 件のコメント
A C
A C 2022 年 11 月 15 日
That is neat. I did not explain it right.
We start with
l = 'abcghinopqxy'
We want to filled it with
gap = 'defjklmrstuvwz'
We know the locations
n = [4 5 6 10 11 12 13 18 19 20 21 22 23 26]
Results is
l = 'abcdefghijklmnopqrstuvwxyz'
David Hill
David Hill 2022 年 11 月 15 日
l = 'abcghinopqxy';
gap = 'defjklmrstuvwz';
n = [4 5 6 10 11 12 13 18 19 20 21 22 23 26];
L=length(l)+length(gap);
r=zeros(1,L);
r(n)=gap;
r(~ismember(1:L,n))=l;
r=char(r)
r = 'abcdefghijklmnopqrstuvwxyz'

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by