Plots an MA like plot GetData() outputs.

    :param df: dataframe output of GetData()
    :param title: plot title, 'Genes' or 'Transcripts'
    :param figName: /path/to/saved/figure/prefix
    :param c: pair of samples to be plotted in list format
    :param daType: data type, ie. 'counts' or 'FPKM'
    :param nbins: number of bins on normalized intensities to fit the splines
    :param per: log2(fold change) percentil to which the splines will be fitted
    :param deg: degress of freedom used to fit the splines
    :param eq: if true assumes for each bin that the lower and upper values are equally distant to 0, taking the smaller distance for both
    :param splines: plot splines, default=True
    :param spec: list of ids to be highlighted
    :param Targets: list of ids that will be highlighted if outside of the fitted splines
    :param ylim: a list of limits to apply on the y-axis of the plot
    :param sizeRed: size of the highlight marker

    :returns df_: a Pandas dataframe similar to the GetData() output with normalized intensities and spline outbounds rows marked as 1.
    :returns red: list of ids that are highlighted

def MA(df,title,figName,c, daType="counts",nbins=10,perc=.5,deg=3,eq=True,splines=True,spec=None,Targets=None,ylim=None,sizeRed=8):
    """
    Plots an MA like plot GetData() outputs.

    :param df: dataframe output of GetData()
    :param title: plot title, 'Genes' or 'Transcripts'
    :param figName: /path/to/saved/figure/prefix
    :param c: pair of samples to be plotted in list format
    :param daType: data type, ie. 'counts' or 'FPKM'
    :param nbins: number of bins on normalized intensities to fit the splines
    :param per: log2(fold change) percentil to which the splines will be fitted
    :param deg: degress of freedom used to fit the splines
    :param eq: if true assumes for each bin that the lower and upper values are equally distant to 0, taking the smaller distance for both
    :param splines: plot splines, default=True
    :param spec: list of ids to be highlighted
    :param Targets: list of ids that will be highlighted if outside of the fitted splines
    :param ylim: a list of limits to apply on the y-axis of the plot
    :param sizeRed: size of the highlight marker

    :returns df_: a Pandas dataframe similar to the GetData() output with normalized intensities and spline outbounds rows marked as 1.
    :returns red: list of ids that are highlighted
    """

    df_=df[df[c[0]]>0]
    df_=df_[df_[c[1]]>0]

    df_["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ]=df_.apply(NormInt, args=(c[0],c[1],), axis=1)

    if daType=="counts":
        lowLim=np.log10(np.sqrt(10))
    elif daType=="FPKM":
        lowLim=np.log10(0.1)

    df_b=df_[df_["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ]>lowLim ]
    df_b.reset_index(inplace=True, drop=True)

    Xdata=df_["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist()
    Ydata=df_["log2(%s/%s)" %( str(c[1]), str(c[0]) )].tolist()

    minX=min(Xdata)
    maxX=max(Xdata)

    minX_=min(df_b["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist())
    maxX_=max(df_b["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist())

    df_b["bin"]=pd.cut(df_b["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist(), nbins,labels=False)

    spl=[]
    for b in set( df_b["bin"].tolist() ):
        tmp=df_b[df_b["bin"]==b]
        Xbin = tmp["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist()
        Xval = np.mean([max(Xbin),min(Xbin)])
        Ybin = tmp["log2(%s/%s)" %( str(c[1]), str(c[0]) )].tolist()
        YvalP=np.percentile(Ybin,100.00-float(perc))
        YvalM=np.percentile(Ybin,float(perc))
        spl.append([Xval,YvalP,YvalM])

    spl=pd.DataFrame( spl,columns=["X","Upper","Lower"],index=range(len(spl)) )

    def CheckMin(df):
        U=abs(df["Upper"])
        L=abs(df["Lower"])
        return min([U,L])

    spl["min"]=spl.apply(CheckMin, axis=1)

    coeffsUpper = np.polyfit(spl["X"].tolist(), spl["Upper"].tolist(), deg)
    coeffsLower = np.polyfit(spl["X"].tolist(), spl["Lower"].tolist(), deg)

    Xspl = np.array(np.linspace(minX, maxX, 10*nbins))

    if eq:
        coeffsUpper = np.polyfit(spl["X"].tolist(), spl["min"].tolist(), deg)
        coeffsLower = np.polyfit(spl["X"].tolist(), [ ss*-1 for ss in spl["min"].tolist()] , deg)
        YsplUpper = np.polyval(coeffsUpper, Xspl)
        YsplLower = np.polyval(coeffsLower, Xspl)

    else:
        coeffsUpper = np.polyfit(spl["X"].tolist(), spl["Upper"].tolist(), deg)
        coeffsLower = np.polyfit(spl["X"].tolist(), spl["Lower"].tolist(), deg)
        YsplUpper = np.polyval(coeffsUpper, Xspl)
        YsplLower = np.polyval(coeffsLower, Xspl)

    def checkOutbounds(df,Xspl=Xspl,coeffsUpper=coeffsUpper,coeffsLower=coeffsLower,c=c):
        x=df["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) )]
        y=df["log2(%s/%s)" %( str(c[1]), str(c[0]) )]
        if y < 0:
            v=np.polyval(coeffsLower, x)
            if y < v:
                return 1
            else:
                return 0
        else:
            v=np.polyval(coeffsUpper, x)
            if y > v:
                return 1
            else:
                return 0

    df_["OutBounds"]=df_.apply(checkOutbounds,axis=1)

    if Targets:
        if title == "Transcripts":
            red=df_[df_["OutBounds"]==1][df_["transcript_id"].isin(Targets)]["transcript_id"].tolist()
            Xdata_=df_[df_["OutBounds"]==1][df_["transcript_id"].isin(Targets)]["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist()
            Ydata_=df_[df_["OutBounds"]==1][df_["transcript_id"].isin(Targets)]["log2(%s/%s)" %( str(c[1]), str(c[0]) ) ].tolist()
        elif title == "Genes":
            red=df_[df_["OutBounds"]==1][df_["gene_id"].isin(Targets)]["gene_id"].tolist()
            Xdata_=df_[df_["OutBounds"]==1][df_["gene_id"].isin(Targets)]["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) )].tolist()
            Ydata_=df_[df_["OutBounds"]==1][df_["gene_id"].isin(Targets)]["log2(%s/%s)" %( str(c[1]), str(c[0]) )].tolist()
    elif spec:
        if title == "Transcripts":
            red=df_[df_["transcript_id"].isin(spec)]["transcript_id"].tolist()
            Xdata_=df_[df_["transcript_id"].isin(spec)]["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist()
            Ydata_=df_[df_["transcript_id"].isin(spec)]["log2(%s/%s)" %( str(c[1]), str(c[0]) ) ].tolist()
        elif title == "Genes":
            red=df_[df_["gene_id"].isin(spec)]["gene_id"].tolist()
            Xdata_=df_[df_["gene_id"].isin(spec)]["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) )].tolist()
            Ydata_=df_[df_["gene_id"].isin(spec)]["log2(%s/%s)" %( str(c[1]), str(c[0]) )].tolist()
    else:
        Xdata_=df_[df_["OutBounds"]==1]["normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) ].tolist()
        Ydata_=df_[df_["OutBounds"]==1]["log2(%s/%s)" %( str(c[1]), str(c[0]) ) ].tolist()
        if title == "Transcripts":
            red=df_[df_["OutBounds"]==1]["transcript_id"].tolist()
        elif title == "Genes":
            red=df_[df_["OutBounds"]==1]["gene_id"].tolist()

    fig = plt.gcf()
    fig.set_size_inches(6, 6)
    plt.scatter(Xdata,Ydata, s=2)
    plt.scatter(Xdata_,Ydata_,s=sizeRed, c='r')
    if splines:
        plt.plot(Xspl,YsplUpper, "-",lw=0.5, c='g')
        plt.plot(Xspl,YsplLower,"-", lw=0.5,c='g')

    plt.xlabel("normalized intensities (%s vs. %s)" %( str(c[0]), str(c[1]) ) )
    plt.ylabel("log2(%s/%s)" %( str(c[1]), str(c[0]) ))

    if ylim:
        plt.ylim(ylim[0],ylim[1])
    else:
        ylims=max([abs(min(Ydata)), abs(max(Ydata)) ])
        plt.ylim(-ylims*1.1,ylims*1.1)

    plt.title(title)
    plt.savefig(figName+".png",dpi=300,bbox_inches='tight', pad_inches=0.1,format='png')
    plt.savefig(figName+".svg",dpi=300,bbox_inches='tight', pad_inches=0.1,format='svg')
    plt.show()

    return df_,red