changeset 16:fa48ad87ae3e draft

Uploaded
author glogobyte
date Wed, 20 Oct 2021 08:43:37 +0000
parents 37aaa551e5fd
children 0cdc0c3c821e
files mirbase_graphs.py
diffstat 1 files changed, 30 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/mirbase_graphs.py	Wed Oct 13 16:16:12 2021 +0000
+++ b/mirbase_graphs.py	Wed Oct 20 08:43:37 2021 +0000
@@ -81,20 +81,20 @@
               t_tem_counts += x[2]
 
     fig = plt.figure(figsize=(7,5))
-    labels = 'miRNA RefSeq','Template', 'Unassigned','Non-template'
+    labels = 'miRNA RefSeq','template', 'unassigned','non-template'
     sizes = [c_mat_counts, c_tem_counts, c_unmap_counts,c_non_counts]
     colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
     ax1 = plt.subplot2grid((1,2),(0,0))
     patches, texts, autotexts=plt.pie(sizes, labels=labels, colors=colors, startangle=140,autopct='%1.1f%%',radius=0.8)
-    [x.set_fontsize(8) for x in texts]
-    plt.title(group_name1 + ' Group (reads)',fontsize=12)
+    [x.set_fontsize(10) for x in texts]
+    plt.title(group_name1.capitalize() + ' Group (reads)',fontsize=12)
     labels = 'miRNA RefSeq','Template', 'Unassigned','non-template'
     sizes = [t_mat_counts, t_tem_counts, t_unmap_counts, t_non_counts]
     colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
     ax2 = plt.subplot2grid((1,2),(0,1))
     patches, texts, autotexts=plt.pie(sizes, labels=labels, colors=colors, startangle=140,autopct='%1.1f%%',radius=0.8)
-    [x.set_fontsize(8) for x in texts]
-    plt.title(group_name2 + ' Group (reads)', fontsize=12)
+    [x.set_fontsize(10) for x in texts]
+    plt.title(group_name2.capitalize() + ' Group (reads)', fontsize=12)
     plt.savefig('pie_non.png',dpi=300)
 
 ######################################################################################################################################################
@@ -158,22 +158,22 @@
 
 
     fig = plt.figure()
-    labels = 'miRNA RefSeq','Template', 'Unassigned'
+    labels = 'miRNA RefSeq','template', 'unassigned'
     sizes = [c_mat_counts, c_tem_counts, c_unmap_counts]
     colors = ['gold', 'yellowgreen', 'lightskyblue']
     explode = (0.2, 0.05, 0.1)
     ax1 = plt.subplot2grid((1,2),(0,0))
     patches, texts, autotexts=plt.pie(sizes, labels=labels, colors=colors, startangle=140,autopct='%1.1f%%',radius=0.8)
-    [x.set_fontsize(8) for x in texts]
-    plt.title(group_name1 + ' group (reads)', fontsize=12)
+    [x.set_fontsize(10) for x in texts]
+    plt.title(group_name1.capitalize() + ' group (reads)', fontsize=12)
     labels = 'miRNA RefSeq','Template', 'Unassigned'
     sizes = [t_mat_counts, t_tem_counts, t_unmap_counts]
     colors = ['gold', 'yellowgreen', 'lightskyblue']
     explode = (0.2, 0.05, 0.1)
     ax2 = plt.subplot2grid((1,2),(0,1))
     patches, texts, autotexts=plt.pie(sizes, labels=labels, colors=colors, startangle=140,autopct='%1.1f%%',radius=0.8)
-    [x.set_fontsize(8) for x in texts]
-    plt.title(group_name2 + ' group (reads)',fontsize = 12)
+    [x.set_fontsize(10) for x in texts]
+    plt.title(group_name2.capitalize() + ' group (reads)',fontsize = 12)
     plt.savefig('pie_tem.png',dpi=300)
 
 ###################################################################################################################################################################################################################
@@ -301,20 +301,20 @@
   radar_max_counts = max(c_5_counts,c_3_counts,c_both_counts,c_mat_counts,c_exception_counts,t_5_counts,t_3_counts,t_both_counts,t_mat_counts,t_exception_counts)
 
   df=pd.DataFrame({
-  'group':[group_name1,group_name2],
+  'group':[group_name1.capitalize(),group_name2.capitalize()],
   """5'3'-isomiRs""":[c_both,t_both],
   """3'-isomiRs""":[c_3,t_3],
   'RefSeq miRNA':[c_mature,t_mature],
   """5'-isomiRs""":[c_5,t_5],
-  'Others*':[c_exception,t_exception]})
+  'others*':[c_exception,t_exception]})
 
   df1=pd.DataFrame({
-  'group':[group_name1,group_name2],
+  'group':[group_name1.capitalize(),group_name2.capitalize()],
   """5'3'-isomiRs""":[c_both_counts,t_both_counts],
   """3'-isomiRs""":[c_3_counts,t_3_counts],
   'RefSeq miRNA':[c_mat_counts,t_mat_counts],
   """5'-isomiRs""":[c_5_counts,t_5_counts],
-  'Others*':[c_exception_counts,t_exception_counts]})
+  'others*':[c_exception_counts,t_exception_counts]})
 
   spider_last(df,radar_max,1,group_name1,group_name2)
   spider_last(df1,radar_max_counts,2,group_name1,group_name2)
@@ -340,39 +340,39 @@
   ax.set_theta_direction(-1)
 
   # Draw one axe per variable + add labels labels yet
-  plt.xticks(angles[:-1], categories, fontsize=11)
+  plt.xticks(angles[:-1], categories, fontsize=13)
 
   # Draw ylabels
   radar_max=round(radar_max+radar_max*0.1)
   mul=len(str(radar_max))-1
   maxi=int(math.ceil(radar_max / pow(10,mul))) * pow(10,mul)
   sep = round(maxi/4)
