set wrap!
function LC()
normal yiW
echo strlen(@") . " characters in word"
endfunction
function PC()
normal yiB
echo strlen(@") . " position in word"
endfunction
"sequence"
function! Count_bases()
let l:string_length = strlen(substitute(getline("."), ".*", "&", "g"))
let l:a = l:string_length - strlen(substitute(getline("."), "\\c[a]", "", "g"))
let l:c = l:string_length - strlen(substitute(getline("."), "\\c[c]", "", "g"))
let l:g = l:string_length - strlen(substitute(getline("."), "\\c[g]", "", "g"))
let l:t = l:string_length - strlen(substitute(getline("."), "\\c[t]", "", "g"))
let l:gap = l:string_length - strlen(substitute(getline("."), "\\c[-]", "", "g"))
let l:other = l:string_length - l:a - l:c - l:g - l:t - l:gap
echo "Length=" . l:string_length " (" "A=" . l:a "C=" . l:c "G=" . l:g "T=" . l:t "-=" . l:gap "other=" . l:other ")"
endfunction
function! AlignSection(regex) range
let extra = 1
let sep = empty(a:regex) ? '\s\+' : a:regex
let maxpos = 0
let section = getline(a:firstline, a:lastline)
for line in section
let pos = match(line, ' *'.sep)
if maxpos < pos
let maxpos = pos
endif
endfor
call map(section, 'AlignLine(v:val, sep, maxpos, extra)')
call setline(a:firstline, section)
endfunction
function! AlignLine(line, sep, maxpos, extra)
let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)')
if empty(m)
return a:line
endif
let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra)
return m[1] . spaces . m[2]
endfunction
command! -nargs=? -range Align <line1>,<line2>call AlignSection('<args>')
vnoremap <silent> <Leader>a :Align<CR>
fun! Rev(result)
let l:i = strlen(a:result) - 1
let l:result = ''
while (l:i > -1)
let l:result = l:result.a:result[l:i]
let l:i = l:i - 1
endwhile
return l:result
endfun
function! RC_Tim(l1, l2)
let l:str = getline(a:l1)
let l:len = strlen(l:str)
let l:ignorecs = &l:ic
let &l:ic = 0
exe a:l1.",".a:l2."j!"
exe a:l1."s/.*/\\=Rev(submatch(0))/"
exe a:l1."s/\\c[agct]/\\=\"ATGCatgc\"[match(\"TACGtacg\", submatch(0))]/ge"
exe a:l1."s/.\\{".&tw."\\}\\zs//g"
let &l:ic = l:ignorecs
endfunction
command! -n=* -range RC :call RC_Tim(<line1>,<line2>)
function! NexusComment()
if getline(".") =~ '['
let hls=@/
s/^\(\s*\)\[/\1/
s/\(\s*\)\]$/\1/
let @/=hls
else
let hls=@/
s/^/[/
s/$/]/
let @/=hls
endif
endfunction
function! GetNtax()
let ntax=0
g/^/let ntax+=strlen(substitute(getline('.'), '[^>]', '', 'g'))
return ntax
endfunction
function! GetNtax2()
exe ': normal G'
let ntax=0
g/^/let ntax+=strlen(substitute(getline('.'), '[^>]', '', 'g'))
echo "Number of sequences: " ntax
endfunction
function! DegapFasta()
exe ':g!/^>/s/-//g'
exe ':g/^\s*$/d'
exe ':normal gg'
endfunction
function! GetMaxLineLength()
let maxLength=0
let start=line("1")
let end=line("$")
while (start <= end)
let lineLength=strlen(substitute(getline(start), '\s', '', ''))
if (lineLength > maxLength)
let maxLength=lineLength
endif
let start = start + 1
endwhile
"max line length: "
return maxLength
endfunction
function! Fasta2Phyml()
let ntax=GetNtax()
exe ':normal gg'
exe ':s/>/\r>/'
exe ':%s/\(^>.\+\)$/\1<skojj/'
exe ':%s/\n//g'
exe ':%s/>/\r/g'
exe ':%s/<skojj/<skojj\r/'
let nchar=GetMaxLineLength()
exe ':%s/<skojj\n/\t/'
exe ':normal gg'
exe ':%Align'
exe ':normal gg'
exe "normal i" ntax nchar "\<Esc>"
Ntax:Nchar:
endfunction
command! -nargs=0 Fasta2NonInterLeavedFasta :normal gg | :s/>/\r>/<CR> | :%s/\(^>.\+\)$/\1<skojj/<CR> | :%s/\n//g<CR> | :%s/>/\r>/g<CR> | :%s/<skojj/\r/<CR> | :normal ggdd<CR>
command! -nargs=0 UnWrapFasta :normal gg | :Fasta2NonInterLeavedFasta<CR>
command! -nargs=0 Phyml2Fasta :normal ggdd | :%s/^/>/<CR> | :%s/\s\+/\r/<CR>
command! -nargs=0 Fasta2Phyml2 :normal gg | :s/>/\r>/<CR> | :%s/\(^>.\+\)$/\1<skojj/<CR> | :%s/\n//g<CR> | :%s/>/\r/g<CR> | :%s/<skojj/\t/<CR> | :normal gg<CR>
command! -nargs=0 WrapFasta :normal gg | :g!/^>/s/.\{70}/&\r/g<CR> | :normal gg<CR>
command! -nargs=0 Fas2Nex :%! fas2nex.stdout %<CR>
command! -nargs=0 Fasta2Tab :normal gg | :%s/^>\(.*\)/>\1\t/<CR> | :%s/\n//<CR> | :%s/>/\r/g<CR> | :g/^$/d<CR>
command! -nargs=0 Tab2Fasta :normal gg | :%s/^\(.*\)\t\(.*\)/>\1\r\2/<CR>
function! RandSeq(len)
let LENGTH = a:len
exe ':r!/home/nylander/bin/getrandomsequence.pl' . ' ' . LENGTH
endfunction
command! -nargs=1 Randseq : call RandSeq(<args>)
function! ReadMan(man_word)
exe ':tabnew'
exe ':r!man ' . a:man_word . ' | col -b'
exe ':goto'
exe ':delete'
exe ':set filetype=man'
endfunction
menu Phylo.Do\ Alignment.CLUSTALW.Protein :! clustalw -outorder=INPUT -output=GDE -case=UPPER -outfile=ClUsTaL.aln -align -infile=%<CR>: tabe ClUsTaL.aln<CR> :% s/%/>/<CR>: normal gg<CR>
menu Phylo.Do\ Alignment.CLUSTALW.DNA :! clustalw -outorder=INPUT -output=GDE -case=UPPER -outfile=ClUsTaL.aln -align -infile=%<CR>: tabe ClUsTaL.aln<CR> :% s/#/>/<CR>: normal gg<CR>
menu Phylo.Do\ Alignment.CLUSTALW.Read\ CLUSTALW\ man\ page : call ReadMan('clustalw')<CR>
menu Phylo.Do\ Alignment.MAFFT.mafft :! mafft % > MaFfT.mafft.ali<CR> : tabe MaFfT.mafft.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.linsi :! linsi % > MaFfT.linsi.ali<CR> : tabe MaFfT.linsi.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.ginsi :! ginsi % > MaFfT.ginsi.ali<CR> : tabe MaFfT.ginsi.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.einsi :! einsi % > MaFfT.einsi.ali<CR> : tabe MaFfT.einsi.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.fftnsi :! fftnsi % > MaFfT.fftnsi.ali<CR>: tabe MaFfT.fftnsi.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.fftns :! fftns % > MaFfT.fftns.ali<CR> : tabe MaFfT.fftns.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.nwns :! nwns % > MaFfT.nwns.ali<CR> : tabe MaFfT.nwns.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.nwnsi :! nwnsi % > MaFfT.nwnsi.ali<CR> : tabe MaFfT.nwnsi.ali<CR><CR>
menu Phylo.Do\ Alignment.MAFFT.-Sep- :
menu Phylo.Do\ Alignment.MAFFT.Read\ MAFFT\ man\ page : call ReadMan('mafft')<CR>
menu Phylo.Utilities.Remove\ all\ gaps\ in\ FASTA : call DegapFasta()<CR>
menu Phylo.Utilities.Align\ taxlabels\ (in\ phyml\ format) : Align<CR>
menu Phylo.Utilities.Count\ sequences\ (in\ FASTA\ format) : echo ''<CR>: call GetNtax2()<CR>
menu Phylo.Utilities.Set\ filetype\ to\ DNA : set ft=align<CR>
menu Phylo.Utilities.Set\ filetype\ to\ AA : set ft=aalign<CR>
menu Phylo.Utilities.Set\ filetype\ to\ Nexus : set ft=nexus<CR>
menu Phylo.Convert.Phyml\ to\ FASTA : Phyml2Fasta<CR>
menu Phylo.Convert.FASTA\ to\ Phyml : call Fasta2Phyml()<CR><CR>
menu Phylo.Convert.FASTA\ to\ Nexus : Fas2Nex<CR> : set ft=nexus<CR>
menu Phylo.Convert.FASTA\ to\ Tab : Fasta2Tab<CR>
menu Phylo.Convert.Tab\ to\ FASTA : Tab2Fasta<CR>
menu Phylo.Convert.Unwrap\ FASTA : Fasta2NonInterLeavedFasta<CR>
menu Phylo.Convert.Wrap\ FASTA : WrapFasta<CR>
menu Phylo.DNA.RevComp : RC<CR>
menu Phylo.DNA.Insert\ Random\ DNA\ Seq : Randseq
TODO:
menu Phylo.Run.Fasttree\ (DNA) : ! fasttree -nt % > FaSt.tre<CR><CR>: tabe FaSt.tre<CR>
menu Phylo.Run.Fasttree\ (AA) : ! fasttree % > FaSt.tre<CR><CR>: tabe FaSt.tre<CR>
menu Phylo.Run.PAUP : ! paup %<CR>
menu Phylo.Run.MrBayes : ! mb312 -i %<CR>
menu Phylo.Run.MrAIC\ (24\ nt\ models) : ! mraic.pl %<CR><CR>: tabe *.MrAIC.txt<CR>
menu Phylo.Run.MrAIC\ (56\ nt\ models) : ! mraic.pl -modeltest %<CR><CR>: tabe *.MrAIC.txt<CR>
menu Phylo.Run.pMrAIC\ (24\ nt\ models) : ! pmraic.pl --noverbose %<CR><CR>: tabe *.pMrAIC.txt<CR>
menu Phylo.Run.pMrAIC\ (56\ nt\ models) : ! pmraic.pl --noverbose --modeltest %<CR><CR>: tabe *.pMrAIC.txt<CR>