Skip to content

Commit 0a10a52

Browse files
committed
analyze.php: Improved read data fallback to HG19 (now works if the output folder exists as well)
1 parent f026c65 commit 0a10a52

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/Pipelines/analyze.php

+25-12
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131
extract($parser->parse($argv));
3232

3333
// create logfile in output folder if no filepath is provided:
34-
$output_folder_exists = true;
3534
if (!file_exists($folder))
3635
{
37-
$output_folder_exists = false;
3836
exec2("mkdir -p $folder");
3937
}
4038
if ($parser->getLogFile() == "") $parser->setLogFile($folder."/analyze_".date("YmdHis").".log");
@@ -180,19 +178,34 @@
180178
$bamfile_to_convert = $bamfile;
181179

182180
//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")
184182
{
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);
188200

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";
191203

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);
194206

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+
}
196209
}
197210

198211
//determine input FASTQ files
@@ -234,7 +247,7 @@
234247
{
235248
if(file_exists($bamfile_to_convert))
236249
{
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);
238251

239252
// extract reads from BAM file
240253
$in_fq_for = $folder."/{$name}_BamToFastq_R1_001.fastq.gz";

src/Tools/liftover_bed.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require_once(dirname($_SERVER['SCRIPT_FILENAME'])."/../Common/all.php");
66

77
// parse command line arguments
8-
$parser = new ToolBase("liftover_bed", "Lift-over from.");
8+
$parser = new ToolBase("liftover_bed", "Lift-over ob BED file from GRCh37 to GRCh38.");
99
$parser->addInfile("in", "Input BED file.", false);
1010
$parser->addOutfile("out", "Input BED file.", false);
1111
$parser->addInt("max_size_inc", "Maximum size increase.", true, 10);
@@ -54,7 +54,7 @@
5454
$size_diff_perc = 100.0 * $size_diff / $size_before;
5555
if ($size_after>$size_before && $size_diff>$max_size_inc && $size_diff_perc>$max_size_inc_perc)
5656
{
57-
print "Error - different size after mapping (from ".($end-$start)." to ".($end2-$start2)."): $line\n";
57+
print "Error - bigger size after mapping (from ".($end-$start)." to ".($end2-$start2)."): $line\n";
5858
continue;
5959
}
6060

0 commit comments

Comments
 (0)