Esempio n. 1
0
def main():

    #Get currentDirectory and filename
    originalFileName = "board2.txt"
    currentDirectory = os.path.dirname(os.path.realpath(__file__))
    fileName = os.path.join(currentDirectory,
                            "../test_boards/" + originalFileName)

    #2d Array of board, with None in empty places
    startingBoard = parseInputFile(fileName)

    board = Board(startingBoard)

    #Print the starting board
    print("Starting Board:")
    printBoard(startingBoard)

    #Run AC3 Algorithm
    print("Calling AC3 Algorithmn")
    resolvedBoard = AC3Functions.getAC3(board)
    print("AC3 Finished")
    if (resolvedBoard == None):
        print("Board Not solvable!")
        return None

    print()
    print()
    print("Calling backtracking")
    print()

    if (engine.lower() == "c"):
        FileFunctions.callBackTrackingInC(resolvedBoard.domainDict,
                                          originalFileName)
    else:
        BackTracking.backTrackHelper(board)
Esempio n. 2
0
def Boltzmann_Calc(constraintes, StructfileRepos, numberofsruct, MFESnbrstruct,
                   rna, Redondantestructure):
    Energy = defaultdict(aa)
    Boltzman = defaultdict(aa)
    ConditionalBoltzman = defaultdict(aa)
    ZBolzman = defaultdict(aa)

    for Condition in constraintes:
        FileStructure = StructfileRepos + '/' + Condition
        #print FileStructure,"ffftft"
        Energy[Condition] = ENERGY_VALUES_STRUCTURES(
            FileStructure, rna
        )  # list of energy values for the structures present in the Condition
    #print Energy,"llllllllllllllllllllll","done"
    for Condition in constraintes:
        #print MFESnbrstruct
        if Condition == "MFES":

            Boltzman[Condition] = [
                BoltzmannEnergy(Energy[Condition][i]) for i in range(2)
            ]
            #print "heehrh",Boltzman[Condition]
            #for i in range(MFESnbrstruct):
            #   print i, Boltzman[Condition][i]
            #print Boltzman[Condition],"mfe"
        else:
            listawithoutRedonddnace = []
            for i in range(numberofsruct):
                Boltzman[Condition][i] = BoltzmannEnergy(Energy[Condition][i])
                if Redondantestructure[Condition][
                        i] == 0:  # if the structure is not redundant
                    listawithoutRedonddnace.append(
                        BoltzmannEnergy(Energy[Condition][i]))

        #print Boltzman, "eeeeeeeeeeeeeeeeeeeeeeeeee"
        ZBolzman[Condition] = sum(
            listawithoutRedonddnace)  # Partition function

    #FF.PickleVariable(Boltzman, os.path.join(conf.PickledData, "Boltzman.pkl"))
    listall = []
    for Condition in constraintes[:-1]:  # to not count MFES
        lista = []
        for i in range(numberofsruct):
            if Redondantestructure[Condition][i] == 0:
                lista.append(
                    BoltzmannEnergy(Energy[Condition][i]) /
                    ZBolzman[Condition])
            else:
                lista.append(
                    0
                )  # to solve the problem of the number of structure variation
        listall += lista
        ConditionalBoltzman[Condition] = lista

    FF.PickleVariable(
        ConditionalBoltzman,
        os.path.join(conf.PickledData, "ConditionalBoltzman.pkl"))
    FF.PickleVariable(ZBolzman, os.path.join(conf.PickledData, "ZBolzman.pkl"))

    return Boltzman
