示例#1
0
def processBmrbNmrGridArchiveLink(urlLocation, saveDir, homeDir,
                                  finalFileName):

    data = getDataFromHttp(urlLocation)

    zipFileName = 'file.zip'
    zipFile = os.path.join(saveDir, zipFileName)
    zipOut = open(zipFile, 'w')
    zipOut.write(data)
    zipOut.close()

    os.chdir(saveDir)
    os.spawnlp(os.P_WAIT, 'nice', 'nice', '-19', 'unzip', zipFileName)
    os.chdir(homeDir)

    os.remove(zipFile)

    removeFiles = ['readme.html', 'main.css', 'index.csv']
    for removeFile in removeFiles:
        removeFilePath = os.path.join(saveDir, removeFile)
        if os.path.exists(removeFilePath):
            os.remove(removeFilePath)

    files = os.listdir(saveDir)

    for fileName in files:
        if fileName[:5] == 'block' and fileName[-4:] == '.str':
            os.rename(os.path.join(saveDir, fileName),
                      os.path.join(saveDir, finalFileName))
示例#2
0
def getBmrbNmrGridJointCoordinateFile(pdbCode, forceGet=False):
    """
  Get NMR restraints grid NMR-STAR file joined with coordinate info from mmCIF file
  """

    pdbDir = os.path.join(nmrGridDataDir, pdbCode)

    if not os.path.exists(pdbDir):
        os.mkdir(pdbDir)

    nmrStarFile = "joinedCoord.str.gz"

    if not os.path.exists(os.path.join(pdbDir, nmrStarFile)) or forceGet:

        origDir = os.getcwd()

        # Location zipped file
        urlLocation = "%s/%s/%s" % (bmrbJoinedCoordUrl, pdbCode, nmrStarFile)

        data = getDataFromHttp(urlLocation)

        localFile = os.path.join(pdbDir, nmrStarFile)
        localOut = open(localFile, 'w')
        localOut.write(data)
        localOut.close()

        Popen(['gunzip', '-f', localFile])

        os.chdir(origDir)

    return True
示例#3
0
def getCasdNmrProjects(saveDataDir=None, forceWrite=False):

    projectInfo = getCasdNmrProjectInfo()

    # Get the files

    if not saveDataDir:
        saveDataDir = casdNmrDataDir

    for (projectName, dataFile, pdbCodes) in projectInfo:

        if dataFile[0] == '/':
            dataUrl = os.path.join(eNmrUrl, dataFile[1:])
        else:
            dataUrl = dataFile

        (path, fileName) = os.path.split(dataFile)

        localDataFilePath = os.path.join(saveDataDir, fileName)

        if forceWrite or not os.path.exists(localDataFilePath):
            print "  Downloading CASD-NMR project %s..." % fileName

            dataLines = getDataFromHttp(dataUrl)

            if os.path.exists(localDataFilePath):
                os.remove(localDataFilePath)

            fout = open(localDataFilePath, 'w')
            fout.write(dataLines)
            fout.close()
示例#4
0
文件: Cing.py 项目: fenglb/ccpnmr2.4
    def updateFiles(self):

      self.getPickleFile("nrgCingPdbCodes")

      newNrgCingPdbCodes = getCingCcpnTgzFileList()

      pdbCodes = newNrgCingPdbCodes.keys()
      pdbCodes.sort()

      for pdbCode in pdbCodes:

        print pdbCode

        downloadTgz = False

        (date,pdbCodeDirectory,downloadUrl) = newNrgCingPdbCodes[pdbCode]

        if not self.nrgCingPdbCodes.has_key(pdbCode):
          downloadTgz = True

        elif self.nrgCingPdbCodes[pdbCode][0] != date:
          # Date change...
          print "  Date change on NRG-CING file for %s..." % (pdbCode)
          downloadTgz = True

        #
        # Create directories and check if file exists, also download if not (could be earlier script problem)
        #

        saveDir = os.path.join(self.archiveDir,pdbCodeDirectory)
        if not os.path.exists(saveDir):
          os.mkdir(saveDir)

        savePath = os.path.join(saveDir,"%s.tgz" % pdbCode)
        if not os.path.exists(savePath):
          downloadTgz = True

        #
        # Now download and update
        #

        if downloadTgz:

          print "  Downloading..."

          data = getDataFromHttp(downloadUrl)

          if os.path.exists(savePath):
            os.remove(savePath)

          fout = open(savePath,'w')
          fout.write(data)
          fout.close()

          # Update pickled information and save... bit slower this but safer
          self.nrgCingPdbCodes[pdbCode] = newNrgCingPdbCodes[pdbCode]
          self.createPickleFile("nrgCingPdbCodes")
