.\" 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::ClinicalCorrelation 3pm" .TH Genome::Model::Tools::Music::ClinicalCorrelation 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 Each file must include at least 1 sample_id column and 1 attribute column, with the format being [sample_id clinical_data_attribute_1 clinical_data_attribute_2 ...] .IP "\(bu" 4 The sample \s-1ID\s0 must match the sample \s-1ID\s0 listed in the \s-1MAF\s0 under \*(L"Tumor_Sample_Barcode\*(R" for relating the mutations of this sample. .PP Note the importance of the headers: the header for each clinical_data_attribute will appear in the output file to denote relationships with the mutation data from the \s-1MAF.\s0 .PP Internally, the input data is fed into an R script which calculates a P\-value representing the probability that the correlation seen between the mutations in each gene (or variant) and each phenotype trait are random. Lower P\-values indicate lower randomness, or likely true correlations. .PP The results are saved to the output filename given with a suffix appended; \*(L".numeric.csv\*(R" will be appended for results derived from numeric clinical data, and \*(L".categorical.csv\*(R" will be appended for results derived from categorical clinical data. Also, \*(L".glm.csv\*(R" will be appended to the output filename for \s-1GLM\s0 results. .PP The \s-1GLM\s0 analysis accepts a mixed numeric and categoric clinical data file, input using the parameter \-\-glm\-clinical\-data\-file. \s-1GLM\s0 clinical data must adhere to the formats described above for the correlation clinical data files. \s-1GLM\s0 also requires the user to input a \-\-glm\-model\-file. This file requires specific headers and defines the analysis to be performed rather exactly. Here are the conventions required for this file: .IP "\(bu" 4 Columns must be ordered as such: .IP "\(bu" 4 [ analysis_type clinical_data_trait_name variant/gene_name covariates memo ] .IP "\(bu" 4 The 'analysis_type' column must contain either \*(L"Q\*(R", indicating a quantative trait, or \*(L"B\*(R", indicating a binary trait will be examined. .IP "\(bu" 4 The 'clinical_data_trait_name' is the name of a clinical data trait defined by being a header in the \-\-glm\-clinical\-data\-file. .IP "\(bu" 4 The 'variant/gene_name' can either be the name of one or more columns from the \-\-glm\-clinical\-data\-file, or the name of one or more mutated gene names from the \s-1MAF,\s0 separated by \*(L"|\*(R". If this column is left blank, or instead contains \*(L"\s-1NA\*(R",\s0 then each column from either the variant mutation matrix (\-\-use\-maf\-in\-glm) or alternatively the \-\-glm\-clinical\-data\-file is used consecutively as the variant column in independent analyses. .IP "\(bu" 4 \&'covariates' are the names of one or more columns from the \-\-glm\-clinical\-data\-file, separated by \*(L"+\*(R". .IP "\(bu" 4 \&'memo' is any note deemed useful to the user. It will be printed in the output data file for reference. .PP \&\s-1GLM\s0 analysis may be performed using solely the data input into \-\-glm\-clinical\-data\-file, as described above, or alternatively, mutational data from the \s-1MAF\s0 may be included as variants in the \s-1GLM\s0 analysis, as also described above. Use the \-\-use\-maf\-in\-glm flag to include the mutation matrix derived from the maf as variant data. .PP Note that all input files for both correlation and \s-1GLM\s0 analysis 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. William Schierding, M.S. \&\s-1EOS\s0 } .PP sub execute { .PP .Vb 5 \& # parse input arguments \& my $self = shift; \& my $bam_list = $self\->bam_list; \& my $output_file = $self\->output_file; \& my $genetic_data_type = $self\->genetic_data_type; \& \& # 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; \& } \& my $glm_model = $self\->glm_model_file; \& \& # declarations \& my @all_sample_names; # names of all the samples, no matter if it\*(Aqs mutated or not \& \& # parse out the sample names from the bam\-list which should match the names in the MAF file \& 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 \& for my $datatype ( keys %clinical_data ) { \& \& my $test_method; \& my $full_output_filename; \& \& if( $datatype =~ /numeric/i ) { \& $full_output_filename = $output_file . ".numeric.csv"; \& $test_method = $self\->numerical_data_test_method; \& } \& \& if( $datatype =~ /categ/i ) { \& $full_output_filename = $output_file . ".categorical.csv"; \& $test_method = "fisher"; \& } \& \& if( $datatype =~ /glm/i ) { \& $full_output_filename = $output_file . ".glm.csv"; \& $test_method = "glm"; \& } \& \& #read through clinical data file to see which samples are represented and create input matrix for R \& my %samples; \& my $matrix_file; \& my $samples = \e%samples; \& my $clin_fh = new IO::File $clinical_data{$datatype},"r"; \& unless( $clin_fh ) { \& die "failed to open $clinical_data{$datatype} for reading: $!"; \& } \& my $header = $clin_fh\->getline; \& while( my $line = $clin_fh\->getline ) { \& chomp $line; \& my ( $sample ) = split( /\et/, $line ); \& $samples{$sample}++; \& } \& #create correlation matrix unless it\*(Aqs glm analysis without using a maf file \& unless(( $datatype =~ /glm/i && !$self\->use_maf_in_glm ) || $self\->input_clinical_correlation_matrix_file ) { \& \& if( $genetic_data_type =~ /^gene$/i ) { \& $matrix_file = $self\->create_sample_gene_matrix_gene( $samples, $clinical_data{$datatype}, @all_sample_names ); \& } \& elsif( $genetic_data_type =~ /^variant$/i ) { \& $matrix_file = $self\->create_sample_gene_matrix_variant( $samples, $clinical_data{$datatype}, @all_sample_names ); \& } \& else { \& $self\->error_message( "Please enter either \e"gene\e" or \e"variant\e" for the \-\-genetic\-data\-type parameter." ); \& return; \& } \& } \& \& if( $self\->input_clinical_correlation_matrix_file ) { \& $matrix_file = $self\->input_clinical_correlation_matrix_file; \& } \& \& unless( defined $matrix_file ) { $matrix_file = "\*(Aq*\*(Aq"; } \& \& #set up R command \& my $R_cmd = "R \-\-slave \-\-args < " . _\|_FILE_\|_ . ".R $test_method "; \& \& if( $datatype =~ /glm/i ) { \& $R_cmd .= "$glm_model $clinical_data{$datatype} $matrix_file $full_output_filename"; \& } \& else { \& $R_cmd .= "$clinical_data{$datatype} $matrix_file $full_output_filename"; \& } \& \& #run R command \& print "R_cmd:\en$R_cmd\en"; \& WIFEXITED( system $R_cmd ) or croak "Couldn\*(Aqt run: $R_cmd ($?)"; \& } \& \& return( 1 ); \&} .Ve .PP sub create_sample_gene_matrix_gene { .PP .Vb 2 \& my ( $self, $samples, $clinical_data_file, @all_sample_names ) = @_; \& my $output_matrix = $self\->clinical_correlation_matrix_file; \& \& #create a hash of mutations from the MAF file \& my ( %mutations, %all_genes, @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 if sample exists in clinical data \& unless( defined $samples\->{$sample} ) { \& warn "Sample Name: $sample from MAF file does not exist in Clinical Data File"; \& next; \& } \& \& # 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 \& @all_genes = sort keys %all_genes; \& \& #write the input matrix for R code to a file \& my $matrix_fh; \& unless (defined $output_matrix) { \& $output_matrix = Genome::Sys\->create_temp_file_path(); \& } \& $matrix_fh = new IO::File $output_matrix,"w"; \& unless ($matrix_fh) { \& die "Failed to create matrix file $output_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"); \& } \& \& return $output_matrix; \&} .Ve .PP sub create_sample_gene_matrix_variant { .PP .Vb 2 \& my ( $self, $samples, $clinical_data_file, @all_sample_names ) = @_; \& my $output_matrix = $self\->clinical_correlation_matrix_file; \& \& #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; \& } \& \& unless( exists $samples\->{$sample} ) { \& warn "Sample Name: $sample from MAF file does not exist in Clinical Data File"; \& next; \& } \& \& # 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; \& unless( defined $output_matrix ) { \& $output_matrix = Genome::Sys\->create_temp_file_path(); \& } \& $matrix_fh = new IO::File $output_matrix,"w"; \& unless( $matrix_fh ) { \& die "Failed to create matrix file $output_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"); \& } \& \& return $output_matrix; \&} .Ve .PP 1;