Exemplo n.º 1
0
 def _getTempChromosomeNames(galaxyTn):
     if isinstance(galaxyTn, basestring):
         galaxyTn = galaxyTn.split(":")
     tempinfofile = ExternalTrackManager.extractFnFromGalaxyTN(galaxyTn)
     #abbrv=GenomeImporter.getGenomeAbbrv(tempinfofile)
     #return os.linesep.join(GenomeInfo(abbrv).sourceChrNames)
     return os.linesep.join(GenomeImporter.getChromosomeNames(tempinfofile))
Exemplo n.º 2
0
    def execute(cls, choices, galaxyFn=None, username=''):
        '''Is called when execute-button is pushed by web-user.
        Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
        If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
        choices is a list of selections made by web-user in each options box.
        '''

        print 'Executing...'

        tempinfofile = ExternalTrackManager.extractFnFromGalaxyTN(
            choices[0].split(":"))
        abbrv = GenomeImporter.getGenomeAbbrv(tempinfofile)
        gi = GenomeInfo(abbrv)
        #chrNamesInFasta=gi.sourceChrNames
        chrNamesInFasta = cls._getTempChromosomeNames(choices[0]).split(
            os.linesep)

        chromNamesDict = {}
        chrDict = cls._getRenamedChrDictWithSelection(choices)

        for i, key in enumerate(chrDict.keys()):
            if chrDict[key]:
                chromNamesDict[chrNamesInFasta[i]] = key
        print 'All chromosomes chosen: ' + str(chromNamesDict)

        stdChrDict = cls._getRenamedChrDictWithSelection(choices, stdChrs=True)
        stdChrs = [x for x in stdChrDict if stdChrDict[x]]
        print 'Standard chromosomes chosen: ' + ", ".join(stdChrs)

        GenomeImporter.createGenome(abbrv,
                                    gi.fullName,
                                    chromNamesDict,
                                    stdChrs,
                                    username=username)

        gi.installedBy = username
        gi.timeOfInstallation = datetime.now()
        gi.store()
Exemplo n.º 3
0
    def execute(cls, choices, galaxyFn=None, username=''):
        '''Is called when execute-button is pushed by web-user.
        Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
        If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
        choices is a list of selections made by web-user in each options box.
        '''

        #print 'Executing... with choices %s'%str(choices)
        abbrv = choices[0]
        name = choices[1]

        #Should test that the genome is not in hyperbrowser.
        gi = GenomeInfo(abbrv)

        if gi.hasOrigFiles():
            sys.stderr.write(
                "Genome " + abbrv +
                " is already in the Genomic HyperBrowser. Remove the old first."
            )
        else:
            gi.fullName = name
            if choices[2] == 'URL':
                urls = choices[3].split()
                gi.sourceUrls = urls
                for url in urls:
                    try:
                        GenomeImporter.downloadGenomeSequence(abbrv, url)
                    except InvalidFormatError:
                        return
            else:
                basePath = GenomeImporter.getBasePathSequence(abbrv)
                fnSource = ExternalTrackManager.extractFnFromGalaxyTN(
                    choices[4].split(':'))
                fnDest = basePath + os.path.sep + abbrv + '.fa'
                ensurePathExists(fnDest)
                copyfile(fnSource, fnDest)

            if choices[16] == 'from URL':
                urls = choices[3].split()
                gi.sourceUrls = urls
                for url in urls:
                    try:
                        GenomeImporter.downloadGffFile(abbrv, url)
                    except InvalidFormatError:
                        return
            elif choices[16] == 'from history':
                fnSource = ExternalTrackManager.extractFnFromGalaxyTN(
                    choices[18].split(':'))
                fnDest = GenomeImporter.getCollectedPathGFF(abbrv)
                ensurePathExists(fnDest)
                copyfile(fnSource, fnDest)

            chrs = GenomeImporter.extractChromosomesFromGenome(abbrv)
            #gi.sourceChrNames = chrs
            gi.installedBy = username
            gi.genomeBuildSource = choices[5]
            gi.genomeBuildName = choices[6]
            gi.species = choices[7]
            gi.speciesTaxonomyUrl = choices[8]
            gi.assemblyDetails = choices[9]
            gi.privateAccessList = [
                v.strip()
                for v in choices[10].replace(os.linesep, ' ').replace(
                    ',', ' ').split(' ') if v.find('@') > 0
            ]
            gi.isPrivate = (choices[11] != 'All')
            gi.isExperimental = (choices[12] != 'All')
            gi.ucscClade = choices[13]
            gi.ucscGenome = choices[14]
            gi.ucscAssembly = choices[15]

            galaxyFile = open(galaxyFn, "w")
            galaxyFile.write('Genome abbreviation: ' + abbrv + os.linesep)
            galaxyFile.write('Genome full name: ' + name + os.linesep)
            galaxyFile.write('Track name: ' +
                             ':'.join(GenomeInfo.getSequenceTrackName(abbrv)) +
                             os.linesep)
            galaxyFile.write('Temp chromosome names: ' + ' || '.join(chrs) +
                             os.linesep)
            #GenomeImporter.saveTempInfo(abbrv, name, chrs)
            #print 'Chromosomes: '+chrs
            gi.store()
Exemplo n.º 4
0
    def validateAndReturnErrors(choices):
        '''
        Should validate the selected input parameters. If the parameters are not valid,
        an error text explaining the problem should be returned. The GUI then shows this text
        to the user (if not empty) and greys out the execute button (even if the text is empty).
        If all parameters are valid, the method should return None, which enables the execute button.
        '''
        if ' ' in choices[0]:
            return 'Genome short name should not contain spaces.'

        basePath = GenomeImporter.getBasePathSequence(choices[0])
        if os.path.exists(basePath):
            return "Genome sequence path already exists: %s. Rename genome or delete directory to proceed." \
                % basePath

        if any(c.strip() == '' for c in choices[0:2]):
            return "Genome abbreviation and name boxes must be filled."

        if choices[2] == 'URL':
            if choices[3].strip() == '':
                return "Sequence URL box must be filled."
        else:
            error = GeneralGuiTool._checkTrack(choices, trackChoiceIndex=4, genomeChoiceIndex=None, \
                                               filetype='FASTA', validateFirstLine=True)
            if error:
                return error

        # test if the URLs are alive
        if choices[2] == 'URL':
            urls = choices[3].strip().split()
            urlError = validateURLs(urls)
            if urlError:
                return urlError

        taxonomyUrl = choices[8].strip()
        if taxonomyUrl != '':
            urlError = validateURL(taxonomyUrl)
            if urlError:
                return urlError
        import re
        emails = [v for v in re.split('[ ,\n\t\r]+', choices[10])]
        for email in emails:
            if not ('@' in email and '.' in email):
                #pass
                #if len([v for v in choices[8].replace(os.linesep, ' ').replace(',', ' ').split(' ') if not v =='' and v.find('@')<0])>0:
                return 'There is an invalid format (%s) inside the E-mail address field' % email

        ucscError = validateUcscValues([choices[x] for x in [13, 14, 15]])
        if ucscError:
            return ucscError

        if choices[16] == 'from URL':
            if choices[17].strip() == '':
                return "Genome annotation URL box must be filled."
        elif choices[16] == 'from history':
            error = GeneralGuiTool._checkTrack(choices, trackChoiceIndex=18, genomeChoiceIndex=None, \
                                               filetype='FASTA', validateFirstLine=True)
            if error:
                return error

        # test if the URLs are alive
        if choices[16] == 'from URL':
            urls = choices[17].strip().split()
            urlError = validateURLs(urls)
            if urlError:
                return urlError