diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63123fb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_store diff --git a/README.md b/README.md index 56827a1..6968970 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # CellrangerPipeline batch run for cellranger count + +``` +perl batchCellrangerCounter.pl --help +version 1.0, October 2018 +usage: batchCellrangerCounter.pl +-f|--fastq + path to FastQ files (required) +-o|--output-dir + path to output directory (required) +-g|--genome + path to genome index (required) +-p|--opts + additional Cellranger Count parameters +-h|--help + print help message +-v|--version + print current version +``` + +example: + +``` +perl batchCellrangerCounter.pl --fastq /path/to/fastq/ --output-dir /path/to/projec/cellranger_count_out/ --genome /path/to/genome/alien/cellranger/ --opts "--chemistry SC3Pv2 --localcores=32 --force-cells=7000" +``` diff --git a/batchCellrangerCounter.pl b/batchCellrangerCounter.pl new file mode 100644 index 0000000..c994767 --- /dev/null +++ b/batchCellrangerCounter.pl @@ -0,0 +1,142 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Getopt::Long(); + +sub usage($); +sub version($); + +sub createBatchJob($); +sub runCellranger($$$$); + +MAIN: +{ + # define inputs + my $version_tag = "version 1.0, October 2018"; + my $version; + my $help; + my $path_fastq; + my $path_genome_index; + my $path_output; + my $opts_cellranger; + + # set-up paramters + Getopt::Long::GetOptions( + "f|fastq=s" => \$path_fastq, + "o|output-dir=s" => \$path_output, + "g|genome=s" => \$path_genome_index, + "p|opts=s" => \$opts_cellranger, + "h|help" => \$help, + "v|version" => \$version + ) or usage("Error::invalid command line options"); + + # parse inputs + version($version_tag) if($version); + usage($version_tag) if($help); + usage("Error::path to FastQ files is required") unless defined($path_fastq); + usage("Error::path to output location is required") unless defined($path_output); + usage("Error::path to genome index is required") unless defined($path_genome_index); + + # create batch job + my $batch_job = createBatchJob($path_fastq); + + # run cellranger count + runCellranger($batch_job, $path_output, $path_genome_index, $opts_cellranger); + +} + + +sub runCellranger($$$$) +{ + my $batch_job = $_[0]; + my $path_output = $_[1]; + my $path_genome_index = $_[2]; + my $opts_cellranger = $_[3]; + + foreach my $id (sort keys %{$batch_job}) + { + my $command = "cellranger count" . + " --id=" . $id . + " --fastqs=" . $batch_job->{$id} . + " --transcriptome=" . $path_genome_index . + " --sample=" . $id; + $command .= " " . $opts_cellranger if (defined($opts_cellranger)); + + print $command,"\n"; + #system($command); + + # move result to output folder + if (-d $id) + { + $path_output =~ s/\/$//g; + $command = "mv " . $id . " " . $path_output . '/' . $id; + print $command,"\n"; + #system($command); + } + } +} + +sub createBatchJob($) +{ + my $path_fastq = $_[0]; + my %tags = (); + + $path_fastq =~ s/\/$//g; + + opendir(my $dh, $path_fastq); + while (my $path_tag = readdir $dh) + { + + my $path_full = $path_fastq . '/' . $path_tag; + next unless -d $path_full; + next if ($path_tag =~ m/^\./); + $tags{$path_tag} = $path_full; + } + closedir($dh); + return \%tags; +} + + +sub usage($) +{ + my $message = $_[0]; + if (defined $message && length($message)) + { + $message .= "\n" unless($message =~/\n$/); + } + my $command = $0; + $command =~ s#^.*/##; + + print STDERR ( + $message, + "usage: $command\n" . + "-f|--fastq\n" . + "\t path to FastQ files (required)\n" . + "-o|--output-dir\n" . + "\t path to output directory (required)\n" . + "-g|--genome\n" . + "\t path to genome index (required)\n" . + "-p|--opts\n" . + "\t additional Cellranger Count parameters\n" . + "-h|--help\n" . + "\t print help message\n" . + "-v|--version\n" . + "\t print current version\n" + ); + + die("\n"); +} + +sub version($) +{ + my $message = $_[0]; + print STDERR ( + $message,"\n", + "Scientific Computing Facility\n", + "Max-Planck Institute For Brain Research\n", + "bug reports to:\n", + "\tsciclist\@brain.mpg.de\n" + ); + die("\n"); +} \ No newline at end of file