-
Notifications
You must be signed in to change notification settings - Fork 0
/
otherR1_proccessing.m
63 lines (55 loc) · 2.45 KB
/
otherR1_proccessing.m
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
workDir = '/illumina1/YanaiLab/eitan/UTRome/wholeEmb/';
genesFiles = dir(strcat(workDir,'depth_oriented/*.txt'));
genesFiles = {genesFiles.name};
sampleDirs = dir(strcat(workDir,'samples/*'));
samples = {sampleDirs.name}; samples = samples(3:end);
cellAppearenceThreshold = 2;
readThreshold = 20;
minDistanceBetweenPopulations = 20;
outFile = fopen('isoformUsage_whole_embryos_oriented.csv','w');
fprintf(outFile,'gene_name,peak_Location');
for n=1:length(samples)
fprintf(outFile,',%s',samples{n});
end
fprintf(outFile,'\n');
for geneIdx=1:size(genesFiles,2)
gene = regexprep(genesFiles{geneIdx},'.txt','');
%[gene]
file = strcat(workDir,'depth_oriented/',genesFiles{geneIdx});
listing = dir(file);
if (listing.bytes > 0)
A = dlmread(file,'\t');
if (sum(logical(sum(A)>readThreshold)) >= cellAppearenceThreshold) % at least 100 reads in 2 samples
%generating a histogram based on all samples (will be skewed to highly represented
smoothedCumulativeHistogram = tsmovavg(sum(A,2)','s', minDistanceBetweenPopulations);
heightThreshold = max(5, sum(sum(A,2)) * 2e-3);
[peakHeights,peakLocations] = findpeaks( smoothedCumulativeHistogram,'MINPEAKDISTANCE', minDistanceBetweenPopulations, ...
'MINPEAKHEIGHT',heightThreshold);
if (size(peakLocations,2) > 0)
peakLocations = peakLocations - minDistanceBetweenPopulations / 2; %centralizing the peaks
% for each peak
for peakIdx=1:size(peakLocations,2)
fprintf(outFile,'%s,%d',gene,peakLocations(peakIdx));
% for each sample
for i=1:size(A,2)
sampleHistogram = A(:,i);
readNum = sum ( sampleHistogram ( ...
peakLocations(peakIdx) - minDistanceBetweenPopulations / 2 : ...
peakLocations(peakIdx) + minDistanceBetweenPopulations / 2 ) );
fprintf(outFile,',%d',readNum);
end
fprintf(outFile,'\n');
end
% for all peaks
fprintf(outFile,'%s,total,',gene);
for i=1:size(A,2)
sampleHistogram = A(:,i);
readNum = sum(sampleHistogram);
fprintf(outFile,'%d,',readNum);
end
fprintf(outFile,'\n');
end
end
end
end
fclose('all');