private static void computeGappedSequenceBlastX(String readName,String readSequence,String text,Collection<Pair<Integer,String>> insertions,boolean showInsertions,Single<char[]> referenceSequence,Single<char[]> originalReferenceSequence,Alignment alignment) throws IOException {
  int length=Basic.parseInt(grabNext(text,"Length =","Length="));
  if (length == 0)   length=10000;
  if (referenceSequence.get() == null)   referenceSequence.set(new char[3 * length]);
  if (originalReferenceSequence.get() == null) {
    originalReferenceSequence.set(new char[length]);
    for (int i=0; i < length; i++) {
      originalReferenceSequence.get()[i]='?';
    }
  }
  final int frame=Basic.parseInt(grabNext(text,"Frame =","Frame="));
  int startQuery=Basic.parseInt(grabNext(text,"Query:","Query"));
  int endQuery=Basic.parseInt(grabLastInLinePassedScore(text,"Query"));
  if (readSequence == null)   throw new IOException("Read '" + readName + "': sequence not found");
  if (readSequence.length() < Math.max(startQuery,endQuery)) {
    throw new IOException("Read '" + readName + "': read length too short: "+ readSequence.length()+ " < "+ Math.max(startQuery,endQuery));
  }
  int startSubject=Basic.parseInt(grabNext(text,"Sbjct:","Sbjct"));
  int endSubject=Basic.parseInt(grabLastInLinePassedScore(text,"Sbjct"));
  String queryString=grabQueryString(text);
  String subjectString=grabSubjectString(text);
  int p=startSubject;
  for (int i=0; i < subjectString.length(); i++) {
    if (subjectString.charAt(i) != '-') {
      referenceSequence.get()[3 * (p - 1)]=subjectString.charAt(i);
      originalReferenceSequence.get()[p - 1]=subjectString.charAt(i);
      p++;
    }
  }
  if (frame < 0) {
    readName+=" (rev)";
    startQuery=readSequence.length() - startQuery + 1;
    endQuery=readSequence.length() - endQuery + 1;
    readSequence=SequenceUtils.getReverseComplement(readSequence);
  }
  int pos=startQuery - 1;
  int alignPos=3 * (startSubject - 1);
  Pair<Integer,String> insertion=null;
  StringWriter w=new StringWriter();
  for (int mPos=0; mPos < queryString.length(); mPos++) {
    if (queryString.charAt(mPos) == '-') {
      if (insertion != null) {
        insertion=null;
      }
      w.write("---");
      alignPos+=3;
    }
 else     if (subjectString.charAt(mPos) == '-') {
      if (showInsertions) {
        if (insertion == null) {
          insertion=new Pair<>(alignPos - 1,readSequence.substring(pos,pos + 3));
          insertions.add(insertion);
        }
 else {
          insertion.setSecond(insertion.getSecond() + readSequence.substring(pos,pos + 3));
        }
      }
      pos+=3;
      alignPos+=3;
    }
 else {
      if (insertion != null) {
        insertion=null;
      }
      if (pos < 0) {
        throw new IOException("pos too small: " + pos);
      }
      if (pos >= readSequence.length()) {
        throw new IOException("pos overrun end of read: " + pos + " >= "+ readSequence.length());
      }
 else {
        w.write(readSequence.charAt(pos++));
        w.write(readSequence.charAt(pos++));
        w.write(readSequence.charAt(pos++));
        alignPos+=3;
      }
    }
  }
  final String block=w.toString();
  final int leadingGaps=3 * (startSubject - 1);
  final int trailingGaps=3 * (length - endSubject);
  final String unalignedPrefix=readSequence.substring(0,startQuery);
  final String unalignedSuffix=readSequence.substring(endQuery,readSequence.length());
  alignment.addSequence(readName,text,null,unalignedPrefix,leadingGaps,block,trailingGaps,unalignedSuffix);
}

