forked from JimBell/miRWoods
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetMirDeepCounts.pl
68 lines (58 loc) · 2.93 KB
/
getMirDeepCounts.pl
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
63
64
65
66
67
68
#!/usr/bin/perl -w
use miRWoods;
use mwPaperCommonCode;
use strict;
my $usage = "USAGE:\n$0 <miRDeepResultsFile> <mirbase gff> <sample name> <output prefix> <get annotated Only ? 1 : 0>\n";
my $miRDeepResultsFile = $ARGV[0] or die $usage;
my $mirbaseGff = $ARGV[1] or die $usage;
my $sampleName = $ARGV[2] or die $usage;
my $outputPrefix = $ARGV[3] or die $usage;
my $annotOnly = $ARGV[4];
my $outputFile = ($annotOnly) ? "$outputPrefix\_annotProductSizes\_miRDeep\_counts.txt" : "$outputPrefix\_majorProductSizes\_miRDeep\_counts.txt";
my($newMiRDeepAnnotPredictions,$mirDeepProducts,$mdPredictions) = getMiRDeepAnnotations($miRDeepResultsFile,$mirbaseGff);
my $mpInfo = getMajorProductCounts($mdPredictions,$mirDeepProducts);
printResults($newMiRDeepAnnotPredictions,$mpInfo,$annotOnly,$outputFile);
sub printResults {
my($newMiRDeepAnnotPredictions,$mpInfo,$annotOnly,$outputFile) = @_;
open(OPTF,">$outputFile") or die "failed to open $outputFile for writing\n";
print OPTF "#tag\tannotationType\tproduct\t$sampleName\n";
foreach my $chrom (keys %{$newMiRDeepAnnotPredictions}) {
foreach my $hpInfo (@{$newMiRDeepAnnotPredictions->{$chrom}}) {
my($hpStart,$hpStop,$hpStrand,$hpId,$annoName,$annoType) = @{$hpInfo};
if ($annoType eq "Annotated" || !$annotOnly) {
my($prodName,$matureCount) = @{$mpInfo->{$hpId}};
print OPTF "$hpId\t$annoType\t$prodName\t$matureCount\n";
}
}
}
close(OPTF);
}
sub getMiRDeepAnnotations {
my($miRDeepResultsFile,$mirbaseGff) = @_;
my $warning = "";
my $parameters = mwPaperCommonCode::loadDefaultParameters();
my($mirDeepAccData,$mdPredictions,$mirDeepProducts) = mwPaperCommonCode::parseMirDeepResults($miRDeepResultsFile);
$mdPredictions = mwPaperCommonCode::applyMirdeepCutoff($mirDeepAccData,$mdPredictions,$parameters);
my($annoHairpins,$annoProducts) = miRWoods::readMirbaseGff3($mirbaseGff);
my($mdAnnotPredictions) = mwPaperCommonCode::annotateMirDeep($mdPredictions,$annoHairpins,$annoProducts,\$warning);
my($newMiRDeepAnnotPredictions,$duplicatePredictions,$duplicatedPredictionCount) = mwPaperCommonCode::checkForDuplicatePredictions($mdAnnotPredictions,
\$warning);
print $warning . "\n";
return($newMiRDeepAnnotPredictions,$mirDeepProducts,$mdPredictions);
}
sub getMajorProductCounts {
my($mdPredictions,$mirDeepProducts) = @_;
my $mpInfo = {};
foreach my $chrom (keys %{$mdPredictions}) {
foreach my $miRDeepResult (@{$mdPredictions->{$chrom}}) {
my($id,$score,$TPProb,$rfamAlert,$total,$matureCount,$loopCount,$starCount,$randfoldSignificant,$miRNA,$otherSpecMiRNA,$UCSCbrowser,$NCBIblastn,$mature,$star,$precursor,$location,$mdPredictionClass) = @{$miRDeepResult};
foreach my $prodInfo (@{$mirDeepProducts->{$id}}) {
my($chrom,$start,$stop,$strand,$prodName) = @{$prodInfo};
if ($prodName =~ /-mat-\dp$/) {
@{$mpInfo->{$id}} = ($prodName,$matureCount);
}
}
}
}
return $mpInfo;
}