@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix CommandLineBinding: <https://w3id.org/cwl/cwl#CommandLineBinding/> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix DockerRequirement: <https://w3id.org/cwl/cwl#DockerRequirement/> .
@prefix cwl:   <https://w3id.org/cwl/cwl#> .
@prefix Workflow: <https://w3id.org/cwl/cwl#Workflow/> .
@prefix ResourceRequirement: <https://w3id.org/cwl/cwl#ResourceRequirement/> .
@prefix sld:   <https://w3id.org/cwl/salad#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix CommandOutputBinding: <https://w3id.org/cwl/cwl#CommandOutputBinding/> .
@prefix ns1:   <http://commonwl.org/cwltool#> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt>
        cwl:in   <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt/vcf> ;
        cwl:out  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt/processed_vcf> ;
        cwl:run  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#processed_vcf>
        cwl:outputSource    <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index/indexed_vcf> ;
        cwl:secondaryFiles  []  ;
        sld:type            cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl#indexed_vcf>
        cwl:outputBinding   [ CommandOutputBinding:glob
                          "$(inputs.vcf.basename)" ] ;
        cwl:secondaryFiles  []  ;
        sld:type            cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl>
        a                        cwl:CommandLineTool ;
        rdfs:label               "add GT tags" ;
        ns1:original_cwlVersion  "v1.0" ;
        cwl:arguments            ( "/usr/bin/perl" "add_strelka_gt.pl" "$(inputs.vcf.path)" "$(runtime.outdir)" ) ;
        cwl:cwlVersion           <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/v1.2> ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/NetworkAccess> ] ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/LoadListingRequirement> ] ;
        cwl:inputs               <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl#vcf> ;
        cwl:outputs              <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl#processed_vcf> ;
        cwl:requirements         [ a            cwl:InitialWorkDirRequirement ;
                                   cwl:listing  [ cwl:entry      "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse feature qw(say);\n\ndie(\"wrong number of arguments\") unless scalar(@ARGV) == 2;\nmy ($strelka_vcf, $outdir) = @ARGV;\n\nopen(my $strelka_vcf_fh, '-|', '/bin/gunzip', '-c', $strelka_vcf) \n    or die(\"couldn't open $strelka_vcf to read\");\nopen(my $add_gt_fh, \">\", \"$outdir/add_gt.vcf\") \n    or die(\"couldn't open add_gt.vcf for write\");\n\nwhile (<$strelka_vcf_fh>) {\n    chomp;\n    if (/^##/) {\n        say $add_gt_fh $_;\n    }\n    elsif (/^#/) { #COLUMN HEADER\n        say $add_gt_fh '##FORMAT=<ID=GT,Number=1,Type=String,Description=\"Genotype\">';\n        say $add_gt_fh $_;\n    }\n    else {\n        my @columns = split /\\t/, $_;\n        my ($ref, $alt, $info) = map{$columns[$_]}(3, 4, 7);\n        my @alts = split /,/, $alt;\n\n        my ($n_gt, $t_gt);\n\n        if (length($ref) == 1 and length($alts[0]) == 1) {\n            my ($n_gt_info, $n_gt_str, $t_gt_str) = $info =~ /NT=(\\S+?);QSS.*SGT=(\\S+?)\\->(\\S+?);/;\n            unshift @alts, $ref;\n\n            my %ids;\n            my $id = 0;\n\n            for my $base (@alts) {\n                $ids{$base} = $id;\n                $id++;\n            }\n\n            $n_gt = $n_gt_info eq 'ref' ? '0/0' : parse_gt($n_gt_str, \\%ids);\n            $t_gt = parse_gt($t_gt_str, \\%ids);\n        }\n        else {#INDEL\n            my ($n_gt_info, $t_gt_info) = $info =~ /;NT=(\\S+?);.*SGT.*\\->(\\S+?);/;\n\n            my %gt_info = (\n                ref => '0/0',\n                het => '0/1',\n                hom => '1/1',\n                conflict => './.',\n            );\n\n            $n_gt = $gt_info{$n_gt_info};\n            $t_gt = $gt_info{$t_gt_info};\n        }\n\n        $columns[8]  = 'GT:'.$columns[8];\n        $columns[9]  = $n_gt . ':' . $columns[9];\n        $columns[10] = $t_gt . ':' . $columns[10];\n\n        my $new_str = join \"\\t\", @columns;\n        say $add_gt_fh $new_str;\n    }\n}\n\nclose($strelka_vcf_fh);\nclose($add_gt_fh);\n\n\nsub parse_gt {\n    my ($gt_str, $ids) = @_;\n    my @gt_ids = map{$ids->{$_}}(split //, $gt_str);\n    return join '/', sort @gt_ids;\n}\n\n#SNV example\n#1       10231   .       C       A       .       QSS_ref NT=ref;QSS=1;QSS_NT=1;SGT=AC->AC;SOMATIC;TQSS=2;TQSS_NT=2       DP:FDP:SDP:SUBDP:AU:CU:GU:TU    32:4:8:0:0,3:28,60:0,0:0,1      84:6:69:0:7,21:71,192:0,0:0,1\n#INDEL example\n##1     965051  .       ATGTGTG A       .       QSI_ref IC=5;IHP=2;NT=ref;QSI=1;QSI_NT=1;RC=8;RU=TG;SGT=het->het;SOMATIC;TQSI=1;TQSI_NT=1       DP:DP2:TAR:TIR:TOR:DP50:FDP50:SUBDP50   8:8:6,6:0,0:2,4:10.3:0.00:0.00  18:18:8,8:5,6:5,8:21:0.25:0.00\n" ;
                                                  cwl:entryname  "add_strelka_gt.pl"
                                                ]
                                 ] ;
        cwl:requirements         [ a                           cwl:ResourceRequirement ;
                                   ResourceRequirement:ramMin  4000
                                 ] ;
        cwl:requirements         [ a                             cwl:DockerRequirement ;
                                   DockerRequirement:dockerPull  "ubuntu:bionic"
                                 ] .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl#bgzipped_file>
        cwl:outputBinding  [ CommandOutputBinding:glob
                          "$(inputs.file.basename).gz" ] ;
        sld:type           cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl>
        a                        cwl:CommandLineTool ;
        rdfs:label               "vcf index" ;
        ns1:original_cwlVersion  "v1.0" ;
        cwl:arguments            ( "cp" "$(inputs.vcf.path)" "$(runtime.outdir)/$(inputs.vcf.basename)"
                                   [ CommandLineBinding:shellQuote  false ;
                                     cwl:valueFrom                  " && "
                                   ]
                                   "/usr/bin/tabix" "-p" "vcf"
                                 ) ;
        cwl:cwlVersion           <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/v1.2> ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/NetworkAccess> ] ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/LoadListingRequirement> ] ;
        cwl:inputs               <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl#vcf> ;
        cwl:outputs              <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl#indexed_vcf> ;
        cwl:requirements         [ a                           cwl:ResourceRequirement ;
                                   ResourceRequirement:ramMin  4000
                                 ] ;
        cwl:requirements         [ a                             cwl:DockerRequirement ;
                                   DockerRequirement:dockerPull  "mgibio/samtools-cwl:1.0.0"
                                 ] ;
        cwl:requirements         [ a  cwl:ShellCommandRequirement ] .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip/file>
        cwl:source  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt/processed_vcf> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl#vcf>
        cwl:inputBinding  [ CommandLineBinding:position  1 ;
                            cwl:valueFrom                "$(self.basename)"
                          ] ;
        sld:type          cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip>
        cwl:in   <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip/file> ;
        cwl:out  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip/bgzipped_file> ;
        cwl:run  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl#processed_vcf>
        cwl:outputBinding  [ CommandOutputBinding:glob
                          "add_gt.vcf" ] ;
        sld:type           cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#vcf>
        sld:type  cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl#file>
        cwl:inputBinding  [ CommandLineBinding:position
                          1 ] ;
        sld:type          cwl:File .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index/vcf>
        cwl:source  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip/bgzipped_file> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt/vcf>
        cwl:source  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#vcf> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl>
        a                        cwl:CommandLineTool ;
        rdfs:label               "bgzip VCF" ;
        ns1:original_cwlVersion  "v1.0" ;
        cwl:arguments            ( "-c" ) ;
        cwl:baseCommand          ( "/opt/htslib/bin/bgzip" ) ;
        cwl:cwlVersion           <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/v1.2> ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/LoadListingRequirement> ] ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/NetworkAccess> ] ;
        cwl:inputs               <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl#file> ;
        cwl:outputs              <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/bgzip.cwl#bgzipped_file> ;
        cwl:requirements         [ a                             cwl:DockerRequirement ;
                                   DockerRequirement:dockerPull  "mgibio/samtools-cwl:1.0.0"
                                 ] ;
        cwl:requirements         [ a                           cwl:ResourceRequirement ;
                                   ResourceRequirement:ramMin  4000
                                 ] ;
        cwl:stdout               "$(inputs.file.basename).gz" .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index>
        cwl:in   <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index/vcf> ;
        cwl:out  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index/indexed_vcf> ;
        cwl:run  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/index_vcf.cwl> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl>
        a                        cwl:Workflow ;
        rdfs:label               "process VCF workflow" ;
        ns1:original_cwlVersion  "v1.0" ;
        Workflow:steps           <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#add_gt> , <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#bgzip> , <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#index> ;
        cwl:cwlVersion           <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/v1.2> ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/LoadListingRequirement> ] ;
        cwl:hints                [ a  <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/NetworkAccess> ] ;
        cwl:inputs               <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#vcf> ;
        cwl:outputs              <https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/subworkflows/strelka_process_vcf.cwl#processed_vcf> .

<https://w3id.org/cwl/view/git/233f026ffce240071edda526391be0c03186fce8/definitions/tools/add_strelka_gt.cwl#vcf>
        sld:type  cwl:File .
