Ignore:
Timestamp:
Feb 16, 2011, 2:24:56 PM (11 years ago)
Author:
robert@…
Message:

Implemented improved authorization (#16)
Built in select all checkboxes (#25)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/nl/tno/metagenomics/SampleExcelService.groovy

    r13 r14  
    8787                       
    8888                headers.eachWithIndex { header, idx ->
    89                         // Do matching using fuzzy search. The 0.1 treshold makes sure that no match if chosen if
     89                        // Do matching using fuzzy search. The 0.8 treshold makes sure that no match if chosen if
    9090                        // there is actually no match at all.
    91                         bestMatches[idx] = fuzzySearchService.mostSimilar( header, possibleFields, 0.1 );
     91                        if( !header || header.toString().trim() == "" )
     92                                bestMatches[idx] = null
     93                        else
     94                                bestMatches[idx] = fuzzySearchService.mostSimilar( header, possibleFields, 0.8 );
    9295                }
    9396               
     
    119122                def dataMatches = false;
    120123                possibleFields.each { columnName ->
    121                         columns[ columnName ] = matchColumns.findIndexOf { it.value == columnName }
     124                        def foundColumn = matchColumns.find { it.value == columnName };
     125                       
     126                        columns[ columnName ] = ( foundColumn && foundColumn.key.toString().isInteger() ) ? Integer.valueOf( foundColumn.key.toString() ) : -1;
    122127
    123128                        if( columnName != sampleNameName && columns[ columnName ] != -1 )
     
    125130                }
    126131
     132                println columns
     133               
    127134                // A column to match the sample name must be present
    128135                if( columns[ sampleNameName ] == -1 ) {
    129                         // Now delete the file, since we don't need it anymore
    130                         _deleteUploadedFileFromSession()
    131 
    132136                        return [ success: false, message: "There must be a column present in the excel file that matches the sample name. Please try again." ]
    133137                }
     
    135139                // A column with data should also be present
    136140                if( !dataMatches ) {
    137                         // Now delete the file, since we don't need it anymore
    138                         _deleteUploadedFileFromSession()
    139 
    140141                        return [ success: false, message: "There are no data columns present in the excel file. No samples are updated." ]
    141142                }
     
    166167                        String sampleName = rowData[ columns[ sampleNameName ] ] as String
    167168
     169                        // If no sample name is found, the row is either empty or contains no sample name
     170                        if( !sampleName ) {
     171                                failedRows << [ row: rowData, sampleName: "" ];
     172                                continue;
     173                        }
     174                               
    168175                        // Find assay by sample name. Since sample names are unique within an assay (enforced by GSCF),
    169176                        // this will always work when only using one assay. When multiple assays are used, this might pose
    170177                        // a problem
     178                        // TODO: Fix problem with multiple assays
    171179                        AssaySample assaySample = assaySamples.find { it.sample.id == Sample.findByName( sampleName )?.id };
     180                        println "Row: " + i + " - Sample name: " + sampleName + " - " + assaySample
    172181
    173182                        // If no assaysample is found, add this row to the failed-row list
Note: See TracChangeset for help on using the changeset viewer.