Esempio n. 3
0
def DistanceStruct(StructFile, SVMlFile, numberofsruct, MFESnbrstruct,
                   constrainte):
    Redondantestructure = defaultdict(aa)
    MatDist = defaultdict(aa)
    Redondantestructure1 = []
    DicStruct = {}
    Dicnumberofsruct = {}

    for i in range(len(constrainte) - 1):
        Dicnumberofsruct[constrainte[i]] = numberofsruct
    Dicnumberofsruct[constrainte[len(constrainte) - 1]] = MFESnbrstruct

    nb, DicStruct = GetBasePairsFromStructFile(StructFile)

    for i in range(0, nb):
        for j in range(i + 1, nb):
            MatDist[i][j] = DistanceTwoBPlist(DicStruct[i], DicStruct[j])
            if MatDist[i][j] == 0:
                if j not in Redondantestructure1:
                    if j > numberofsruct * (len(constrainte) - 1):
                        Dicnumberofsruct[constrainte[len(constrainte) -
                                                     1]] -= 1
                    else:
                        Dicnumberofsruct[constrainte[int(j /
                                                         numberofsruct)]] -= 1
                    Redondantestructure1.append(j)

            MatDist[j][i] = MatDist[i][j]

    for elem in Redondantestructure1:
        if elem < numberofsruct * (len(constrainte) - 1):
            ConditionNumber = int((elem) / numberofsruct)
        else:
            ConditionNumber = len(constrainte) - 1
        StructureNumber = elem - ConditionNumber * numberofsruct
        Redondantestructure[constrainte[ConditionNumber]][StructureNumber] = 1

    # strore the distance matrix in the file SVMLFile
    o = open(os.path.join("output", SVMlFile), "w")
    for i in range(len(MatDist)):
        o.write("%i\t" % (i + 1))
        for j in range(len(MatDist)):
            if (i != j):
                o.write("%i:%.4f\t" % (j + 1, MatDist[i][j]))
        o.write("\n")
    o.close()

    if Redondantestructure != 0:
        print "Warning! redundant structures"
    FF.PickleVariable(MatDist, os.path.join(conf.PickledData,
                                            "dissmatrix.pkl"))
    FF.PickleVariable(
        Redondantestructure1,
        os.path.join(conf.PickledData, "Redondantestructures.pkl"))
    FF.PickleVariable(
        Redondantestructure,
        os.path.join(conf.PickledData, "Redondantestructures_Id.pkl"))
    FF.PickleVariable(Dicnumberofsruct,
                      os.path.join(conf.PickledData, "Dicnumberofsruct.pkl"))
    return 0
Esempio n. 4
0
def DistanceStruct(StructFile, SVMlFile, numberofsruct, constrainte):
    conf = loadConfig()
    Redondantestructure = defaultdict(aa)
    MatDist = defaultdict(aa)
    Redondantestructure1 = {}
    Dicnumberofsruct = {}

    for i in range(len(constrainte)):
        Dicnumberofsruct[constrainte[i]] = numberofsruct

    nb, DicStruct = GetBasePairsFromStructFile(StructFile)

    progress.StartTask("Dissimilarity Loop")
    for i in range(0, nb):
        for j in range(i + 1, nb):
            MatDist[i][j] = DistanceTwoStructs(DicStruct[i], DicStruct[j])
            MatDist[j][i] = MatDist[i][j]

            ####### Check for redundancy
            if MatDist[i][j] == 0:
                jconstraint = int(j / numberofsruct)
                if j not in Redondantestructure1 and int(
                        i / numberofsruct
                ) == jconstraint:  # To be sure that the redundant  structure belongs to the same probing condition
                    Dicnumberofsruct[constrainte[jconstraint]] -= 1
                    Redondantestructure1[j] = jconstraint
    progress.EndTask()

    progress.StartTask("Export dissimilarity matrix")
    for elem in Redondantestructure1:
        jconstraint = Redondantestructure1[elem]
        StructureNumber = elem - jconstraint * numberofsruct
        Redondantestructure[constrainte[jconstraint]][
            StructureNumber] = 1  # we mark redundant structures by value 1

    # store the distance matrix in the  SVMLFile
    SVMLFullPath = os.path.join(conf.OutputFolder, "tmp", SVMlFile)
    if os.path.isfile(SVMLFullPath):
        os.remove(SVMLFullPath)  # To clean the previous version
    o = open(SVMLFullPath, "w")
    for i in range(len(MatDist)):
        o.write("%i\t" % (i + 1))
        for j in range(len(MatDist)):
            if (i != j):
                o.write("%i:%.4f\t" % (j + 1, MatDist[i][j]))
        o.write("\n")
    o.close()
    progress.EndTask()

    progress.StartTask("Pickle all data")
    FF.PickleVariable(MatDist, "dissmatrix.pkl")
    FF.PickleVariable(list(Redondantestructure1.keys()),
                      "Redondantestructures.pkl")
    FF.PickleVariable(Redondantestructure, "Redondantestructures_Id.pkl")
    FF.PickleVariable(Dicnumberofsruct, "Dicnumberofsruct.pkl")
    progress.EndTask()
    return 0
