Changeset 55
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/nl/tno/massSequencing/SampleController.groovy
r52 r55 99 99 tokens.each { token -> 100 100 sample = Sample.findBySampleToken( token ); 101 if( sample .study.canRead( session.user ) ) {101 if( sample?.study?.canRead( session.user ) ) { 102 102 if( sample && sample.assaySamples ) 103 103 assaySamples += sample.assaySamples; … … 106 106 ids.each { id -> 107 107 sample = Sample.get( id ); 108 if( sample .study.canRead( session.user ) ) {108 if( sample?.study?.canRead( session.user ) ) { 109 109 if( sample && sample.assaySamples ) 110 110 assaySamples += sample.assaySamples; -
trunk/grails-app/services/nl/tno/massSequencing/FastaService.groovy
r54 r55 624 624 // The minimum number of characters used is 10, to ensure the correct working of the other 625 625 // programs. 626 int tagLength = Math.max( 10, Math.ceil( Math.log( assaySamples.size() ) / Math.log( 4 ) ) );626 int tagLength = computeTagLength( assaySamples.size() ) 627 627 int tagNumber = 0; 628 628 … … 800 800 def numChars = chars.size(); 801 801 802 if( tagNumber > numChars ** length ) 802 // Determine whether the tagNumber is not too high 803 if( tagNumber > numChars * ( ( numChars - 1 ) ** ( length - 1 ) ) ) 803 804 throw new Exception( "Given tag number (" + tagNumber + ") is too large for the specified length (" + length + ")") 804 805 805 806 String tag = ""; 806 807 808 // Loop through all characters 807 809 for( def i = 0; i < length; i++ ) { 808 int currentChar = tagNumber % numChars 809 810 // Append the new character to the end of the tag, to ensure that the first part of the tag is 811 // the most volatile. This way it is easy to find the end of the tag and the beginning of the real 812 // sequence on first sight. 813 tag = tag + chars[ currentChar ]; 814 815 tagNumber = Math.floor( tagNumber / numChars ); 810 def currentChars 811 812 // Make sure the characters to choose from are different from 813 // the previous character 814 if( i == 0 ) 815 currentChars = chars; 816 else 817 currentChars = chars - tag[ 0 ] 818 819 // Determine which character to append by taking the tagNumber modulo the number of characters 820 int currentChar = tagNumber % currentChars.size() 821 tag = currentChars[ currentChar ] + tag; 822 823 tagNumber = Math.floor( tagNumber / currentChars.size() ); 816 824 } 817 825 818 826 return tag; 827 } 828 829 /** 830 * Computes the number of characters needed for a tag to be unique for the given number of samples 831 * @param numSamples Number of samples to generate tags for 832 * @return Number of characters needed for a unique tag 833 */ 834 public int computeTagLength( int numSamples ) { 835 // No homopolymers are allowed in the tag. For that reason we have 836 // 4 possibilities for the first character, and 3 for every next character 837 838 // In order to allow enough characters, we take the 3log(numSamples), with a 839 // minimum of 10 840 return Math.max( 10, Math.ceil( Math.log( numSamples ) / Math.log( 3 ) ) ); 819 841 } 820 842 -
trunk/test/unit/nl/tno/massSequencing/FastaServiceTests.groovy
r42 r55 21 21 void testCreateTag() { 22 22 // Simple check for uniqueness on different lengths 23 for( int length = 1; length <= 5; length++ ) {23 for( int length = 1; length <= 6; length++ ) { 24 24 println "Checking uniqueness on length " + length 25 25 26 int maxTags = 4 * * length;26 int maxTags = 4 * 3 ** ( length - 1); 27 27 List tags = [] 28 28 for( int tagNum = 0; tagNum < maxTags; tagNum++ ) { 29 29 String tag = fastaService.createTag( length, tagNum ); 30 assert tag.size() == length;31 30 tags << tag; 32 31 }
Note: See TracChangeset
for help on using the changeset viewer.