Skip to content

Commit 1856116

Browse files
author
Rebecca Halperin
committed
get chr names from bam header
Former-commit-id: d58269a6503e0da83f7a19b0943dfe36b8c4cb16
1 parent 95d95aa commit 1856116

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/chr2idx.m

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function chrTable=chr2idx(inputParam)
2+
%preprocessTumorOnly - creates data structures for tumor only calling
3+
%calls parsePileupData.packed.pl to parse samtools output
4+
%
5+
% Syntax: [T, E]=preprocessTumorOnly(inputParam,paramFile)
6+
%
7+
% Inputs:
8+
% inputParam - data structure with the following fields: regionsFile,
9+
% numCPU, outname, blockSize, snpVCFpath, snpVCFname,
10+
% workingDirectory, tabixPath, NormalBase
11+
%
12+
% Outputs:
13+
% T - table of data by position
14+
% E - table of data by exon
15+
%
16+
% Other m-files required: none
17+
% Other requirements: parsePileupData.packed.pl, samtools, htslib
18+
% Subfunctions: none
19+
% MAT-files required: none
20+
%
21+
% See also: TumorOnlyWrapper
22+
23+
% Author: Rebecca F. Halperin, PhD
24+
% Translational Genomics Research Institute
25+
26+
% Website: https://github.com/tgen
27+
% Last revision: 3-June-2016
28+
29+
%------------- BEGIN CODE --------------
30+
31+
%[status,out]=system('printenv')
32+
%profile('-memory','on');
33+
%profile on;
34+
35+
sexChr=regexprep(inputParam.sexChr,'''','')
36+
sexChr=regexp(sexChr,',','split')
37+
if max(cellfun('length',sexChr))==0
38+
chrList=cellstr(num2str(inputParam.autosomes','%-d'))
39+
else
40+
chrList=[cellstr(num2str(inputParam.autosomes','%-d')); sexChr'];
41+
end
42+
43+
[~,out]=system(['samtools view -H `head -n1 ' inputParam.bamList ' ` | grep ^@SQ']);
44+
45+
contigs=strtok(extractAfter(strsplit(out,'\n'),'SN:'));
46+
47+
[lia,locb]=ismember(chrList,contigs);
48+
49+
chrTable=table();
50+
chrTable.chrName=chrList(lia);
51+
chrTable.chrIdx=locb(lia);
52+
53+
if sum(~lia)>0
54+
message=['warning chr ' strjoin(chrList(~lia),',') ' not found in bam']
55+
end

src/writeSomTable.m

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function writeSomTable(Tcell,somPos,cloneId,sampleFrac,somaticDetected,outName)
2+
3+
somTable=Tcell{1}(somPos,{'Chr','Pos'});
4+
somTable.Ref=int2ntIndels(Tcell{1}.RefComb(somPos));
5+
somTable.A_allele=int2ntIndels(Tcell{1}.Acomb(somPos));
6+
somTable.B_allele=int2ntIndels(Tcell{1}.Bcomb(somPos));
7+
somTable.cloneGroup=cloneId(somPos,1);
8+
somTable.detectStr=num2str(somaticDetected(somPos,:),'%-d');
9+
somTable.sampleFrac=sampleFrac(somPos,:);
10+
for i=1:length(Tcell)
11+
somTable.Depth(:,i)=Tcell{i}.ReadDepthPass(somPos);
12+
somTable.Bcounts(:,i)=Tcell{i}.BcountsComb(somPos);
13+
end
14+
somTable.N=Tcell{1}.NumCopies(somPos);
15+
somTable.M=Tcell{1}.MinAlCopies(somPos);
16+
17+
18+
writetable(somTable,[outName '.somaticPass.txt'],'Delimiter','\t','FileType','text','WriteVariableNames',1);

0 commit comments

Comments
 (0)