Esempio n. 5
0
def StructSampling(Pathconstraints, InputAlignment, numberofsruct, Tmpr,
                   Extension, m, b):
    print InputAlignment
    dir = 'OutputSamples' + str(numberofsruct)
    FF.CreateFold(dir)

    for Path in Pathconstraints:
        for filename in FF.GetListFile(Path, Extension):
            print "filename", filename
            Input = Path + "/" + filename
            output = dir + '/' + os.path.splitext(filename)[0]
            #Command = 'RNAsubopt  -p ' + str(numberofsruct) + ' -s -T ' + str(Tmpr)+ ' --maxBPspan '+ str(3*444/2)
            Command = 'RNAsubopt  -p ' + str(numberofsruct) + ' -s -T ' + str(
                Tmpr)
            if Path == conf.PathConstrainteFile:
                Command += ' -C  --enforceConstraint'
            if Path == conf.PathConstrainteFileShape:
                ShapeFile = conf.PathConstrainteFileShape + "/" + os.path.splitext(
                    filename)[0] + 'Shape.txt'
                #Command += ' --shape ' + ShapeFile + ' shapeMethod=Z '+ 'shapeConversion= M' # by default the shapeMethod=D (Deigan et al 2009), where the method Z is from Zarringhalm et al 2012
                #Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm3.48b-1.35"' # DMS new param
                #Command += ' --shape ' + ShapeFile #" defaults
                #Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm3.4794b-1.1598"' # for CMCT
                #print Command
                Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm' + str(
                    m) + 'b' + str(b) + '"'
            subprocess.call(Command,
                            stdin=open(Input, 'r'),
                            stdout=open(output, 'wb'),
                            shell=True)
            #because the version 2.3 of rnaeval does not consider the rna, second line should be removed

            lines = []

            with open(output, 'r') as f:
                lines = f.readlines()

            with open(output, 'w') as f:
                f.writelines(lines[:1] + lines[2:])

    for filename in FF.GetListFile(InputAlignment, '.aln'):
        Input = InputAlignment + "/" + filename
        print InputAlignment, Input
        Output = 'Sample' + os.path.splitext(filename)[0]
        #For the sampling from MSA alifold
        Command = 'RNAalifold -r -d2 --noLP  --aln --stochBT ' + str(
            numberofsruct)
        subprocess.call(Command,
                        stdin=open(Input, 'r'),
                        stdout=open(Output, 'wb'),
                        shell=True)
        Adjust_structure(Output, dir, os.path.splitext(filename)[0])
    return dir
Esempio n. 6
0
def run_functions(c_loc, m_loc, f_loc):
    # reads the file and creates the desired matrices based on the parameters given
    matrix = FileFunctions.read_covariance_matrix(c_loc)
    model = FileFunctions.read_model(m_loc)
    fiducial = FileFunctions.read_fiducial(f_loc)

    matrices = []
    for m in model:
        temp = Matrix(m[0], m[1], matrix, fiducial)
        temp.print_covariance_matrix()
        temp.print_fisher_matrix()
        matrices.append(temp)

    return matrices
Esempio n. 7
0
 def test_getSoftwareListWithFilesAndFolders(self):
     vCorrectSWList = ["800-A0443_SBB_ANTENNA_ON_AIR_FTP", "800-A0575_LGA-5005_Main_Assy_NF_Functional_Test_Script", "800-A0582_SCM_HASS_Test_Script"]
     # vSourceDirectory = "D:\\Projects\\Xerox Copier\\TestFolders\\MixedFileFolders"
     vSourceDirectory = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\TestFolders\\MixedFileFolders"
     vSWList = FileFunctions.GetSoftwareList(vSourceDirectory)
     for i in range(len(vSWList) ):
         self.assertEqual(vSWList[i].PartNumber, vCorrectSWList[i], "The list should have 3 elements")
