Package kmer

Examples of kmer.ProteinKmerBitFeatureVector


         
          byte[] valueVector = new byte[(int) Math.ceil(Math.pow(alphabetSize, kmerLength) / ProteinKmerBitFeatureVector.BITS_IN_BYTE)];
          System.arraycopy(value.getBytes(), 0, valueVector, 0, valueVector.length);
       
          // Add the kmer feature vector to the array of clusters'.
          clusterFeatureVectors[(int) key.get()] = new ProteinKmerBitFeatureVector(valueVector, kmerLength, alphabetSize);
         
          key.set(0);
        }
       
        reader.close();
View Full Code Here


            / ProteinKmerBitFeatureVector.BITS_IN_BYTE)];

        // Very slow.
        // System.arraycopy(value.getBytes(), 0, featureVector, 0, featureVector.length);
       
        ProteinKmerBitFeatureVector vector = new ProteinKmerBitFeatureVector(
            featureVector, context.getConfiguration().getInt(KMER_LENGTH, 3));
         
        LOG.info(key.get() + ": " + vector.printKmers());
      }
     
      byte[] valueBytes = value.getBytes();
     
      for (int i = 0; i < clusterFeatureVectors.length; i++) {
View Full Code Here

    byte[] testBytes = new byte[(int) Math.ceil(Math.pow(20, 3) / ProteinKmerBitFeatureVector.BITS_IN_BYTE)];
   
    initializeBytes(testBytes);
    testBytes[0] = (byte) 0x1;
   
    ProteinKmerBitFeatureVector vector = new ProteinKmerBitFeatureVector(testBytes, 3, 20);
   
    assertTrue(equalBytes(vector.getFeatureVector(), testBytes));

    testBytes[0] = (byte) 0x0;
   
    assertTrue(!equalBytes(vector.getFeatureVector(), testBytes));
  }
View Full Code Here

    assertTrue(!equalBytes(vector.getFeatureVector(), testBytes));
  }
 
  /** Test for {@link ProteinKmerBitFeatureVectorTest#ProteinKmerFeatureVector(byte[])}. */
  public void testPrintKmers() {   
    ProteinKmerBitFeatureVector vector = new ProteinKmerBitFeatureVector(3, 20);
   
    vector.parseKmersFromSequence("AVAA");
   
    System.out.println(vector.printKmers());
   
    assertTrue(true);
  }
View Full Code Here

    assertTrue(true);
  }
 
  /** Test for {@link ProteinKmerBitFeatureVectorTest#parseKmersFromSequence(String)}. */
  public void testSetBitsCorrectly() {
    ProteinKmerBitFeatureVector vector = new ProteinKmerBitFeatureVector(2, 20);
    String sequence = "AA";
   
    byte[] testBytes = new byte[(int) Math.ceil(Math.pow(vector.getAlphabetSize(),
        vector.getKmerLength()) / ProteinKmerBitFeatureVector.BITS_IN_BYTE)];
   
    initializeBytes(testBytes);
    testBytes[0] = (byte) 0x1;
   
    vector.parseKmersFromSequence(sequence);
    byte[] bytes = vector.getFeatureVector();

    System.out.println(vector.printByteVector());
    System.out.println(printByteVector(testBytes));
   
    assertTrue(equalBytes(bytes, testBytes));
   
    sequence = "AR";

    vector = new ProteinKmerBitFeatureVector(2, 20);
    vector.parseKmersFromSequence(sequence);
    bytes = vector.getFeatureVector();
   
    testBytes[0] = (byte) 0x2;
   
    System.out.println(vector.printByteVector());
    System.out.println(printByteVector(testBytes));
   
    assertTrue(equalBytes(bytes, testBytes));
   
    sequence = "AV";
   
    vector = new ProteinKmerBitFeatureVector(2, 20);
    vector.parseKmersFromSequence(sequence);
    bytes = vector.getFeatureVector();
   
    testBytes[0] = (byte) 0x0;
    testBytes[2] = (byte) 0x8;
   
    System.out.println(vector.printByteVector());
    System.out.println(printByteVector(testBytes));
   
    assertTrue(equalBytes(bytes, testBytes));
   
    sequence = "VV";
   
    vector = new ProteinKmerBitFeatureVector(2, 20);
    vector.parseKmersFromSequence(sequence);
    bytes = vector.getFeatureVector();
   
    testBytes[0] = (byte) 0x0;
    testBytes[2] = (byte) 0x0;
    testBytes[49] = (byte) 0x80;
   
    System.out.println(vector.printByteVector());
    System.out.println(printByteVector(testBytes));
   
    assertTrue(equalBytes(bytes, testBytes));
   
    // 32, b = -65
View Full Code Here

     
      // Skip the header character.
      LongWritable seqId = new LongWritable(new Integer(line.substring(1, spaceIndex)));
     
      // Create the feature vector.
      ProteinKmerBitFeatureVector featureVector = new ProteinKmerBitFeatureVector(
          context.getConfiguration().getInt(KMER_LENGTH, 3));
      // ProteinKmerCountFeatureVector featureVector = new ProteinKmerCountFeatureVector(
      //    context.getConfiguration().getInt(KMER_LENGTH, 3));
     
      featureVector.parseKmersFromSequence(line.substring(spaceIndex + 1).trim());
     
     
      LOG.info(featureVector.getFeatureVector().length);
      LOG.info(featureVector.printByteVector());
      LOG.info(featureVector.printKmers());
     
      context.write(seqId, new BytesWritable(featureVector.getFeatureVector()));
    }
