SharedProteinResources(
      final ProteinScoringMatrix matrix,
      final SequencesReader template,
      final SequencesReader query,
      boolean readNames)
      throws IOException {
    mProteinScoringMatrix = matrix;
    mTemplateReader = template;

    mQueryReader = query;
    if (query != null) {
      mWorkSpace = new byte[(int) query.maxLength()];
      mWorkSpaceProtein = new byte[mWorkSpace.length / 3];
      if (query.numberSequences() > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Number of reads exceeds " + Integer.MAX_VALUE);
      }
    } else {
      mWorkSpace = null;
      mWorkSpaceProtein = null;
    }
    if (mTemplateReader != null) {
      mTemplateNames = mTemplateReader.names();
    } else {
      mTemplateNames = null;
    }
    if (readNames && mQueryReader != null) {
      mReadNames = query.names();
    } else {
      mReadNames = null;
    }
  }
 int queryLength(final int id) throws IOException {
   if (mQueryReader == null) {
     return -1;
   } else {
     return mQueryReader.length(id);
   }
 }
 int templateLength(final int id) throws IOException {
   if (mTemplateReader == null) {
     return -1;
   } else {
     return mTemplateReader.length(id);
   }
 }
 long totalTemplateLength() {
   if (mTemplateReader == null) {
     return -1;
   } else {
     return mTemplateReader.totalLength();
   }
 }
 /**
  * Return the query, resulting array may contain rubbish entries at the end. Assumes the caller
  * knows what it is doing!
  *
  * @param id read id
  * @param frame read frame
  * @return amino acid sequence
  * @exception IOException if an I/O error occurs.
  */
 byte[] query(final int id, final int frame) throws IOException {
   if (mQueryReader == null) {
     return EMPTY;
   } else if (mQueryReader.type() == SequenceType.DNA) {
     // In this situation, use precomputed array to store intermediate nt version
     final int length = mQueryReader.read(id, mWorkSpace);
     // Convert to protein in situ
     final Frame frames = ProteinOutputProcessor.FRAMES_MAPPING[frame + 3];
     final int limit = (length - Math.abs(frame) + 1) / 3;
     for (int j = 0, i = 0; j < limit; j++, i += 3) {
       mWorkSpaceProtein[j] = frames.code(mWorkSpace, length, i);
     }
     return mWorkSpaceProtein;
   } else {
     return mQueryReader.read(id);
   }
 }
 byte[] template(final int id) throws IOException {
   if (id != mCachedTemplateId) {
     if (mTemplateReader == null) {
       mCachedTemplate = EMPTY;
     } else {
       mCachedTemplate = mTemplateReader.read(id);
     }
     mCachedTemplateId = id;
   }
   return mCachedTemplate;
 }
Beispiel #7
0
 private static BufferedReader getReferenceReader(SequencesReader genome, DefaultFallback fallback)
     throws IOException {
   final BufferedReader r;
   final File ref = new File(genome.path(), REFERENCE_FILE);
   if (ref.exists()) {
     final InputStreamReader isr =
         new InputStreamReader(new BufferedInputStream(new FileInputStream(ref)));
     r = new BufferedReader(isr);
   } else if (fallback == DefaultFallback.DIPLOID) {
     r = new BufferedReader(new StringReader(REFERENCE_DEFAULT_DIPLOID));
   } else if (fallback == DefaultFallback.HAPLOID) {
     r = new BufferedReader(new StringReader(REFERENCE_DEFAULT_HAPLOID));
   } else {
     if (genome.path() != null) {
       throw new IOException("No reference file contained in: " + genome.path().getPath());
     } else {
       throw new IOException("No reference file found");
     }
   }
   return r;
 }
Beispiel #8
0
 /**
  * Test if reference file exists
  *
  * @param sr sequences reader
  * @return true if it exists
  */
 public static boolean hasReferenceFile(SequencesReader sr) {
   return new File(sr.path(), REFERENCE_FILE).exists();
 }