Esempio n. 8
0
    def test_GetFormattedSoftwareListFileNotFound(self):
        # Create list of SoftwareItem objects
        vSWItemList = []
        vSWItem = FileFunctions.SoftwareItem("MissingFile")
        vSWItemList.append(vSWItem)

        vExpectedResult = []
        vPcName = "CPT1-EUD-D00191"
        
        # Mock method for IsOnline
        FileFunctions.IsOnline = MagicMock(return_value=0)
        # Mock method for CheckFile
        FileFunctions.CheckFile = MagicMock(return_value=False)

        vActualResult = FileFunctions.GetFormattedSoftwareList(vPcName, vSWItemList)
        self.assertCountEqual(vActualResult, vExpectedResult, "The Lists are not the same.")
Esempio n. 9
0
    def test_GetFormattedSoftwareListWithNoPcName(self):
        # Create list of SoftwareItem objects
        vSWItemList = []
        vSWItem = FileFunctions.SoftwareItem("800-A0443_SBB_ANTENNA_ON_AIR_FTP")
        vSWItemList.append(vSWItem)
        # vSWItem = FileFunctions.SoftwareItem("800-A0582_SCM_HASS_Test_Script")
        # vSWItemList.append(vSWItem)

        vExpectedResult = []
        vPcName = ""
        
        # Mock method for IsOnline
        FileFunctions.IsOnline = MagicMock(return_value=3)

        vActualResult = FileFunctions.GetFormattedSoftwareList(vPcName, vSWItemList)
        self.assertCountEqual(vActualResult, vExpectedResult, "The Lists are not the same.")
Esempio n. 10
0
 def make(self, argument=None):
     """Performs a make on the application. The unix exit code is 
        returned. Any arguments given are passed onto as in
        dv.make('clean').
     """
     import FileFunctions
     return FileFunctions.make(self, argument)
Esempio n. 11
0
def drawStructure(Sequence, Shapefile, outfile):
    lines = ""
    f = FF.Parsefile(Shapefile)
    lines = ";".join(
        ["%.3f" % float(line.strip().split('\t')[1]) for line in f])
    cmd = 'java -cp VARNAv3-93.jar fr.orsay.lri.varna.applications.VARNAcmd -i ' + Sequence + ' -colorMap ' + '"' + lines + '"' + ' -colorMapStyle ' + '"-5.00:#4747B6,0.00:#4747FF,0.40:#1CFF47,0.70:#FF4747,2.41:#FFFF00"' + ' -algorithm line -o ' + outfile + " > /dev/null"
    os.system(cmd)
Esempio n. 12
0
def Adjust_structure(File, directory, IndexRna):
    rnaaligned = FF.Parsefile(File)[0]
    listdeletion = [i for i, j in enumerate(rnaaligned) if j == '_']
    lines = FF.Parsefile(File)
    #SeqLen=len(lines[1])-1
    #print SeqLen,"seq length"
    fileout = os.path.join(directory, IndexRna + 'MSA')
    o = open(fileout, "w")
    o.write('>' + IndexRna + 'MSA\n')
    for struct in lines[2:-2]:
        struc = list(struct)
        for k in listdeletion:
            #print struct
            struc[k] = ""
        o.write('%s' % ("".join(struc)))
    o.close()
Esempio n. 13
0
 def make(self, argument=None):
     """Performs a make on the application. The unix exit code is 
        returned. Any arguments given are passed onto as in
        dv.make('clean').
     """
     import FileFunctions
     return FileFunctions.make(self, argument)
Esempio n. 14
0
 def test_GetFilePathListWithEmptyPath(self):
     vExpectResult = []
     vFile = "Data"
     vPcName = ""
     vPath = ""
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertCountEqual(vActualResult, vExpectResult, "The expected list should be empty.")
Esempio n. 15
0
    def test_GetFormattedSoftwareListWithEmptySoftwareList(self):
        # Create list of SoftwareItem objects
        vSWItemList = []

        vExpectedResult = []
        vPcName = ""
        vActualResult = FileFunctions.GetFormattedSoftwareList(vPcName, vSWItemList)
        self.assertCountEqual(vActualResult, vExpectedResult)
