.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Genome::Model::Tools::Music::Survival 3pm" .TH Genome::Model::Tools::Music::Survival 3pm "2020-11-06" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .IP "\(bu" 4 Headers are required. .IP "\(bu" 4 The first column of each clinical data file must contain sample IDs which match those in both the \-\-bam\-list and the \s-1MAF\s0 variant list (in the \s-1MAF,\s0 this is the Tumor_Sample_Barcode column, specifically). .IP "\(bu" 4 In at least one of the clinical data files input, columns with headers \*(L"vital_status\*(R" and \*(L"days_to_last_followup\*(R" (case insensitive) must exist. \*(L"vital_status\*(R" must be delineated by 1's and 0's, where 0 denotes 'living', and 1 denotes 'deceased'. .PP Note that all input files must be tab-separated. .PP \&\s-1HELP\s0 } .PP sub _additional_help_sections { return ( \*(L"\s-1ARGUMENTS\*(R",\s0 <<\s-1EOS\s0 .IP "\-\-bam\-list" 4 .IX Item "--bam-list" .RS 4 .PD 0 .IP "Provide a file containing sample names and normal/tumor \s-1BAM\s0 locations for each. Use the tab\- delimited format [sample_name normal_bam tumor_bam] per line. This tool only needs sample_name, so all other columns can be skipped. The sample_name must be the same as the tumor sample names used in the \s-1MAF\s0 file (16th column, with the header Tumor_Sample_Barcode)." 8 .IX Item "Provide a file containing sample names and normal/tumor BAM locations for each. Use the tab- delimited format [sample_name normal_bam tumor_bam] per line. This tool only needs sample_name, so all other columns can be skipped. The sample_name must be the same as the tumor sample names used in the MAF file (16th column, with the header Tumor_Sample_Barcode)." .RE .RS 4 .RE .PD .PP \&\s-1EOS\s0 ); } .PP sub _doc_authors { return <<\s-1EOS\s0 Nathan D. Dees, Ph.D. Qunyuan Zhang, Ph.D. \&\s-1EOS\s0 } .PP sub execute { .PP .Vb 5 \& # parse input arguments \& my $self = shift; \& my $bam_list = $self\->bam_list; \& my $genetic_data_type = $self\->genetic_data_type; \& my $legend_placement = $self\->legend_placement; \& \& # handle phenotype inclusions \& my @phenotypes_to_include; \& my @clinical_phenotypes_to_include; \& my @mutated_genes_to_include; \& if ($self\->phenotypes_to_include) { @phenotypes_to_include = split /,/,$self\->phenotypes_to_include; } \& \& # check genetic data type \& unless ($genetic_data_type =~ /^gene|variant$/i) { \& $self\->error_message("Please enter either \e"gene\e" or \e"variant\e" for the \-\-genetic\-data\-type parameter."); \& return; \& } \& \& # load clinical data and analysis types \& my %clinical_data; \& if ($self\->numeric_clinical_data_file) { \& $clinical_data{\*(Aqnumeric\*(Aq} = $self\->numeric_clinical_data_file; \& } \& if ($self\->categorical_clinical_data_file) { \& $clinical_data{\*(Aqcateg\*(Aq} = $self\->categorical_clinical_data_file; \& } \& if ($self\->glm_clinical_data_file) { \& $clinical_data{\*(Aqglm\*(Aq} = $self\->glm_clinical_data_file; \& } \& \& # create array of all sample names possibly included from clinical data and MAF \& my @all_sample_names; # names of all the samples, no matter if they are mutated or not \& my $sampleFh = IO::File\->new( $bam_list ) or die "Couldn\*(Aqt open $bam_list. $!\en"; \& while( my $line = $sampleFh\->getline ) \& { \& next if ( $line =~ m/^#/ ); \& chomp( $line ); \& my ( $sample ) = split( /\et/, $line ); \& push( @all_sample_names, $sample ); \& } \& $sampleFh\->close; \& \& # loop through clinical data files and assemble survival data hash (vital_status and days_to_last_followup required); \& my %survival_data; \& my $vital_status_flag = 0; \& my $days_to_last_follow_flag = 0; \& \& for my $clin_file (keys %clinical_data) { \& \& #check filehandle \& my $clin_fh = new IO::File $clinical_data{$clin_file},"r"; \& unless ($clin_fh) { \& $self\->error_message("Failed to open $clinical_data{$clin_file} for reading: $!"); \& return; \& } \& \& #initiate variables to hold column info \& my %phenotypes_to_print; \& my $vital_status_col = 0; \& my $days_to_last_follow_col = 0; \& \& #parse header and record column locations for needed data \& my $header = $clin_fh\->getline; \& my @header_fields = split /\et/,$header; \& for (my $i = 1; $i <= $#header_fields; $i++) { #sample ID should be in first column of file \& my $field = $header_fields[$i]; \& if ($field =~ /vital_status|vitalstatus/i) { $vital_status_col = $i; $vital_status_flag++; } \& if ($field =~ /days_to_last_(follow_up|followup)|daystolastfollowup/i) { $days_to_last_follow_col = $i; $days_to_last_follow_flag++; } \& if (scalar grep { /^$field$/i } @phenotypes_to_include) { $phenotypes_to_print{$field} = $i; } \& } \& \& #read through clinical data file and store needed data in a hash \& while (my $line = $clin_fh\->getline) { \& chomp $line; \& my @fields = split /\et/,$line; \& my $sample = $fields[0]; \& unless (scalar grep { m/^$sample$/ } @all_sample_names) { \& $self\->status_message("Skipping sample $sample. (Sample is not in \-\-bam\-list)."); \& next; \& } \& if ($vital_status_col) { \& my $vital_status; \& if ($fields[$vital_status_col] =~ /^(0|living)$/i) { $vital_status = 0; } \& elsif ($fields[$vital_status_col] =~ /^(1|deceased)$/i) { $vital_status = 1; } \& else { $vital_status = "NA"; } \& $survival_data{$sample}{\*(Aqvital_status\*(Aq} = $vital_status; \& } \& if ($days_to_last_follow_col) { $survival_data{$sample}{\*(Aqdays\*(Aq} = $fields[$days_to_last_follow_col]; } \& for my $pheno (keys %phenotypes_to_print) { $survival_data{$sample}{$pheno} = $fields[$phenotypes_to_print{$pheno}]; } \& } \& $clin_fh\->close; \& \& # record phenotypes included from clinical data \& push @clinical_phenotypes_to_include, keys %phenotypes_to_print; \& \& } \& \& # check for necessary header fields \& unless ($vital_status_flag) { \& $self\->error_message(\*(AqClinical data does not seem to contain a column labeled "vital_status".\*(Aq); \& return; \& } \& unless ($days_to_last_follow_flag) { \& $self\->error_message(\*(AqClnical data does not seem to contain a column labeled "days_to_last_followup".\*(Aq); \& return; \& } \& \& # create temporary files for R command \& my $survival_data_file = Genome::Sys\->create_temp_file_path(); \& my $mutation_matrix = Genome::Sys\->create_temp_file_path(); \& \& # print survival data (temp file) \& my $surv_fh = new IO::File $survival_data_file,"w" or die "Couldn\*(Aqt open survival data filehandle."; \& print $surv_fh join("\et","Sample","Days_To_Last_Followup","Vital_Status"); \& if (@clinical_phenotypes_to_include) { print $surv_fh "\et" . join("\et",@clinical_phenotypes_to_include); } \& print $surv_fh "\en"; \& for my $sample (keys %survival_data) { \& unless (exists $survival_data{$sample}{\*(Aqdays\*(Aq}) { $survival_data{$sample}{\*(Aqdays\*(Aq} = "NA"; } \& unless (exists $survival_data{$sample}{\*(Aqvital_status\*(Aq}) { $survival_data{$sample}{\*(Aqvital_status\*(Aq} = "NA"; } \& print $surv_fh join("\et",$sample,$survival_data{$sample}{\*(Aqdays\*(Aq},$survival_data{$sample}{\*(Aqvital_status\*(Aq}); \& for my $pheno (@clinical_phenotypes_to_include) { \& unless (exists $survival_data{$sample}{$pheno}) { $survival_data{$sample}{$pheno} = "NA"; } \& print $surv_fh "\et" . $survival_data{$sample}{$pheno}; \& } \& print $surv_fh "\en"; \& } \& $surv_fh\->close; \& \& # find if any of the "phenotypes_to_include" are genes, and if so, limit the MAF mutation matrix to those genes \& my %clinical_pheno_to_include; \& @clinical_pheno_to_include{@clinical_phenotypes_to_include} = (); \& for my $item (@phenotypes_to_include) { \& push @mutated_genes_to_include,$item unless exists $clinical_pheno_to_include{$item}; \& } \& my $mutated_genes_to_include = \e@mutated_genes_to_include; \& \& # create mutation matrix file \& if( $genetic_data_type =~ /^gene$/i ) { \& $self\->create_sample_gene_matrix_gene( $mutation_matrix, $mutated_genes_to_include, @all_sample_names ); \& } \& elsif( $genetic_data_type =~ /^variant$/i ) { \& $self\->create_sample_gene_matrix_variant( $mutation_matrix, $mutated_genes_to_include, @all_sample_names ); \& } \& else { \& $self\->error_message( "Please enter either \e"gene\e" or \e"variant\e" for the \-\-genetic\-data\-type parameter." ); \& return; \& } \& \& # check and prepare output directory \& my $output_dir = $self\->output_dir . "/"; \& unless (\-e $output_dir) { \& $self\->status_message("Creating output directory: $output_dir..."); \& unless(mkdir $output_dir) { \& $self\->error_message("Failed to create output directory: $!"); \& return; \& } \& } \& \& # set up R command \& my $R_cmd = "R \-\-slave \-\-args < " . _\|_FILE_\|_ . ".R " . join( " ", $survival_data_file, $mutation_matrix, $legend_placement, $output_dir ); \& print "R_cmd:\en$R_cmd\en"; \& \& #run R command \& WIFEXITED( system $R_cmd ) or croak "Couldn\*(Aqt run: $R_cmd ($?)"; \& \& return(1); \&} .Ve .PP sub create_sample_gene_matrix_gene { .PP .Vb 1 \& my ( $self, $mutation_matrix, $mutated_genes_to_include, @all_sample_names ) = @_; \& \& #create hash of mutations from the MAF file \& my ( %mutations, %all_genes ); \& \& #parse the MAF file and fill up the mutation status hashes \& my $maf_fh = IO::File\->new( $self\->maf_file ) or die "Couldn\*(Aqt open MAF file!\en"; \& while( my $line = $maf_fh\->getline ) { \& next if( $line =~ m/^(#|Hugo_Symbol)/ ); \& chomp $line; \& my @cols = split( /\et/, $line ); \& my ( $gene, $mutation_class, $sample ) = @cols[0,8,15]; \& \& #check that the mutation class is valid \& if( $mutation_class !~ m/^(Missense_Mutation|Nonsense_Mutation|Nonstop_Mutation|Splice_Site|Translation_Start_Site|Frame_Shift_Del|Frame_Shift_Ins|In_Frame_Del|In_Frame_Ins|Silent|Intron|RNA|3\*(AqFlank|3\*(AqUTR|5\*(AqFlank|5\*(AqUTR|IGR|Targeted_Region|De_novo_Start_InFrame|De_novo_Start_OutOfFrame)$/ ) { \& $self\->error_message( "Unrecognized Variant_Classification \e"$mutation_class\e" in MAF file for gene $gene\enPlease use TCGA MAF v2.3.\en" ); \& return; \& } \& \& #check to see if this gene is on the list (if there is a list at all) \& if( @{$mutated_genes_to_include} ) { \& next unless( scalar grep { m/^$gene$/ } @{$mutated_genes_to_include} ); \& } \& \& # If user wants, skip Silent mutations, or those in Introns, RNA, UTRs, Flanks, IGRs, or the ubiquitous Targeted_Region \& if(( $self\->skip_non_coding && $mutation_class =~ m/^(Intron|RNA|3\*(AqFlank|3\*(AqUTR|5\*(AqFlank|5\*(AqUTR|IGR|Targeted_Region)$/ ) || \& ( $self\->skip_silent && $mutation_class =~ m/^Silent$/ )) { \& print "Skipping $mutation_class mutation in gene $gene.\en"; \& next; \& } \& \& $all_genes{$gene}++; \& $mutations{$sample}{$gene}++; \& } \& $maf_fh\->close; \& \& #sort @all_genes for consistency in header and loops \& my @all_genes = sort keys %all_genes; \& \& #write the input matrix for R code to a temp file \& my $matrix_fh = new IO::File $mutation_matrix,"w" or die "Failed to create matrix file $mutation_matrix!: $!"; \& \& #print input matrix file header \& my $header = join( "\et", "Sample", @all_genes ); \& $matrix_fh\->print( "$header\en" ); \& \& #print mutation relation input matrix \& for my $sample ( sort @all_sample_names ) { \& $matrix_fh\->print( $sample ); \& for my $gene ( @all_genes ) { \& if( exists $mutations{$sample}{$gene} ) { \& $matrix_fh\->print( "\et$mutations{$sample}{$gene}" ); \& } \& else { \& $matrix_fh\->print( "\et0" ); \& } \& } \& $matrix_fh\->print( "\en" ); \& } \&} .Ve .PP sub create_sample_gene_matrix_variant { .PP .Vb 1 \& my ( $self, $mutation_matrix, $mutated_genes_to_include, @all_sample_names ) = @_; \& \& #create hash of mutations from the MAF file \& my ( %variants_hash, %all_variants ); \& \& #parse the MAF file and fill up the mutation status hashes \& my $maf_fh = IO::File\->new( $self\->maf_file ) or die "Couldn\*(Aqt open MAF file!\en"; \& while( my $line = $maf_fh\->getline ) { \& next if( $line =~ m/^(#|Hugo_Symbol)/ ); \& chomp $line; \& my @cols = split( /\et/, $line ); \& my ( $gene, $chr, $start, $stop, $mutation_class, $mutation_type, $ref, $var1, $var2, $sample ) = @cols[0,4..6,8..12,15]; \& \& #check that the mutation class is valid \& if( $mutation_class !~ m/^(Missense_Mutation|Nonsense_Mutation|Nonstop_Mutation|Splice_Site|Translation_Start_Site|Frame_Shift_Del|Frame_Shift_Ins|In_Frame_Del|In_Frame_Ins|Silent|Intron|RNA|3\*(AqFlank|3\*(AqUTR|5\*(AqFlank|5\*(AqUTR|IGR|Targeted_Region|De_novo_Start_InFrame|De_novo_Start_OutOfFrame)$/ ) { \& $self\->error_message( "Unrecognized Variant_Classification \e"$mutation_class\e" in MAF file for gene $gene\enPlease use TCGA MAF v2.3.\en" ); \& return; \& } \& \& #check to see if this gene is on the list (if there is a list at all) \& if( @{$mutated_genes_to_include} ) { \& next unless (scalar grep { m/^$gene$/ } @{$mutated_genes_to_include}); \& } \& \& # If user wants, skip Silent mutations, or those in Introns, RNA, UTRs, Flanks, IGRs, or the ubiquitous Targeted_Region \& if(( $self\->skip_non_coding && $mutation_class =~ m/^(Intron|RNA|3\*(AqFlank|3\*(AqUTR|5\*(AqFlank|5\*(AqUTR|IGR|Targeted_Region)$/ ) || \& ( $self\->skip_silent && $mutation_class =~ m/^Silent$/ )) { \& print "Skipping $mutation_class mutation in gene $gene.\en"; \& next; \& } \& \& my $var; \& my $variant_name; \& if( $ref eq $var1 ) { \& $var = $var2; \& $variant_name = $gene."_".$chr."_".$start."_".$stop."_".$ref."_".$var; \& $variants_hash{$sample}{$variant_name}++; \& $all_variants{$variant_name}++; \& } \& elsif( $ref eq $var2 ) { \& $var = $var1; \& $variant_name = $gene."_".$chr."_".$start."_".$stop."_".$ref."_".$var; \& $variants_hash{$sample}{$variant_name}++; \& $all_variants{$variant_name}++; \& } \& elsif( $ref ne $var1 && $ref ne $var2 ) { \& $var = $var1; \& $variant_name = $gene."_".$chr."_".$start."_".$stop."_".$ref."_".$var; \& $variants_hash{$sample}{$variant_name}++; \& $all_variants{$variant_name}++; \& $var = $var2; \& $variant_name = $gene."_".$chr."_".$start."_".$stop."_".$ref."_".$var; \& $variants_hash{$sample}{$variant_name}++; \& $all_variants{$variant_name}++; \& } \& } \& $maf_fh\->close; \& \& #sort variants for consistency \& my @variant_names = sort keys %all_variants; \& \& #write the input matrix for R code to a file \& my $matrix_fh = new IO::File $mutation_matrix,"w" or die "Failed to create matrix file $mutation_matrix!: $!"; \& \& #print input matrix file header \& my $header = join("\et","Sample",@variant_names); \& $matrix_fh\->print("$header\en"); \& \& #print mutation relation input matrix \& for my $sample (sort @all_sample_names) { \& $matrix_fh\->print($sample); \& for my $variant (@variant_names) { \& if (exists $variants_hash{$sample}{$variant}) { \& $matrix_fh\->print("\et$variants_hash{$sample}{$variant}"); \& } \& else { \& $matrix_fh\->print("\et0"); \& } \& } \& $matrix_fh\->print("\en"); \& } \&} .Ve .PP 1;