|
31 | 31 | extract($parser->parse($argv));
|
32 | 32 |
|
33 | 33 | // create logfile in output folder if no filepath is provided:
|
34 |
| -$output_folder_exists = true; |
35 | 34 | if (!file_exists($folder))
|
36 | 35 | {
|
37 |
| - $output_folder_exists = false; |
38 | 36 | exec2("mkdir -p $folder");
|
39 | 37 | }
|
40 | 38 | if ($parser->getLogFile() == "") $parser->setLogFile($folder."/analyze_".date("YmdHis").".log");
|
|
180 | 178 | $bamfile_to_convert = $bamfile;
|
181 | 179 |
|
182 | 180 | //fallback for remapping GRCh37 samples to GRCh38 - use BAM to create FASTQs
|
183 |
| - if (!$output_folder_exists && $sys['build']=="GRCh38") |
| 181 | + if ($sys['build']=="GRCh38") |
184 | 182 | {
|
185 |
| - if (!db_is_enabled("NGSD")) trigger_error("NGSD access required to determine GRCh37 sample path!", E_USER_ERROR); |
186 |
| - $db = DB::getInstance("NGSD", false); |
187 |
| - $info = get_processed_sample_info($db, $name, false); |
| 183 | + //determine if HG38 folder contains read data |
| 184 | + $read_data_present = false; |
| 185 | + list($files) = exec2("ls {$folder}"); |
| 186 | + foreach($files as $file) |
| 187 | + { |
| 188 | + if (ends_with($file, ".bam") || ends_with($file, ".fastq.gz")) |
| 189 | + { |
| 190 | + $read_data_present = true; |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + //no read data > try to generate it from HG19 |
| 195 | + if (!$read_data_present) |
| 196 | + { |
| 197 | + if (!db_is_enabled("NGSD")) trigger_error("NGSD access required to determine GRCh37 sample path!", E_USER_ERROR); |
| 198 | + $db = DB::getInstance("NGSD", false); |
| 199 | + $info = get_processed_sample_info($db, $name, false); |
188 | 200 |
|
189 |
| - // determine project folder of GRCh37 |
190 |
| - $bamfile_to_convert = get_path("GRCh37_project_folder").$info['project_type']."/".$info['project_name']."/Sample_${name}/${name}.bam"; |
| 201 | + // determine project folder of GRCh37 |
| 202 | + $bamfile_to_convert = get_path("GRCh37_project_folder").$info['project_type']."/".$info['project_name']."/Sample_${name}/${name}.bam"; |
191 | 203 |
|
192 |
| - // check if bam file exists |
193 |
| - if (!file_exists($bamfile_to_convert)) trigger_error("BAM file of GRCh37 sample is missing!", E_USER_ERROR); |
| 204 | + // check if bam file exists |
| 205 | + if (!file_exists($bamfile_to_convert)) trigger_error("BAM file of GRCh37 sample is missing!", E_USER_ERROR); |
194 | 206 |
|
195 |
| - trigger_error("Output folder does not exists. Using BAM or Fastq files from GRCh37 as input!", E_USER_NOTICE); |
| 207 | + trigger_error("No read data found in output folder. Using BAM/FASTQ files from GRCh37 as input!", E_USER_NOTICE); |
| 208 | + } |
196 | 209 | }
|
197 | 210 |
|
198 | 211 | //determine input FASTQ files
|
|
234 | 247 | {
|
235 | 248 | if(file_exists($bamfile_to_convert))
|
236 | 249 | {
|
237 |
| - trigger_error("No FASTQ files found in folder. Using BAM file to generate FASTQ files.", E_USER_NOTICE); |
| 250 | + trigger_error("No FASTQ files found in folder. Using BAM file to generate FASTQ files: $bamfile_to_convert", E_USER_NOTICE); |
238 | 251 |
|
239 | 252 | // extract reads from BAM file
|
240 | 253 | $in_fq_for = $folder."/{$name}_BamToFastq_R1_001.fastq.gz";
|
|
0 commit comments