示例#5
0
文件: Cing.py 项目: fenglb/ccpnmr2.4
    def cingProjectDownload(self, outputDir):

        #
        # Put in CCPN project as default. Always usea time-stamped directory name.
        #

        if not outputDir:
            outputDir = self.ccpnProject.findFirstRepository(
                name='userData').url.path
            outputDir = os.path.join(outputDir, 'cing',
                                     self.getFileTimeString())

        #
        # Make sure output dir exists
        #

        if not os.path.exists(outputDir):
            os.makedirs(outputDir)

        #
        # Get the CING project name - safer in case changed on server side
        #

        projectPage = self.cingRequest("ProjectName")

        pyDict = eval(projectPage)
        projectName = pyDict['Result']

        #
        # Now download the file - first wait a bit just in case
        #

        time.sleep(20)

        cingZipFile = "%s_CING_report.zip" % projectName
        cingZipFileHttp = os.path.join(self.cingDownload, self.userId,
                                       self.accessKey, cingZipFile)

        # Try to re-download if not found.
        outputData = None

        while (not outputData or outputData.count("Not Found")):

            time.sleep(20)
            outputData = getDataFromHttp(cingZipFileHttp)

        #
        # And write it out...
        #

        self.cingZipFileOut = joinPath(outputDir, cingZipFile)

        fout = open(self.cingZipFileOut, 'w')
        fout.write(outputData)
        fout.close()
示例#6
0
文件: Bmrb.py 项目: fenglb/ccpnmr2.4
def getBmrbEntry(bmrbId, skipCodes=None, forceGet=False):

    if skipCodes and bmrbId in skipCodes:
        return False

    bmrbFile = "%s.str" % bmrbId

    newBmrbFile = os.path.join(bmrbArchiveDataDir, bmrbFile)

    if not forceGet and os.path.exists(newBmrbFile):
        return True

    #
    # Download
    #

    print "Downloading %s..." % bmrbFile

    bmrbFileLink = '%s%s' % (bmrbArchiveUrlLocation, bmrbId)

    data = getDataFromHttp(bmrbFileLink)

    #
    # Exit if no data
    #

    if not data:
        print "  Download failed!"
        return False

    #
    # Write the new file
    #

    if not os.path.exists(bmrbArchiveDataDir):
        os.mkdir(bmrbArchiveDataDir)

    fout = open(os.path.join(newBmrbFile), 'w')
    fout.write(data)
    fout.close()

    return True
示例#7
0
def getBmrbNmrGridCompletenessInfo(pdbCode, forceWrite=False):
    """
  Read info on completeness check for.a PDB entry at the BMRB...
  """

    fileName = 'completeness.str'
    pdbDir = os.path.join(nmrGridDataDir, pdbCode)

    finalFileName = os.path.join(pdbDir, fileName)

    if forceWrite or not os.path.exists(finalFileName):
        finalFileName = None

    if not finalFileName:
        urlLocation = '%s?db_username=wattos1&format=distance&pdb_id=%s&request_type=block_set&subtype=completeness&type=check' % (
            nmrGridServletUrl, pdbCode)

        data = getDataFromHttp(urlLocation)
        dataLines = data.split("\n")

        for dataLine in dataLines:
            if mrArchiveLinkPatt.search(dataLine):
                mrLinkSearch = mrLinkPatt.search(dataLine)
                if mrLinkSearch:
                    archiveLink = "%s?%s" % (nmrGridServletUrl,
                                             mrLinkSearch.group(1))

                    if not os.path.exists(pdbDir):
                        os.mkdir(pdbDir)

                    processBmrbNmrGridArchiveLink(archiveLink, pdbDir,
                                                  nmrGridDataDir, fileName)

                    finalFileName = os.path.join(pdbDir, fileName)

                    break

                else:
                    print "  Error: no link for completeness data for %s!" % pdbCode

    return finalFileName