Esempio n. 16
0
 def test_GetFilePathListWithMissingNestedFile(self):
     vExpectResult = []
     vFile = "800-A0580_SCM_Functional_Test_Script.ini"
     vPcName = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover"
     vPath = "\\Production\\800-A0582_SCM_HASS_Test_Script"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertCountEqual(vActualResult, vExpectResult, "The expected list should be empty.")
Esempio n. 17
0
 def test_GetFilePathListWithIncorrectPath(self):
     vExpectResult = []
     vFile = "Data"
     vPcName = ""
     vPath = "\\Production\\800-A0582_SCM_HASS_Test_Script\\"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertCountEqual(vActualResult, vExpectResult, "The expected list should be empty.")
Esempio n. 18
0
 def test_GetFilePathListWithMissingFile(self):
     vExpectResult = []
     vFile = "800-A0580_SCM_Functional_Test_Script.ini"
     vPath = "\\Production\\800-A0443_SBB_ANTENNA_ON_AIR_FTP\\"
     vPcName = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertEqual(vActualResult, vExpectResult, "The expected result was False. The file should not be found.")
Esempio n. 19
0
 def test_GetFilePathListWithMissingDir(self):
     vExpectResult = []
     vFile = "Tools"
     vPcName = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover"
     vPath = "\\Production\\800-A0443_SBB_ANTENNA_ON_AIR_FTP"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertEqual(vActualResult, vExpectResult, "The expected result was False. The Directory should not be found.")
Esempio n. 20
0
def FromStructFiletoRNAEvalInput(StructFile, InputRNAeval, rna):
    lines = FF.Parsefile(StructFile)
    o = open(
        InputRNAeval, "w"
    )  # geneate intermediate file with sequence+strcuture , seq+strcture .... as the input format  to use RNAeval
    # print "sdfqspkojr",len(lines)
    for i in range(1, len(lines)):
        o.write("%s%s\t" % (rna, lines[i]))
    o.close()
Esempio n. 21
0
def Boltzmann_Calc(constraintes, StructfileRepository, NumStructures, rna,
                   Redondantestructure):
    Energy = defaultdict(aa)
    Boltzman = defaultdict(aa)
    ConditionalBoltzman = defaultdict(aa)
    ZBolzman = defaultdict(aa)
    # Calculate structure energies in each condition sample
    for Condition in constraintes:
        FileStructure = os.path.join(StructfileRepository, Condition)
        Energy[Condition] = EvalStructuresEnergies(
            FileStructure, rna
        )  # list of energy values for the structures present in the Condition

    for Condition in constraintes:
        ListwithoutRedundnacy = []
        for i in range(NumStructures):
            Boltzman[Condition][i] = BoltzmannFactor(Energy[Condition][i])
            if Redondantestructure[Condition][
                    i] == 0:  # if the structure is not redundant
                ListwithoutRedundnacy.append(Boltzman[Condition][i])

        # Calculate the normalization term as the sum over all Boltzmann probabilities for one copy of each structure
        ZBolzman[Condition] = sum(ListwithoutRedundnacy)  # Partition function

    # FF.PickleVariable(Boltzman, "Boltzman.pkl")
    listall = []
    for Condition in constraintes:  # to not count MFES
        lista = []
        for i in range(NumStructures):
            if Redondantestructure[Condition][
                    i] == 0:  # a non redundnat structure
                lista.append(Boltzman[Condition][i] / ZBolzman[Condition])
            else:
                lista.append(
                    0.
                )  # Redundant structures have a conditional Boltzmann value NULL
        listall += lista
        ConditionalBoltzman[Condition] = lista
        # print "Condition \t  ConditionalBoltzman", Condition, ConditionalBoltzman[Condition]
    FF.PickleVariable(Boltzman, "Boltzman.pkl")
    FF.PickleVariable(ConditionalBoltzman, "ConditionalBoltzman.pkl")
    FF.PickleVariable(ZBolzman, "ZBolzman.pkl")

    return ConditionalBoltzman
Esempio n. 22
0
 def test_GetFilePathListWithValidPcNameAndDir(self):
     vExpectResult = [
         "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\Production\\800-A0443_SBB_ANTENNA_ON_AIR_FTP\\Data"
         ]
     vFile = "Data"
     vPcName = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover"
     vPath = "\\Production\\800-A0443_SBB_ANTENNA_ON_AIR_FTP"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertEqual(vActualResult, vExpectResult, "The expected result was True.")
