Exemplo n.º 1
0
def plottingAct(dataArray):
    creatingArrayOutput = creatingArray(dataArray)
    if creatingArrayOutput[0] == "graph":
            graphTypeInput,xArray,yArray,typeInput,valueInput1,valueInput2 = creatingArrayOutput
            maxx,minix = getMaxMin(xArray)
            maxy,miniy = getMaxMin(yArray)
            if typeInput == "BB":
                xLabel = "Group of bacteria 1"
                yLabel = "Group of bacteria 2"
            #typeInput == "BM"
            else:
                xLabel = "Group of bacteria"
                yLabel = "Metadatum"
            plotGraph(xArray,yArray,xLabel=xLabel,yLabel=yLabel,maxx=maxx+1,minx=minix-1,maxy=maxy+1,miny=miniy-1,title="Plotting of type " + typeInput + " with values " + str(valuesInput1[:3]) + "...  and " + str(valuesInput2[:3]) + "...")
    elif creatingArrayOutput[0] == "pie":
        graphTypeInput,result,nodesGroup,sampleNameList,metadataList = creatingArrayOutput
        plotPieChart(sampleNameList,result,"Assignments to the group of bacterias: " + str(nodesGroup) + " depending on samples")
    else:
        print "\n/!\ ERROR: [BUG] [actions/plottingAct] Unknown type of graph."
        raise ValueError
Exemplo n.º 2
0
def pearsonAct(dataArray):
    xNArray,yArray,typeInput,valueInput1,valueInput2 = creatingArray(dataArray,True)
    if typeInput == "BB":
        xArray = xNArray
        pearson = samplePearson(xArray,yArray)
    #typeInput = "BM"
    else:
        #xNArray is a list of list of (sampleID,number of assignments in this sample) pairs
        #We need thus to sum the numbers of assignments for a same value of the metadata
        xArray = []
        for ls in xNArray:
            s = 0
            for pair in ls:
                s += pair[1]
            xArray.append((ls[0][0],s))
        pearson = samplePearson(xArray,yArray)
    print "\nPearson coefficient is: " + str(pearson) + "\n"
    answer = raw_input("Save the results? Y/N\n")
    if (answer == "Y"):
        data = "The (" + typeInput + ") Pearson coefficient ****\nfor values: \n\n" + str([ x[1] for x in xArray]) + "\ncorresponding to " + str(valueInput1) + "\n\n and\n\n" + str([ y[1] for y in yArray ]) + "\ncorresponding to " + str(valueInput2) + "\n\n is : " + str(pearson) + "\n\nEND OF FILE ****"
        writeFile(data,"","text")
    elif not (answer == "N"):
        print "/!\ You should answer 'Y' or 'N'!"
    answer = raw_input("Plot the corresponding graph? Y/N\n")
    if (answer == "Y"):
        cleanedxArray = [ x[1] for x in xArray ]
        cleanedyArray = [ y[1] for y in yArray ]
        maxix,minix = getMaxMin(cleanedxArray)
        maxiy,miniy = getMaxMin(cleanedyArray)
        #It is more interesting to generate a histogram in these cases
        if len(cleanedxArray) < 4:
            plotHist(cleanedyArray,str(valueInput2[:3]) + "...",str(valueInput1[:3]) + "...",maxiy+1,miniy-1,maxix-1,minix+1,"Plotting (" + typeInput + ") Pearson coefficient and the graph of both sets of values")
        else:
            plotPearsonGraph(cleanedxArray,cleanedyArray,pearson,str(valueInput1[:3]) + "...",str(valueInput2[:3]) + "...",maxix+1,minix-1,maxiy+1,miniy-1,"Plotting (" + typeInput + ") Pearson coefficient and the graph of both sets of values")
    elif not (answer == "N"):
        print "/!\ You should answer 'Y' or 'N'!"