View Full Code Here

        // LOG.info("Value bytes: " + value.getBytes().length);
       
        byte[] valueVector = new byte[numberOfBytes];
        System.arraycopy(value.getBytes(), 0, valueVector, 0, valueVector.length);
       
        ProteinKmerBitFeatureVector featureVector = new ProteinKmerBitFeatureVector(
            valueVector, context.getConfiguration().getInt(KMER_LENGTH, 3));
       
        // LOG.info(featureVector.printByteVector());
        // LOG.info(featureVector.printKmers());
       
        context.write(key, new Text(featureVector.printKmers()));
      }     
    }
View Full Code Here

public class ProteinKmerBitFeatureVectorTest extends TestCase {
 
  /** Test for {@link ProteinKmerBitFeatureVectorTest#getIndexForSequence(String)}. */
  public void testGetIndexForSequence() {

    ProteinKmerBitFeatureVector vector = new ProteinKmerBitFeatureVector(2, 20);
    assertEquals(vector.getIndexForSequence("AR"), 1);
    assertEquals(vector.getIndexForSequence("VV"), 399);
   
    vector = new ProteinKmerBitFeatureVector(3, 20);
   
    assertEquals(vector.getIndexForSequence("AAA"), 0);
    assertEquals(vector.getIndexForSequence("AAR"), 1);
    assertEquals(vector.getIndexForSequence("AAD"), 3);
    assertEquals(vector.getIndexForSequence("RAA"), 400);
    assertEquals(vector.getIndexForSequence("RAR"), 401);
    assertEquals(vector.getIndexForSequence("VVV"), 7999);
   
    vector = new ProteinKmerBitFeatureVector(4, 20);

    assertEquals(vector.getIndexForSequence("AAAA"), 0);
    assertEquals(vector.getIndexForSequence("AAAA"), 0);
    assertEquals(vector.getIndexForSequence("EQHI"), 42569);
    assertEquals(vector.getIndexForSequence("VVVV"), 159999);   
  }
View Full Code Here

        throws IOException, InterruptedException {
       
      String[] tuple = value.toString().split("\t");
      String kmerTable = tuple[1].trim();
     
      ProteinKmerBitFeatureVector featureVector = new ProteinKmerBitFeatureVector(kmerLength);
     
      for (int i = 0; i < kmerTable.length() /*- kmerLength*/; i += kmerLength) {
        featureVector.setBitAtPosition(featureVector.getIndexForSequence(kmerTable.substring(i, i + kmerLength)));
      }
               
      context.write(new LongWritable(new Long(tuple[0])), new BytesWritable(featureVector.getFeatureVector()));
    }
View Full Code Here

   *
   * @param kmerLength
   * @return
   */
  private BytesWritable createRandomBitVector(int kmerLength) {
    ProteinKmerBitFeatureVector featureVector = new ProteinKmerBitFeatureVector(kmerLength);
    byte[] vector = featureVector.getFeatureVector();
   
    Random r = new Random();
   
    for (int i = 0; i < vector.length; i++) {
      vector[i] = (byte) r.nextInt();
View Full Code Here

TOP

Related Classes of kmer.ProteinKmerBitFeatureVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.