public void scan() {
		SAMFileReader inputSAM = new SAMFileReader(inputSAMFile);
		SAMFileWriter outputSAM = new SAMFileWriterFactory().makeBAMWriter(
				inputSAM.getFileHeader(), true, outputSAMFile);
		SAMFileWriter outputSAM2 = new SAMFileWriterFactory().makeBAMWriter(
				inputSAM.getFileHeader(), true, outputSAMFile2);
		String str ="";

		long IACount = 0;
		long TotalCount = 0;


		for (SAMRecord samRecord : inputSAM) {
			str ="";

			if ((!samRecord.getReadUnmappedFlag())
					&& samRecord.getSecondOfPairFlag()) {
 				//System.out.println(samRecord.getReferenceName()+" "+samRecord.getAlignmentEnd());	
				if(samRecord.getReadNegativeStrandFlag())
				str = fastadao.getSequence(samRecord.getReferenceName(),samRecord.getAlignmentEnd(),true);	
				else if(!samRecord.getReadNegativeStrandFlag()){
					str = fastadao.getSequence(samRecord.getReferenceName(),samRecord.getAlignmentStart(),false);	
				}
 				//System.out.println(str);
				//str = fastadao.getSequence("chr1", 10024867, true);					 		
				//System.out.println(str);
				
			} else {
				continue;
			}

			boolean flag = IAcheck(str,contThre, ratioThre,ratioRange,samRecord.getReadNegativeStrandFlag());
			if (flag){
				IACount++;
				outputSAM.addAlignment(samRecord);
				flag = false;
				//System.out.println(flag);				
			} else {
				outputSAM2.addAlignment(samRecord);
			}
						
			if(TotalCount%200000==0){
				System.out.print(".");
				if (TotalCount%4000000==0) System.out.println();
			}
			TotalCount++;
		}

		System.out.println("IA:" + IACount);
		System.out.println("Total 3' Reads:" + TotalCount);

		inputSAM.close();
		outputSAM.close();
		outputSAM2.close();
		fastadao.close();
	}