-  plt.yticks([sep, 2*sep, 3*sep, 4*sep, 5*sep], [str(sep)+'%', str(2*sep)+'%', str(3*sep)+'%', str(4*sep)+'%', str(5*sep)+'%'], color="grey", size=10)
+  plt.yticks([sep, 2*sep, 3*sep, 4*sep, 5*sep], [str(sep)+'%', str(2*sep)+'%', str(3*sep)+'%', str(4*sep)+'%', str(5*sep)+'%'], color="grey", size=12)
   plt.ylim(0, maxi)
 
   # ------- PART 2: Add plots
 
   # Plot each individual = each line of the data
-  # I don't do a loop, because plotting more than 3 groups makes the chart unreadable
+  # I don't do a loop, because plotting more than 2 groups makes the chart unreadable
 
   # Ind1
   values=df.loc[0].drop('group').values.flatten().tolist()
   values += values[:1]
-  ax.plot(angles, values,'-o', linewidth=1, linestyle='solid', label=group_name1)
+  ax.plot(angles, values,'-o', linewidth=1, linestyle='solid', label=group_name1.capitalize())
   ax.fill(angles, values, 'b', alpha=0.1)
 
   # Ind2
   values=df.loc[1].drop('group').values.flatten().tolist()
   values += values[:1]
-  ax.plot(angles, values, '-o' ,linewidth=1, linestyle='solid', label=group_name2)
+  ax.plot(angles, values, '-o' ,linewidth=1, linestyle='solid', label=group_name2.capitalize())
   ax.fill(angles, values, 'r', alpha=0.1)
 
   # Add legend
   if flag==1:
-     plt.legend(loc='upper right', bbox_to_anchor=(0.0, 0.1))
+     plt.legend(loc='upper right', prop={'size': 11}, bbox_to_anchor=(0.0, 0.1))
      plt.savefig('spider_non_red.png',dpi=300)
   else:
-     plt.legend(loc='upper right', bbox_to_anchor=(0.0, 0.1))
+     plt.legend(loc='upper right', prop={'size': 11}, bbox_to_anchor=(0.0, 0.1))
      plt.savefig('spider_red.png',dpi=300)
 
 
@@ -386,9 +386,9 @@
     seq=[]
 
     if flag == "c":
-        title = "Length Distribution of "+ group_name +" group (Redudant reads)"
+        title = "Length distribution of "+ group_name.lower() +" group (redundant reads)"
     if flag == "t":
-        title = "Length Distribution of "+ group_name +" group (Redudant reads)"
+        title = "Length distribution of "+ group_name.lower() +" group (redundant reads)"
 
     # classification of the sequences on two categories mapped or unmapped
     for i in samples:
@@ -454,11 +454,11 @@
 def logo_seq_red(merge, flag, group_name):
 
     if flag=="c":
-       titlos= group_name + " group (Redundant)"
+       titlos= group_name + " group (redundant)"
        file_logo="c_logo.png"
        file_bar="c_bar.png"
     if flag=="t":
-       titlos= group_name + " group (Redundant)"
+       titlos= group_name + " group (redundant)"
        file_logo="t_logo.png"
        file_bar="t_bar.png"
 
@@ -559,7 +559,7 @@
   pdf.set_font('Arial', 'B', 20.0)
 
   # Page header
-  pdf.cell(pdf.w-0.5, 0.5, 'IsomiR Profile Report',align='C')
+  pdf.cell(pdf.w-0.5, 0.5, 'IsomiR profile report',align='C')
   pdf.ln(0.7)
   pdf.set_font('Arial','B', 16.0)
   pdf.cell(pdf.w-0.5, 0.5, 'sRNA length distribution',align='C')
@@ -574,10 +574,10 @@
   pdf.ln(0.3)
 
   pdf.cell(0.2)
-  pdf.cell(3.0, 0.0, "  Mapped and unmapped reads to custom precussor arm reference DB (5p and 3p arms) in "+group_name1)
+  pdf.cell(3.0, 0.0, "  Mapped and unmapped reads to custom precursor arm reference DB (5p and 3p arms) in "+group_name1.lower())
   pdf.ln(0.2)
   pdf.cell(0.2)
-  pdf.cell(3.0, 0.0, "  (left) and "+group_name2+" (right) groups")
+  pdf.cell(3.0, 0.0, "  (left) and "+group_name2.lower()+" (right) groups")
 
   pdf.ln(0.5)
   h1=FPDF.get_y(pdf)
@@ -595,12 +595,12 @@
      pdf.cell(3.0, 0.0, "  RefSeq miRNAs, templated isomiRs, non-templated isomiRs and unassigned sequences as percentage")
      pdf.ln(0.2)
      pdf.cell(0.2)
-     pdf.cell(3.0, 0.0, "  of total sRNA reads in "+group_name1+" (left) and "+group_name2+" (right) groups")
+     pdf.cell(3.0, 0.0, "  of total sRNA reads in "+group_name1.lower()+" (left) and "+group_name2.lower()+" (right) groups")
   else:
      pdf.cell(3.0, 0.0, "  RefSeq miRNAS, Templated isomiRs and unassigned sequences as percentage of total sRNA reads in")
      pdf.ln(0.2)
      pdf.cell(0.2)
-     pdf.cell(3.0, 0.0, "  "+group_name1+" (left) and "+group_name2 + " (right) groups")
+     pdf.cell(3.0, 0.0, "  "+group_name1.lower()+" (left) and "+group_name2.lower() + " (right) groups")
 
   pdf.add_page()
   pdf.set_font('Arial', 'B', 18.0)