Fasta Header Replacer V2.0

Extension of previous code 'Fasta Header Replacer.m' to process files in batch mode. Keep all/only the .fasta files inside the specified directory.

%Author: Arun Prasanna
%Version 2.0 of Fasta_Header_replacer.m!.
%Efficient to process files in batch mode. 

clear; clc;
FileList = dir('D:\BRC_POSTDOC-RESEARCH\ARMILLARIA_Project\PROTEIN_FASTA');
[rFL, cFL] = size(FileList);
for i = 3:rFL %i of 1 & 2 are . & .. respectively
    Org_name{i-2,1} = FileList(i).name; %FileList is a structure
end

[rOn, cOn] = size(Org_name);
for OL = 1:rOn
    FileName = char(Org_name{OL});
    [Header, Seq] = fastaread(FileName);
    Header = Header';
    Seq= Seq';
    [rH,cH] = size(Header);
    check(OL,1) = rH;
    for IL = 1:rH
        id = num2str(IL);
        [tok,rem] = strtok(FileName,'.'); %Extract org name from FileName itself.
        new{IL,1} = strcat(id,'_',tok); 
    end
    OutFileName = strcat(tok,'_mod',rem);
    fastawrite(OutFileName,new,Seq)
    TransTab = horzcat(new, Header);
    %===========Section-to-write-cell-array-2-Txt-file===========%
    TT = strcat(tok,'_Transtab.txt')
    fileID = fopen(TT,'w');
    [nrows,ncols] = size(TransTab);
    for row = 1:nrows
        fprintf(fileID,'%s\t%s\n',TransTab{row,:});
    end
    fclose(fileID);
    clear Header Seq new tok fileID %Important to prevent carry-over
end

Comments

Popular posts from this blog

Map multiple annotations using pandas

Condense fasta header