fastawrite error with string array as input datatype

1 回表示 (過去 30 日間)
Akshay Chenna
Akshay Chenna 2020 年 6 月 20 日
コメント済み: Akshay Chenna 2020 年 6 月 22 日
Dear MATLAB community,
I would like to create a fasta file from a cell array of character vectors. I have used the fastawrite function in Bioinformatics toolbox but I encounter the following error:
a=top50.dat.aa{2,1};
% 'a' is 50 X 1 cell array of character vectors
fastawrite('test.fasta',a)
Error using fastawrite (line 123)
Data is not a valid sequence or structure.
I have also tried to convert 'a' to a string but the error is still the same:
fastawrite('test.fasta',string(a))
Error using fastawrite (line 123)
Data is not a valid sequence or structure.
I have solved this issue by using a loop (since fasta write appends an existing file instead of overwriting it) but I would like to know if a more direct solution exists.
for i=1:50
fastawrite('test.fasta', string(a(i,1)))
end
Considering that since MATLAB 2018 all functions which take character array as an input work with string arrays, I would like to know if there is an issue with my code or with fastawrite.
Thank you,
Akshay
IIT D
  2 件のコメント
madhan ravi
madhan ravi 2020 年 6 月 20 日
Akshay Chenna
Akshay Chenna 2020 年 6 月 20 日
Thank you @madhan for the quick reply, I was refering to this page https://www.mathworks.com/help/matlab/matlab_prog/update-your-code-to-accept-strings.html
which states that any function that can accept character vector as input also accepts strings. So shouldnt this string array:
fastawrite('test.fasta',string(a))
work inplace of character array?

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

採用された回答

Arthur Goldsipe
Arthur Goldsipe 2020 年 6 月 20 日
You generally should be able to cell arrays of character vectors and string vectors interchangeably, and a character vector interchangeably with a single string. Both of these are two ways of encoding text. But if a function only excepts one piece of text, then you should expect to see the same error if you specify more than one piece of text. That is the case in the error you get when calling fastawrite with a cell of character vector or with a vector of strings.
In other words, (and as described in the documentation that madhan ravi points to), fastawrite only accepts a single piece of text as the data. This piece of text can be specified as a character vector or as a single string. If you want to write several pieces of text into a single FASTA file, then you first need to join them into a single piece of text. For example, you could try the following:
a=top50.dat.aa{2,1};
% 'a' is 50 X 1 cell array of character vectors
fastawrite('test.fasta',join(a, ''))
  1 件のコメント
Akshay Chenna
Akshay Chenna 2020 年 6 月 22 日
Thank you for making it clear. This worked for me:
a=top50.dat.aa{2,1};
% 'a' is 50 X 1 cell array of character vectors
fastawrite('test.fasta',join(string(a), ''))

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by