Esempio n. 23
0
def Writeproba(dir, Matrixproba, constraintes, rna):
    FF.CreateFold(Matrixproba)
    for file in constraintes:
        PSPath = dir + "/" + file + "_dp.ps"
        bpm = loadDotPlotPS(PSPath, "RNAfold")
        dp = DotPlot(rna, bpm)
        with open(Matrixproba + file.split('.')[0] + ".proba", "w") as o:
            for (i, j) in bpm.keys():
                o.write("%i\t%i\t%.6f\n" % (i, j, bpm[(i, j)]))
        o.close()
Esempio n. 24
0
def EnergyValuesFromStructure(StructFile, rna):
    Energy = []
    # generate the rnaeval input file
    FromStructFiletoRNAEvalInput(StructFile, "InputRNAeval", rna)
    # launch the RNaeval command
    os.system('RNAeval <' + "InputRNAeval" + '>' + "energyvalues")
    # Parse the RNAevaloutput to extract energy values
    lines = FF.Parsefile("energyvalues")
    for i in xrange(1, len(lines), 2):
        Energy.append(lines[i].split(" ")[1][1:-2])
    return Energy
Esempio n. 25
0
def GetBasePairsFromStructFile(
        faPath):  #return dic={structure:[liste de pairs de base ],....}
    #print faPath
    DicStruct = {}
    lines = FF.Parsefile(faPath)
    #print lines
    SeqLen = len(lines[1]) - 1
    #print SeqLen,"seq length"
    for j in range(len(lines)):
        DicStruct[j] = ListBasePairsFromStruct(lines[j].strip().split(' ')[0])
    return len(lines), DicStruct
Esempio n. 26
0
def drawStructure(Sequence, Structure, Shapefile, OutFile):
    conf = CF.loadConfig()
    cmopt = ""
    #print "shape",Shapefile
    if os.path.isfile(Shapefile):
        vals = FF.parseReactivityfile(Shapefile)
        cmopt = ' -colorMap "' + ";".join(["%.3f" % float(v) for v in vals]) + '"' + COLOR_MAP
    dummyout = os.path.join(conf.OutputFolder, "tmp", "varnamsg.txt")
    cmd = 'java -cp VARNAv3-93.jar fr.orsay.lri.varna.applications.VARNAcmd  -bpStyle simple -sequenceDBN "%s" -structureDBN "%s" '%(Sequence, Structure) + cmopt + ' -algorithm line -o ' + OutFile
    #print cmd
    subprocess.call(cmd, stdin=None, stdout=open(dummyout, 'wb'),
                    stderr=open(dummyout, 'w'), shell=True)
Esempio n. 27
0
def StructSampling(Pathconstraints, numberofsruct, Tmpr, Extension):
    dir = 'OutputSamples' + str(numberofsruct)
    FF.CreateFold(dir)
    for Path in Pathconstraints:
        for filename in FF.GetListFile(Path, Extension):
            Input = Path + "/" + filename
            output = dir + '/' + os.path.splitext(filename)[0]
            Command = 'RNAsubopt --noLP -p ' + str(
                numberofsruct) + ' -s -T ' + str(Tmpr)
            if Path == conf.PathConstrainteFile:
                Command += ' -C'
            if Path == conf.PathConstrainteFileShape:
                ShapeFile = conf.PathConstrainteFileShape + "/" + os.path.splitext(
                    filename)[0] + 'Shape.txt'
                Command += ' --shape ' + ShapeFile
            subprocess.call(Command,
                            stdin=open(Input, 'r'),
                            stdout=open(output, 'wb'),
                            shell=True)

    return dir
