def prepInputs(self):
        '''parses out input MDS file into the 1 to 3 SWD files that Maxent requires.
        '''
        
        #Create the outputs in our outputdirectory
        self.testCSV = os.path.join(self.outputDir, 'testSamples.csv')
        self.trainingCSV = os.path.join(self.outputDir, 'trainingSamples.csv')
        self.backgroundCSV = os.path.join(self.outputDir, 'backgroundPoints.csv')
        
        testWriter = csv.writer(open(self.testCSV, 'wb'))
        trainingWriter = csv.writer(open(self.trainingCSV, 'wb'))
        backgroundWriter = csv.writer(open(self.backgroundCSV, 'wb'))
        
        #Read through the MDS and pull the headers
        MDSreader = csv.reader(open(self.inputMDS, 'r'))
        header1 = MDSreader.next()
        header2 = MDSreader.next()
        header3 = MDSreader.next()
        
        self.pullCategoricals(header1)

        #The split column indicates that this file has been run through the 
        #test training split and testing data should be writen to the test file.
        splitcol = None
        try:
            splitcol = header1.index('Split')
            deleteTest = False
        except __HOLE__:
            self.writetolog("    The supplied MDS does not have a 'Split' column defaulting to having Maxent apply test/training split.")        
            deleteTest = True
            
        covariateIndexes = self.usedIndexes(header1, header2)        
        covariateNames = self.usedValues(header1, covariateIndexes)
        covariateNamesClean = [name.replace('_categorical', '') for name in covariateNames]
        usedCovariateFiles = self.usedValues(header3, covariateIndexes)
        
        self.writetolog('    Used covariates:' +  ", ".join(covariateNames), False, False)
             
        testWriter.writerow(['full_name', 'x', 'y'] + covariateNamesClean)
        trainingWriter.writerow(['full_name', 'x', 'y'] + covariateNamesClean)
        backgroundWriter.writerow(['full_name', 'x', 'y'] + covariateNamesClean)
        
        #loop through the rows sending each row to the appropriate file
        hasBackground = False
        for row in MDSreader:
            if row[2] == '-9999':
                hasBackground = True
                vals = self.usedValues(row, covariateIndexes)
                backgroundWriter.writerow([''] + row[:2] + vals)
            elif splitcol is None and row[2] <> 0:
                vals = self.usedValues(row, covariateIndexes)
                trainingWriter.writerow([self.args['species_name']] + row[:2] + vals)
            elif (row[splitcol] == 'test' and row[2] <> 0) or \
                self.testCSV == '':
                vals = self.usedValues(row, covariateIndexes)
                testWriter.writerow([self.args['species_name']] + row[:2] + vals)
            elif row[splitcol] == 'train'  and row[2] <> 0:
                vals = self.usedValues(row, covariateIndexes)
                trainingWriter.writerow([self.args['species_name']] + row[:2] + vals)
            #any absense points (row[2] == 0) will be ignored for maxent
        
        if not hasBackground:
            msg = "    No background points were detected in the input file."
            msg += "\n    This implementation of Maxent does not have access to prepared ASCII environmental layers"
            msg += " from which to extract values.  Background points must be supplied in the MDS file."
            self.writetolog(msg)
            raise RuntimeError(msg)
        
        #del our writers 
        try:
            del testWriter
            if deleteTest:
                os.remove(self.testCSV)
                self.testCSV = ''
            del backgroundWriter
            if not hasBackground:
                os.remove(self.backgroundCSV)
                self.backgroundCSV = ''
            del trainingWriter
        except:
            print ' '.join([str(i) for i in sys.exc_info()[:2]])
            pass
        
        #First we have to figure out what they passed us
        #either a directory, a SWD file, or a csv with a list of files
        
        if self.args['projectionlayers'] <> '':
            pass
        else:
            self.args['outputgrids'] = 'false'
dataset/ETHPy150Open VisTrails/VisTrails/contrib/sahm/pySAHM/MaxentRunner.py/MAXENTRunner.prepInputs