private static void computeGappedSequenceBlastX ( String readName , String readSequence , String text , Collection < Pair < Integer , String > > insertions , boolean showInsertions , Single < char [ ] > referenceSequence , Single < char [ ] > originalReferenceSequence , Alignment alignment ) throws IOException { int length = Basic . parseInt ( grabNext ( text , "Length =" , "Length=" ) ) ; if ( length == 0 ) length = 10000 ; if ( referenceSequence . get ( ) == null ) referenceSequence . set ( new char [ 3 * length ] ) ; if ( originalReferenceSequence . get ( ) == null ) { originalReferenceSequence . set ( new char [ length ] ) ; for ( int i = 0 ; i < length ; i ++ ) { originalReferenceSequence . get ( ) [ i ] = '?' ; } } final int frame = Basic . parseInt ( grabNext ( text , "Frame =" , "Frame=" ) ) ; int startQuery = Basic . parseInt ( grabNext ( text , "Query:" , "Query" ) ) ; int endQuery = Basic . parseInt ( grabLastInLinePassedScore ( text , "Query" ) ) ; if ( readSequence == null ) throw new IOException ( "Read '" + readName + "': sequence not found" ) ; if ( readSequence . length ( ) < Math . max ( startQuery , endQuery ) ) { throw new IOException ( "Read '" + readName + "': read length too short: " + readSequence . length ( ) + " < " + Math . max ( startQuery , endQuery ) ) ; } int startSubject = Basic . parseInt ( grabNext ( text , "Sbjct:" , "Sbjct" ) ) ; int endSubject = Basic . parseInt ( grabLastInLinePassedScore ( text , "Sbjct" ) ) ; String queryString = grabQueryString ( text ) ; String subjectString = grabSubjectString ( text ) ; int p = startSubject ; for ( int i = 0 ; i < subjectString . length ( ) ; i ++ ) { if ( subjectString . charAt ( i ) != '-' ) { referenceSequence . get ( ) [ 3 * ( p - 1 ) ] = subjectString . charAt ( i ) ; originalReferenceSequence . get ( ) [ p - 1 ] = subjectString . charAt ( i ) ; p ++ ; } } if ( frame < 0 ) { readName += " (rev)" ; startQuery = readSequence . length ( ) - startQuery + 1 ; endQuery = readSequence . length ( ) - endQuery + 1 ; readSequence = SequenceUtils . getReverseComplement ( readSequence ) ; } int pos = startQuery - 1 ; int alignPos = 3 * ( startSubject - 1 ) ; Pair < Integer , String > insertion = null ; StringWriter w = new StringWriter ( ) ; for ( int mPos = 0 ; mPos < queryString . length ( ) ; mPos ++ ) { if ( queryString . charAt ( mPos ) == '-' ) { if ( insertion != null ) { insertion = null ; } w . write ( "---" ) ; alignPos += 3 ; } else if ( subjectString . charAt ( mPos ) == '-' ) { if ( showInsertions ) { if ( insertion == null ) { insertion = new Pair < > ( alignPos - 1 , readSequence . substring ( pos , pos + 3 ) ) ; insertions . add ( insertion ) ; } else { insertion . setSecond ( insertion . getSecond ( ) + readSequence . substring ( pos , pos + 3 ) ) ; } } pos += 3 ; alignPos += 3 ; } else { if ( insertion != null ) { insertion = null ; } if ( pos < 0 ) { throw new IOException ( "pos too small: " + pos ) ; } if ( pos >= readSequence . length ( ) ) { throw new IOException ( "pos overrun end of read: " + pos + " >= " + readSequence . length ( ) ) ; } else { w . write ( readSequence . charAt ( pos ++ ) ) ; w . write ( readSequence . charAt ( pos ++ ) ) ; w . write ( readSequence . charAt ( pos ++ ) ) ; alignPos += 3 ; } } } final String block = w . toString ( ) ; final int leadingGaps = 3 * ( startSubject - 1 ) ; final int trailingGaps = 3 * ( length - endSubject ) ; final String unalignedPrefix = readSequence . substring ( 0 , startQuery ) ; final String unalignedSuffix = readSequence . substring ( endQuery , readSequence . length ( ) ) ; alignment . addSequence ( readName , text , null , unalignedPrefix , leadingGaps , block , trailingGaps , unalignedSuffix ) ; }
compute the aligned read sequence