Esempio n. 28
0
def BasePairsbyCluster(clusters, Structurefile, Boltzmann, numberofsruct,
                       constrainte, cutoff):
    ListBPbyCluster = defaultdict()
    ListBPbyStruct = defaultdict(lambda: defaultdict())
    Zcluster = defaultdict(lambda: defaultdict())
    BoltzmannOverPairsbyCluster = defaultdict(
        lambda: defaultdict(lambda: defaultdict(lambda: 0)))
    Fiftypercent = defaultdict()
    for ClusterNumber in clusters:
        liste = []
        for structure in clusters[ClusterNumber]:
            #print structure, 'clusters[ClusterNumber]',clusters[ClusterNumber]
            ConditionNumber = int((structure - 1) / numberofsruct)
            StructureNumber = (structure - 1) - ConditionNumber * numberofsruct
            #print 'ConditionNumber', ConditionNumber,'StructureNumber',StructureNumber, Boltzmann[constrainte[ConditionNumber]][StructureNumber]

            if (Boltzmann[constrainte[ConditionNumber]][StructureNumber] != 0):
                liste.append(
                    Boltzmann[constrainte[ConditionNumber]][StructureNumber])
        print "LILSALISALISA", ClusterNumber, liste
        Zcluster[ClusterNumber] = sum(liste)

        list1 = []
        for structure in clusters[ClusterNumber]:

            ConditionNumber = int((structure - 1) / numberofsruct)
            StructureNumber = (structure - 1) - ConditionNumber * numberofsruct
            for (i, j) in SF.ListBasePairsFromStruct(
                    FF.GetlinefromFile(Structurefile, structure - 1)):
                BoltzmannOverPairsbyCluster[ClusterNumber][i][j] += Boltzmann[
                    constrainte[ConditionNumber]][StructureNumber] / Zcluster[
                        ClusterNumber]

            ListBPbyStruct[ClusterNumber][
                structure] = SF.ListBasePairsFromStruct(
                    FF.GetlinefromFile(Structurefile, structure - 1))

        ListBPbyCluster[ClusterNumber] = list1
        Fiftypercent[ClusterNumber] = len(clusters) / 2
    return ListBPbyStruct, ListBPbyCluster, Fiftypercent, BoltzmannOverPairsbyCluster
Esempio n. 29
0
 def test_GetFilePathListWithValidNestedFile(self):
     vExpectResult = [
         "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\Production\\800-A0582_SCM_HASS_Test_Script\\SCM_1\\800-A0582_SCM_HASS_Test_Script.ini",
         "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\Production\\800-A0582_SCM_HASS_Test_Script\\SCM_2\\800-A0582_SCM_HASS_Test_Script.ini",
         "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\Production\\800-A0582_SCM_HASS_Test_Script\\SCM_3\\800-A0582_SCM_HASS_Test_Script.ini",
         "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover\\Production\\800-A0582_SCM_HASS_Test_Script\\SCM_4\\800-A0582_SCM_HASS_Test_Script.ini"
         ]
     vFile = "800-A0582_SCM_HASS_Test_Script.ini"
     vPcName = "c:\\Projects\\Software\\Non-Framework\\Applications\\ProductionChangeover"
     vPath = "\\Production\\800-A0582_SCM_HASS_Test_Script"
     vActualResult = []
     FileFunctions.GetFilePathList(vFile, vPcName + vPath, vActualResult)
     self.assertCountEqual(vActualResult, vExpectResult, "The expected list should have 4 items.")
Esempio n. 30
0
def DotplotRnaFold(dir, PathConstrainteFile, PathConstrainteFileShape):
    FF.CreateFold(dir)
    for filename in FF.GetListFile(PathConstrainteFile, '.fa'):
        name = os.path.splitext(filename)[0]
        Input = PathConstrainteFile + "/" + filename
        output = dir + '/' + name
        #print "command is", 'RNAfold -p -d2  -C --enforceConstraint <'+Input+  '>'+ output
        os.system('RNAfold --noLP -p -d2  -C --enforceConstraint <' + Input +
                  '>' + output)
        #Sp.call("RNAfold -p -d2  -C ", stdin=Input, stdout=output, shell=True)
        # redirect files to the specific folder dir
        shutil.move(name + '_dp.ps', dir + "/" + name + '_dp.ps')
        shutil.move(name + '_ss.ps', dir + "/" + name + '_ss.ps')
    for filename in FF.GetListFile(PathConstrainteFileShape, '.fa'):
        name = os.path.splitext(filename)[0]
        Input = PathConstrainteFileShape + "/" + filename
        ShapeFile = PathConstrainteFileShape + "/" + name + 'Shape.txt'
        output = dir + '/' + name
        os.system('RNAfold -p -d2  -C ' + '<' + Input + ' --shape ' +
                  ShapeFile + '>' + output)
        shutil.move(name + '_dp.ps', dir + "/" + name + '_dp.ps')
        shutil.move(name + '_ss.ps', dir + "/" + name + '_ss.ps')
