Posts

Showing posts with the label Fasta_utils

Condense fasta header

''' Biopython hack to condense fasta header. When there is a lengthy header in fasta file like the following: >geneid1213 len = 234 covStat = val otherparam = sval, Shorten it to make it >geneid1213. ''' from Bio import SeqIO new_header = [] with open ( "test.fasta" , "rU" ) as infile: for record in SeqIO . parse(infile, "fasta" ): record . description = record . name record . id = record . name new_header . append(record) SeqIO . write(new_header, "short_header.fasta" , "fasta" ) print ( "program complete" )

Calculate Cys-Richness for a protein

''' Code description: Calculate Cys-richness of a protein with criteria set as: >=4 'C's over the length of protein AND >=5% total cysteine content Function: Take input sequence => Count number of 'C's & length => Calculate percentage Output True or False if criteria is met ''' from Bio import SeqIO def Cys_rich (record_seq): C_count = record_seq . count( 'C' ) seq_len = len (record_seq) Cys_perc = float (C_count) / float (seq_len) * 100 if C_count >= 4.0 and Cys_perc >= 5.0 : return 'Cys-rich' else : return 'No' CysRichSeq = [] for record in SeqIO . parse( 'filename.fasta' , 'fasta' ): if Cys_rich(record . seq) == 'Cys-rich' : CysRichSeq . append(record) SeqIO . write(CysRichSeq, 'Cys-rich_sequences.fasta' , 'fasta' ) print 'Cys-rich sequences written to file..'

Fasta_Header_Rename

A simple matlab code to rename the headers in fasta file. Self-explanatory variable names. 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 %Author = Arun Prasanna %Rename the headers in fasta file to desired choice %For example: The input fasta file used here had header in >num_name format %strtok is used to strip and extract the required format clear; clc; tic; Path = 'Drive\Path\ToReadFile' ; % FileList = dir(Path); [rFL, cFL] = size(FileList); for i = 3:rFL %i of 1 & 2 are . & .. respectively     Fas_Fname{i-2,1} = FileList(i).name; %FileList is a structure end [rFas,cFas] = size(Fas_Fname); for i = 1:rFas     clear Header Seq ProtID Sp new_Header     OpenFile = cell2mat(strcat(Path,Fas_Fname(i)));     [Header, Seq] = fastaread(OpenFile);[rH,cH] = size(Header);     for j = 1:cH    ...

Fasta_Dupicate_Header

A simple, self-explanatory matlab code to identify duplicate headers in fasta files. 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 %Simple matlab code to check for the duplicate header in fasta files %Store the size of header -> unique(header) ->size of new header %Copy the Table data in excel and compare the two values clear; clc; tic; Path = 'Drive\Path\FileName' ; % FileList = dir(Path); [rFL, cFL] = size(FileList); for i = 3:rFL %i of 1 & 2 are . & .. respectively     Fas_Fname{i-2,1} = FileList(i).name; %FileList is a structure end [rFas,cFas] = size(Fas_Fname); for i = 1:rFas     clear Header Seq Old_Header Unik_header     OpenFile = cell2mat(strcat(Path,Fas_Fname(i)));     [Header, Seq] = fastaread(OpenFile);[rH,cH] = size(Header);     Old_Header = length(Header);     Unik_header = length(...

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      ...

Fasta Header Replacer

Handling sequence files (like .fasta) is one of the trickiest problems for novice in Bioinformatics. Bio-Perl, Bio-python are quite useful but looks really scary :-( !. MATLAB offers a cool solution with its in-built Bioinformatics toolbox !!. Reading a fasta file with 'fastaread' is as easy as 'xlsread' ...followingly the same with 'fastawrite'/'xlswrite' :-) fastaread simply extract the sequence headers & sequences in cell arrays !. Voila !!! Once it does...then one can do all kinds of manipulation they want. Here is a simple-self-explanatory, one-file-at-a-time code to replace the header with an user-defined headers. Besides, creates a translation table. If you want to process multiple file then one can readily loop it over directory operations. INPUT (sequence.fasta) >gi|154163|gb|M83220.1|STYLEXA Salmonella typhimurium lexA (repressor of DNA damage inducible genes) gene, 5' end ATGCGCCAGCTGCAAAATTTAAAT >gi|154164|gb|M8322...