@@ -36,8 +36,8 @@ def read_params():
3636 p .add_argument ('-p' , '--pangenome' , type = str ,
3737 help = 'Path to pangenome tsv file exported from ChocoPhlAn' )
3838 p .add_argument ('--i_covmat' , type = str , default = None ,
39- help = 'Path to precomputed coverage matrix' )
40-
39+ help = 'Path to precomputed coverage matrix' )
40+
4141 # OUTPUT ARGUMENTS
4242 p .add_argument ('--o_matrix' , type = str , default = None ,
4343 help = 'Path for presence/absence matrix output' )
@@ -68,17 +68,17 @@ def read_params():
6868 help = 'Minimum threshold (percentage) for genome length to add a reference genome to presence/absence matrix (default: 50).' )
6969
7070 # TRANSCRIPTOMICS ARGUMENTS
71- p .add_argument ('--i_rna' , metavar = 'INPUT_RNA_FOLDER' , type = str ,
71+ p .add_argument ('--i_rna' , metavar = 'INPUT_RNA_FOLDER' , type = str ,
7272 help = 'RNA-seq: input directory of RNA mapping results SAMPLE_RNA.csv.bz2' )
7373 p .add_argument ('--sample_pairs' , metavar = 'DNA_RNA_MAPPING' , type = str ,
7474 help = 'RNA-seq: list of DNA-RNA sequencing pairs from the same biological sample.' )
7575 p .add_argument ('--rna_max_zeros' , metavar = 'RNA_MAX_ZEROES' , type = float , default = 10.0 ,
7676 help = 'Max accepted percent of zero coveraged gene-families (default: <10 %%).' )
7777 p .add_argument ('--rna_norm_percentile' , metavar = 'RNA_NORM_PERCENTILE' , type = float , default = 50 ,
7878 help = 'Percentile for normalizing RNA/DNA ratios' )
79- p .add_argument ('--o_rna' , metavar = 'RNA_EXPRS_FILE' , type = str ,
79+ p .add_argument ('--o_rna' , metavar = 'RNA_EXPRS_FILE' , type = str ,
8080 help = 'Write normalized gene-family transcription values (RNA-seq).' )
81-
81+
8282
8383 # OPTIONAL ARGUMENTS
8484 p .add_argument ('--add_ref' , action = 'store_true' ,
@@ -336,7 +336,7 @@ def print_coverage_matrix(dna_samples_covs, out_channel, families, VERBOSE):
336336
337337def read_coverage_matrix (cov_matrix_file ):
338338 """Read coverage matrix (option --o_cov) for re-analysis using other thresholds"""
339-
339+
340340 sample2family2cov = defaultdict (dict )
341341
342342 if not os .path .exists (cov_matrix_file ):
@@ -499,7 +499,7 @@ def plot_dna_coverage(samples_coverages, sample_stats, genome_length, args, norm
499499 used_colors = [color ]
500500 else :
501501 used_colors .append (color )
502-
502+
503503 plt .xlabel ('Gene families' )
504504 for s in samples :
505505 covs = samples_coverages [s ].values () # also finc a way to extract covs from here
@@ -580,6 +580,8 @@ def get_genefamily_presence_absence(sample2family2dnaidx, sample_stats, avg_geno
580580 gene family in sample has DNA index 1 or -1 ==> present (1)
581581 gene family in sample has DNA index -2 or -3 ==> NOT present (0)
582582 """
583+ if len (sample2family2dnaidx ) == 0 :
584+ sys .exit ('[E] No sample passed the coverage threshold. Try more sensitive threhold or check that you are using both forward and reverse reads.' )
583585 sample2family2presence = defaultdict (dict )
584586 dna_samples = sorted (sample2family2dnaidx .keys ())
585587 # get keys (families names) from the sub dict.
@@ -701,8 +703,8 @@ def read_rna_coverage(input_rna, genes_info, verbose):
701703 rna_samples_covs [sample ] = get_genefamily_coverages (rna_samples_covs [sample ], genes_info , verbose )
702704 # dict of samples, for each sample : nested dict with familly and normalized coverage
703705 return rna_samples_covs
704-
705-
706+
707+
706708def read_samples_pairs (mapping_file ):
707709 dna2rna = dict ()
708710 if os .path .exists (mapping_file ):
@@ -738,12 +740,12 @@ def create_ratio_matrix(rna_samples_covs, dna_samples_covs, dna2rna, dna_accepte
738740
739741
740742def filter_normalize_rna_rate (sample2family2rna_div_dna , sample2family2dnaidx , families , args ):
741-
743+
742744 sample2family2median_norm = defaultdict (dict )
743745 sample2zeroes = defaultdict (tuple )
744746 sample2zeroes_ratio = defaultdict (float )
745747 median = defaultdict (float )
746-
748+
747749 # Percentile (default 50 = median) normalization
748750 # plateau_rna_div_dna = []
749751 for sample in sample2family2rna_div_dna .keys ():
@@ -754,7 +756,7 @@ def filter_normalize_rna_rate(sample2family2rna_div_dna, sample2family2dnaidx, f
754756 # print("{} : {}".format(f, sample2family2dnaidx[sample][f]))
755757 # if sample2family2dnaidx[sample][f] == 1:
756758 # plateau_rna_div_dna.append(sample2family2rna_div_dna[sample][f])
757- #
759+ #
758760 plateau_rna_div_dna = [sample2family2rna_div_dna [sample ][f ] for f in sample2family2rna_div_dna [sample ] if sample2family2dnaidx [sample ][f ] == 1 ]
759761 if len (plateau_rna_div_dna ) == 0 :
760762 continue
@@ -764,7 +766,7 @@ def filter_normalize_rna_rate(sample2family2rna_div_dna, sample2family2dnaidx, f
764766 for f in families :
765767 # If the family is in the plateau, calculate median normalized RNA/DNA value
766768 if sample2family2dnaidx [sample ][f ] == 1 :
767- if median [sample ] == 0 :
769+ if median [sample ] == 0 :
768770 sample2family2median_norm [sample ][f ] = 0.0
769771 else :
770772 sample2family2median_norm [sample ][f ] = sample2family2rna_div_dna [sample ][f ] / median [sample ]
@@ -780,7 +782,7 @@ def filter_normalize_rna_rate(sample2family2rna_div_dna, sample2family2dnaidx, f
780782 else :
781783 sample2family2median_norm [sample ][f ] = 'NaN'
782784 sample2zeroes_ratio [sample ] = float (sample2zeroes [sample ][0 ]) / sample2zeroes [sample ][1 ]
783-
785+
784786 print (sample2zeroes_ratio )
785787 # Reject samples with too many zeros
786788 rnaseq_accepted_samples = []
@@ -805,8 +807,8 @@ def filter_normalize_rna_rate(sample2family2rna_div_dna, sample2family2dnaidx, f
805807 sample2family2log_norm [sample ][f ] = 0.0 if v == 0.0 else (numpy .log2 (v ) / 10 ) + 1.0
806808
807809 return sample2family2log_norm
808-
809-
810+
811+
810812def write_rna_rate_matrix (sample2family2log_norm , output_path , families ):
811813 rnaseq_accepted_samples = sample2family2log_norm .keys ()
812814 if not output_path == '' :
@@ -854,10 +856,10 @@ def main():
854856 else :
855857 write_presence_absence_matrix (ref2family2presence , args , None )
856858 sys .exit (0 )
857-
858-
859+
860+
859861 if args .i_covmat == None :
860- # no shortcut
862+ # no shortcut
861863 print ('\n STEP 2. Create coverage matrix' )
862864 dna_samples_covs = read_map_results (args .i_dna , args .verbose )
863865 # Merge gene/transcript abundance into family (normalized) coverage
@@ -871,7 +873,7 @@ def main():
871873 # shortcut possible, precomputed coverage matrix available
872874 print ('\n STEP 2. Read provided coverage matrix' )
873875 dna_samples_covs = read_coverage_matrix (args .i_covmat )
874-
876+
875877
876878 print ('\n STEP 3: Strain presence/absence filter based on coverage plateau curve...' )
877879 avg_genome_length = adjust_genome_length (genome2families )
@@ -912,7 +914,7 @@ def main():
912914 # RNA SEQ
913915 if args .o_rna :
914916 print ('\n STEP 7: Meta-transcriptomics analysis : Gene family transcription rate' )
915- # read rna coverage
917+ # read rna coverage
916918 rna_samples_covs = read_rna_coverage (args .i_rna , genes_info , args .verbose )
917919 # check samples sample_pairs
918920 dna2rna = read_samples_pairs (args .sample_pairs )
0 commit comments