Esempio n. 31
0
def CentroidBycluster(clusters, StructFile, Boltzmann, numberofsruct, constrainte, rna):
    progress.StartTask("Computing centroids")
    dim_clustering = len(clusters)
    E = defaultdict()
    mycentroid = defaultdict()
    Intradistance = []
    centroids = defaultdict(lambda: defaultdict())
    Myproba = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: 0)))

    ListStructures = [SF.BasePairsFromStruct(Struct) for Struct in FF.Parsefile(StructFile)]

    progress.StartTask("Gathering base pairs")
    ListBPbystructure, ListBP, Myproba, Boltzmancluster = BasePairsbyCluster(clusters, ListStructures, Boltzmann,
                                                                             numberofsruct,
                                                                             constrainte)
    # Eliminate cluster reporting one structure
    ListDiameters, Listeliminated_clusers = ClustersDiameter(clusters, ListBPbystructure)
    for elem in Listeliminated_clusers:
        del clusters[elem]
    progress.EndTask()

    progress.StartTask("Computing cluster distance distribution")
    E = ClustersDistances(clusters, Boltzmann, ListBPbystructure, numberofsruct, constrainte)
    progress.EndTask()
    progress.StartTask("Computing MEA centroids")
    for ClusterNumber in clusters:
        mycentroid[ClusterNumber], centroids[ClusterNumber] = MEA(Myproba[ClusterNumber], rna)
    progress.EndTask()

    MatriceDistanceCentroids = scipy.zeros([dim_clustering, dim_clustering])
    MatriceDistanceClustersEucld = scipy.zeros([dim_clustering, dim_clustering])
    for ClusterNumber in clusters.keys():
        for ClusterNumber2 in clusters.keys():
            if ClusterNumber2 > ClusterNumber:
                l = SF.DistanceTwoStructs(centroids[ClusterNumber], centroids[ClusterNumber2])
                #print "BP_centoid_distances", "\t", ClusterNumber, "\t", ClusterNumber2, "\t", l
                Intradistance.append(l)
                # print "distance between clusters comparing the centroide's distances",l
                MatriceDistanceCentroids[ClusterNumber][ClusterNumber2] = l
                MatriceDistanceCentroids[ClusterNumber2][ClusterNumber] = l
                # print "distance between clusters comparing the means distances", ClusterNumber, ClusterNumber2, np.abs(E[ClusterNumber]-E[ClusterNumber2]),np.sqrt(abs(pow(E[ClusterNumber],2)-pow(E[ClusterNumber2],2)))
                # print E
                l = np.sqrt(abs(pow(E[ClusterNumber], 2) - pow(E[ClusterNumber2], 2)))
                MatriceDistanceClustersEucld[ClusterNumber][ClusterNumber2] = l
                MatriceDistanceClustersEucld[ClusterNumber2][ClusterNumber] = l
            # print "distance between clusters compring the centroide's distances", ClusterNumber, ClusterNumber2, DistanceTwoBPlist(ListBPbystrcut[ClusterNumber][listCentroidStructure[ClusterNumber][0]],ListBPbystrcut[ClusterNumber2][listCentroidStructure[ClusterNumber2][0]])
    # VT.plotDistanceClusters(MatriceDistanceCentroids, clusters, "blue", " Base pair distance between centroids")
    # VT.plotDistanceClusters(MatriceDistanceClustersEucld, clusters, "red", "Eucledian distance between structures")
    #print "BZ_distance_btw_clusters", "\t", E
    progress.EndTask()
    return mycentroid, Boltzmancluster, E, MatriceDistanceCentroids, ListDiameters, Intradistance
Esempio n. 32
0
 def getpack(self, options=''):
     """Performs a getpack on the package given within the environment
        of the application. The unix exit code is returned
     """
     import FileFunctions
     return FileFunctions.getpack(self, options)