-
Notifications
You must be signed in to change notification settings - Fork 0
/
mhcI_haplotype.pl
executable file
·220 lines (147 loc) · 9.48 KB
/
mhcI_haplotype.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env perl
# last updated on 07/07/2016
# This file is part of MHCI haplotype finder
#
# MHCI haplotype finder is the pipeline of perl scripts
# to analyse Illumina high throughput data of MHCI
# alleles in cattle.
#
# This script uses only pre-defined haplotype information
# based on MHCI genes deposited in IPD database.
# We are making it more generical in near future.
# Please refer README.txt for more detail on usage.
use warnings;
use Getopt::Long;
my $command = shift or die "Please enter command:\npreAlign - to analyse the paired-end raw/quility trimmed fastq files.\nBlast - to align processed unique aligned reads on database\npostAlign - to analyse the blast results\nanalyseUnknowns - to find out which sample has unknown sequences\n\n";
my $inDir;
my $total_samples;
my $dir;
my $flashPath;
my $fastxPath;
my $blastPath;
my $db;
my $onlySelected;
my $primer;
my $workDir;
my $read1;
my $read2;
if ($command eq "preAlign"){
GetOptions(
'fastqDir=s' => \$inDir,
'total_samples=i' => \$total_samples,
'dir=s' => \$dir,
'FlashPath=s' => \$flashPath,
'fastxToolkitPath=s' => \$fastxPath,
) or die "Usage:\n--fastqDir\t/Directory/of/Fastq/Files\n--total_samples\tTotal number of samples\n--dir\t/Full/path/to/main/directory\n--FlashPath\t/Full/Path/of/FLASH/software\n--fastxToolkitPath\t/Full/Path/of/fastx-toolkit/software\n\n";
if (! defined $inDir or ! defined $total_samples or ! defined $dir or ! defined $flashPath){
die "Usage:\n--fastqDir\t/Directory/of/Fastq/Files\n--total_samples\tTotal number of samples\n--dir\t/Full/path/to/main/directory\n--FlashPath\t/Full/Path/of/FLASH/software\n--fastxToolkitPath\t/Full/Path/of/fastx-toolkit/software\n\n";
}
for (my $n = 1; $n <= $total_samples; $n++){
print "\nRunning Sample $n\n";
$workDir = "$dir/Samples/$n";
$read1 = "$inDir/$n.R1.fastq.gz";
$read2 = "$inDir/$n.R2.fastq.gz";
system ("mkdir -p $workDir");
system ("mkdir -p $workDir/Flash");
print "**** Running FLASH for Sample $n using $read1 and $read2 ****\n";
system ("$flashPath/flash $read1 $read2 -m 20 -M 300 -o $n -d $workDir/Flash > $workDir/Flash/$n.flash.log");
print "**** Converting fastq into fasta: Sample $n...\n";
system ("$fastxPath/bin/fastq_to_fasta -r -v -Q33 -i $workDir/Flash/$n.extendedFrags.fastq -o $workDir/$n.extendedFrags.fasta > $workDir/$n.fastqToFasta.log");
print "**** Sorting primers in Sample $n...\n";
system ("perl sortPrimers.pl --input $workDir/$n.extendedFrags.fasta --outDir $workDir --prefix $n");
print "**** Grouping unique sequences in Sample $n For1Rev2...\n";
system ("perl findUniqueSeq.pl --input $workDir/$n.For1Rev2.fasta --outDir $workDir --cutoff 0.2 --prefix $n --primer For1Rev2");
print "**** Grouping unique sequences in Sample $n For3Rev1...\n";
system ("perl findUniqueSeq.pl --input $workDir/$n.For3Rev1.fasta --outDir $workDir --cutoff 0.2 --prefix $n --primer For3Rev1");
}
system("mkdir -p $dir/Reports");
print "\n\n**** Generating reports for primer sorting and unique sequences...\n";
system ("cat $dir/Samples/*/*.sortPrimer.log | sort -nk1 > $dir/Reports/sortPrimer.log");
system ("cat $dir/Samples/*/*.For1Rev2.uniqueSeq.log | sort -nk1 > $dir/Reports/For1Rev2.uniqueSeq.log");
system ("cat $dir/Samples/*/*.For3Rev1.uniqueSeq.log | sort -nk1 > $dir/Reports/For3Rev1.uniqueSeq.log");
}
elsif ($command eq "Blast"){
GetOptions(
'blastPath=s' => \$blastPath,
'db=s' => \$db,
'dir=s' => \$dir,
'total_samples=i' => \$total_samples,
'primer=s' => \$primer,
'onlySelected=s' => \$onlySelected,
) or die "Usage:\n--blastPath\t/Full/Path/of/Blast/software\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n--db\tblast indexed database\n--primer\tPrimer name\n--onlySelected\talign only selected sequences which are above threshold\n\n";
if (! defined $blastPath or ! defined $dir or ! defined $total_samples or ! defined $db or ! defined $primer){
die "Usage:\n--blastPath\t/Full/Path/of/Blast/software\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n--db\tblast indexed database\n--primer\tPrimer name\n--onlySelected\talign only selected sequences which are above threshold, TRUE or FALSE\n\n";
}
if ($onlySelected eq "TRUE" or $onlySelected eq "true" or $onlySelected eq "True"){
for ($n = 1; $n <= $total_samples; $n++){
$workDir = "$dir/Samples/$n";
print "Running BLAST for sample $n for $primer only selected sequences...\n";
system("$blastPath/bin/blastall -p blastn -d $db -i $workDir/$n.${primer}.selected.fasta -m 8 -o $workDir/$n.$primer.blast");
}
}
elsif ($onlySelected eq "FALSE" or $onlySelected eq "false" or $onlySelected eq "False"){
for ($n = 1; $n <= $total_samples; $n++){
$workDir = "$dir/Samples/$n";
print "Running BLAST for sample $n for $primer...\n";
system("$blastPath/bin/blastall -p blastn -d $db -i $workDir/$n.${primer}.unique.fasta -m 8 -o $workDir/$n.$primer.blast");
}
}
else{
die "Usage:\n--onlySelected\talign only selected sequences which are above threshold, TRUE or FALSE\n\n";
}
}
elsif ($command eq "postAlign"){
GetOptions(
'dir=s' => \$dir,
'total_samples=i' => \$total_samples,
) or die "Usage:\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n\n";
if (! defined $dir or ! defined $total_samples){
die "Usage:\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n\n";
}
for ($n = 1; $n <= $total_samples; $n++){
print "**** Analysing Blast of sample $n...\n";
$workDir = "$dir/Samples/$n";
system ("perl analyseBlast.pl --dir $workDir --prefix $n --primer For1Rev2");
system ("perl analyseBlast.pl --dir $workDir --prefix $n --primer For3Rev1");
print "\n\n**** Analysing known alleles and assigning haplotypes..\n";
system ("perl analyseKnownGenes.pl --dir $workDir --prefix $n --primer For1Rev2");
system ("perl analyseKnownGenes.pl --dir $workDir --prefix $n --primer For3Rev1");
print "\n\n**** Generating combining reports...\n";
system ("cat $dir/Samples/*/*.For1Rev2.unknown.fasta > $dir/Reports/Unknown.For1Rev2.fasta");
system ("cat $dir/Samples/*/*.For3Rev1.unknown.fasta > $dir/Reports/Unknown.For3Rev1.fasta");
system ("cat $dir/Samples/*/*.For1Rev2.analyseBlast.log | sort -nk1,1 > $dir/Reports/For1Rev2.analyseBlast.log.txt");
system ("cat $dir/Samples/*/*.For3Rev1.analyseBlast.log | sort -nk1,1 > $dir/Reports/For3Rev1.analyseBlast.log.txt");
system ("cat $dir/Samples/*/*.For1Rev2.haplotypes.genes.txt | sort -nk1,1 > $dir/Reports/For1Rev2.haplotypes.genes.txt");
system ("cat $dir/Samples/*/*.For3Rev1.haplotypes.genes.txt | sort -nk1,1 > $dir/Reports/For3Rev1.haplotypes.genes.txt");
system ("cat $dir/Samples/*/*.For1Rev2.haplotypes.txt | sort -nk1,1 > $dir/Reports/For1Rev2.haplotypes.txt");
system ("cat $dir/Samples/*/*.For3Rev1.haplotypes.txt | sort -nk1,1 > $dir/Reports/For3Rev1.haplotypes.txt");
system ("cat $dir/Samples/*/*.For1Rev2.analyseKnownGenes.log | sort -nk1,1 > $dir/Reports/For1Rev2.analyseKnownGenes.log.txt");
system ("cat $dir/Samples/*/*.For3Rev1.analyseKnownGenes.log | sort -nk1,1 > $dir/Reports/For3Rev1.analyseKnownGenes.log.txt");
system ("cat $dir/Samples/*/*.For1Rev2.extra.genes.txt | sort -nk1,1 > $dir/Reports/For1Rev2.extra.genes.txt");
system ("cat $dir/Samples/*/*.For3Rev1.extra.genes.txt | sort -nk1,1 > $dir/Reports/For3Rev1.extra.genes.txt");
system ("cat $dir/Samples/*/*.For1Rev2.nonclassic.genes.txt | sort -nk1,1 > $dir/Reports/For1Rev2.nonclassic.genes.txt");
system ("cat $dir/Samples/*/*.For3Rev1.nonclassic.genes.txt | sort -nk1,1 > $dir/Reports/For3Rev1.nonclassic.genes.txt");
}
}
elsif ($command eq "analyseUnknowns"){
GetOptions(
'dir=s' => \$dir,
'total_samples=i' => \$total_samples,
) or die "Usage:\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n\n";
if (! defined $dir or ! defined $total_samples){
die "Usage:\n--dir\t/Full/path/to/main/directory\n--total_samples\tTotal number of samples\n\n";
}
print "\n**** Grouping unique sequences from all unknown sequences for For1Rev2...\n";
system ("perl findUniqueUnknown.pl --input $dir/Reports/Unknown.For1Rev2.fasta --output $dir/Reports/Unknown.For1Rev2.unique.fasta --prefix Foo");
print "\n**** Grouping unique sequences from all unknown sequences for For3Rev1...\n";
system ("perl findUniqueUnknown.pl --input $dir/Reports/Unknown.For3Rev1.fasta --output $dir/Reports/Unknown.For3Rev1.unique.fasta --prefix Bar");
print "\n\n**** Allocating new unknown sequences ids to samples....\n";
system ("perl allocateUnknownFastaIds.pl --dir $dir --input $dir/Reports/Unknown.For1Rev2.unique.fasta --output $dir/Reports/Unknown.For1Rev2.unique.occurance.report.txt --primer For1Rev2 --total_samples $total_samples");
system ("perl allocateUnknownFastaIds.pl --dir $dir --input $dir/Reports/Unknown.For3Rev1.unique.fasta --output $dir/Reports/Unknown.For3Rev1.unique.occurance.report.txt --primer For3Rev1 --total_samples $total_samples");
print "\n\n**** Generating reports of unknown sequences...\n";
system ("cat ${dir}/Samples/*/*.For1Rev2.unknown.genes.txt | sort -nk1 > $dir/Reports/For1Rev2.unknown.genes.txt");
system ("cat ${dir}/Samples/*/*.For3Rev1.unknown.genes.txt | sort -nk1 > $dir/Reports/For3Rev1.unknown.genes.txt");
}
else{
die "Please enter command:\npreAlign - to analyse the paired-end raw fastq files.\nBlast - to align processed unique aligned reads on database\npostAlign - to analyse the blast results\nanalyseUnknowns - to find out which sample has unknown sequences\n\n";
}