private static void computeGappedSequenceBlastP(String readName,String readSequence,String text,Collection<Pair<Integer,String>> insertions,boolean showInsertions,Single<char[]> referenceSequence,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[length]);
  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()[p - 1]=subjectString.charAt(i);
      p++;
    }
  }
  int alignPos=(startSubject - 1);
  Pair<Integer,String> insertion=null;
  final StringWriter w=new StringWriter();
  for (int mPos=0; mPos < queryString.length(); mPos++) {
    char ch=queryString.charAt(mPos);
    if (ch == '-') {
      if (insertion != null) {
        insertion=null;
      }
      w.write("-");
      alignPos+=1;
    }
 else     if (subjectString.charAt(mPos) == '-') {
      if (showInsertions) {
        if (insertion == null) {
          insertion=new Pair<>(alignPos - 1,queryString.substring(mPos,mPos + 1));
          insertions.add(insertion);
        }
 else {
          insertion.setSecond(insertion.getSecond() + readSequence.substring(mPos,mPos + 1));
        }
      }
      alignPos+=1;
    }
 else {
      if (insertion != null) {
        insertion=null;
      }
      w.write(ch);
      alignPos+=1;
    }
  }
  String block=w.toString();
  int leadingGaps=startSubject - 1;
  int trailingGaps=length - endSubject;
  String unalignedPrefix=readSequence.substring(0,startQuery);
  String unalignedSuffix=readSequence.substring(endQuery,readSequence.length());
  alignment.addSequence(readName,text,null,unalignedPrefix,leadingGaps,block,trailingGaps,unalignedSuffix);
}

private static void computeGappedSequenceBlastP ( String readName , String readSequence , String text , Collection < Pair < Integer , String > > insertions , boolean showInsertions , Single < char [ ] > referenceSequence , 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 [ length ] ) ; 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 ( ) [ p - 1 ] = subjectString . charAt ( i ) ; p ++ ; } } int alignPos = ( startSubject - 1 ) ; Pair < Integer , String > insertion = null ; final StringWriter w = new StringWriter ( ) ; for ( int mPos = 0 ; mPos < queryString . length ( ) ; mPos ++ ) { char ch = queryString . charAt ( mPos ) ; if ( ch == '-' ) { if ( insertion != null ) { insertion = null ; } w . write ( "-" ) ; alignPos += 1 ; } else if ( subjectString . charAt ( mPos ) == '-' ) { if ( showInsertions ) { if ( insertion == null ) { insertion = new Pair < > ( alignPos - 1 , queryString . substring ( mPos , mPos + 1 ) ) ; insertions . add ( insertion ) ; } else { insertion . setSecond ( insertion . getSecond ( ) + readSequence . substring ( mPos , mPos + 1 ) ) ; } } alignPos += 1 ; } else { if ( insertion != null ) { insertion = null ; } w . write ( ch ) ; alignPos += 1 ; } } String block = w . toString ( ) ; int leadingGaps = startSubject - 1 ; int trailingGaps = length - endSubject ; String unalignedPrefix = readSequence . substring ( 0 , startQuery ) ; String unalignedSuffix = readSequence . substring ( endQuery , readSequence . length ( ) ) ; alignment . addSequence ( readName , text , null , unalignedPrefix , leadingGaps , block , trailingGaps , unalignedSuffix ) ; }
compute the aligned read sequence
