22
22
import net .sf .samtools .SAMRecordIterator ;
23
23
24
24
25
+
25
26
//import org.apache.commons.math3.util.MultidimensionalCounter.Iterator;
26
27
import org .apache .log4j .Logger ;
27
28
@@ -63,6 +64,7 @@ public InDropPreprocess(HashMap<String,ArrayList<File>> bamFiles,
63
64
64
65
SAMRecord r ;
65
66
SAMFileWriterFactory sf = new SAMFileWriterFactory ();
67
+ File outFile ;
66
68
int readsIn = 0 ;
67
69
int readsOut = 0 ;
68
70
@@ -88,52 +90,26 @@ public InDropPreprocess(HashMap<String,ArrayList<File>> bamFiles,
88
90
SAMFileHeader bamHeader = bamReader .getFileHeader (); // get the header information
89
91
90
92
// create the pre-processed output BAM file:
91
- // The processed file is called <original bam file base name>_nextPrep .bam
93
+ // The processed file is called <original bam file base name>_inPrep .bam
92
94
String inFile = bamFile .getCanonicalPath ();
93
95
int extPos = inFile .length ()-4 ;
94
- File outFile = new File (inFile .substring (0 ,extPos )+"_inPrep" +inFile .substring (extPos ));
96
+ // File outFile = new File(inFile.substring(0,extPos)+"_inPrep"+inFile.substring(extPos));
97
+
98
+ // Make a temporary file for the PCR de-duplicated reads:
99
+ //logger.info("creating temporary file: "+inFile.substring(0,extPos)+"xxxxxxx.bam");
100
+ //outFile = File.createTempFile(inFile.substring(0,extPos), ".bam");
101
+ outFile = File .createTempFile ("sc_umiFiltered_" , ".bam" );
102
+ logger .info ("temporary file created: " +outFile );
103
+ // delete after exit:
104
+ outFile .deleteOnExit ();
95
105
96
106
// add this file to the list of files to be processed by ESAT:
97
107
if (!bamFiles_prep .containsKey (exp )) {
98
108
bamFiles_prep .put (exp , new ArrayList <File >());
99
109
}
100
110
bamFiles_prep .get (exp ).add (outFile );
101
- SAMProgramRecord prepProg = new SAMProgramRecord ("ESAT" );
102
- prepProg .setProgramVersion (PROGRAM_VERSION );
103
- prepProg .setAttribute ("task" , task );
104
- prepProg .setAttribute ("wExt" , "" +wExt );
105
- boolean makeNewPrepFile = true ; // by default, make a new file.
106
-
107
- // check for the existence of this file:
108
- if (outFile .exists ()) {
109
- // open the file to read the header
110
- SAMFileReader scReader = new SAMFileReader (outFile ); // open as a non-eager reader
111
- SAMFileHeader scHeader = scReader .getFileHeader (); // get the header information
112
- List <SAMProgramRecord > scProg = scHeader .getProgramRecords ();
113
- // check to make sure the ESAT parameters are the same:
114
- for (SAMProgramRecord sp :scProg ) {
115
- String pid = sp .getProgramGroupId ();
116
- if (pid .equals ("ESAT" )) {
117
- // Extract all necessary parameters:
118
- String oldVer = sp .getProgramVersion ();
119
- String oldTask = sp .getAttribute ("task" );
120
- int oldWExt = Integer .parseInt (sp .getAttribute ("wExt" ));
121
- if (oldVer .equals (PROGRAM_VERSION ) && oldTask .equals (task ) && oldWExt ==wExt ) {
122
- makeNewPrepFile = false ;
123
- }
124
- }
125
- }
126
- }
127
111
128
- if (!makeNewPrepFile ) {
129
- // close the input file
130
- bamReader .close ();
131
- // skip creating a new output file:
132
- continue ;
133
- }
134
-
135
112
// copy the header from the input BAM file:
136
- bamHeader .addProgramRecord (prepProg );
137
113
SAMFileWriter bamWriter = sf .makeBAMWriter (bamHeader , false , outFile );
138
114
139
115
//bamReader.setValidationStringency(ValidationStringency.LENIENT);
0 commit comments