    private void parseInput(File inputFile) throws IOException {
        CSVReader reader = null;
        Map<String, Set<String>> groupMap = new HashMap<String, Set<String>>();
        Map<String, Set<Publication>> publicationMap = new HashMap<String, Set<Publication>>();
        Map<String, SampleData> stMap = new HashMap<String, SampleData>();
        int linecount;
        String [] nextLine;
        try {
            reader = new CSVReader(new FileReader(inputFile), "\t".charAt(0));
            linecount = 0;
            while ((nextLine = reader.readNext()) != null) {
                linecount += 1;
                if (this.headers == null || linecount == 0){
                    this.headers = new ArrayList<String>();
                    for (String header : nextLine){
                        if (header.startsWith("V_")){
                            header = header.substring(2);
                        }
                        log.info("Found header : "+header);
                        headers.add(header);
                    }
                    this.doiindex = this.headers.indexOf("DOI");
                    if (this.doiindex < 0){
                        throw new IOException("Headers does not contain DOI");
                    }
                    this.pubmedindex = this.headers.indexOf("PUBMED_ID");
                    if (this.pubmedindex < 0){
                        throw new IOException("Headers does not contain PUBMED_ID");
                    }
                    this.projheaderindex = this.headers.indexOf("PROJECT_ACC");
                    this.pubheaderindex = this.headers.indexOf("ENA_PUBID");
                    if (this.pubheaderindex < 0){
                        throw new IOException("Headers does not contain ENA_PUBID");
                    }
                    this.collectedbyindex = this.headers.indexOf("COLLECTED_BY");
                    if (this.collectedbyindex < 0){
                        throw new IOException("Headers does not contain COLLECTED_BY");
                    }
                    this.identifiedbyindex = this.headers.indexOf("IDENTIFIED_BY");
                    if (this.identifiedbyindex < 0){
                        throw new IOException("Headers does not contain IDENTIFIED_BY");
                    }
                    this.taxidindex = this.headers.indexOf("TAX_ID");
                    if (this.taxidindex < 0){
                        throw new IOException("Headers does not contain TAX_ID");
                    }
                } else {
                    if (nextLine.length > headers.size()){
                        log.warn("Line longer than headers "+linecount);
                    }
                    String accession = nextLine[0].trim();
                    log.debug("First processing "+accession);
                    for (String id : getGroupIdentifiers(nextLine)){
                        if(!groupMap.containsKey(id)){
                            groupMap.put(id, new HashSet<String>());
                        }
                        groupMap.get(id).add(accession);
                    }
                    publicationMap.put(accession, getPublications(nextLine));
                    log.info(accession+" "+getPublications(nextLine).size());
                }
            }
            reader.close();
        } finally {
            try {
                if (reader != null){
                    reader.close();
                }
            } catch (IOException e){
            }
        }
        try {
            reader = new CSVReader(new FileReader(inputFile), "\t".charAt(0));
            linecount = 0;
            while ((nextLine = reader.readNext()) != null) {
                linecount += 1;
                if (this.headers == null || linecount == 0){
                } else {
                    if (nextLine.length > this.headers.size()){
                        log.warn("Line longer than headers "+linecount);
                    }
                    String accession = nextLine[0].trim();
                    log.debug("Second processing "+accession);
                    for (String id : getGroupIdentifiers(nextLine)){
                        if (!groupMap.containsKey(id)){
                            continue;
                        }
                        if(!stMap.containsKey(id)){
                            stMap.put(id, new SampleData());
                        }
                        SampleData st = stMap.get(id);
                        SampleNode s = lineToSample(nextLine, st);
                        if (s.getNodeName() == null){
                            log.error("Unable to add node with null name");
                            continue;
                        }
                        try {
                            if (s.getNodeName() == null){
                                log.error("Unable to add node with null name");
                            } else if (st.scd.getNode(s.getNodeName(), SampleNode.class) != null) {
                                log.error("Unable to add duplicate node with name "+s.getNodeName());
                            } else if (s.getAttributes().size() <= 1){
                                log.warn("Refusing to add sample "+s.getNodeName()+" without attributes");
                            } else {
                                st.scd.addNode(s);
                            }
                        } catch (ParseException e) {
                            log.error("Unable to add node "+s.getNodeName(), e);
                        }     
                        if (!groupMap.containsKey(id)){
                            log.error("Problem locating publication ID "+id+" in publication maping");
                            continue;
                        }
                        if (!groupMap.get(id).contains(s.getNodeName())){
                            log.error("Problem removing sample "+s.getNodeName()+" from publication maping");
                            continue;
                        }
                        if (publicationMap.containsKey(accession)){
                            st.msi.publications.addAll(publicationMap.get(accession));
                            log.debug(accession+" "+publicationMap.get(accession).size());
                            log.debug(accession+" "+st.msi.publications.size());
                        }
                        groupMap.get(id).remove(s.getNodeName());
                        if (groupMap.get(id).size() == 0){
                            st.msi.submissionIdentifier = prefix+"-"+id;
                            if (wgs){
                                String speciesName = null;
                                for (SampleNode sn : st.scd.getNodes(SampleNode.class)){
                                    for (SCDNodeAttribute a : sn.getAttributes()){
                                        if (OrganismAttribute.class.isInstance(a)){
                                            OrganismAttribute oa = (OrganismAttribute) a;
                                            speciesName = a.getAttributeValue();
                                        }
                                    }
                                }
                                if (speciesName == null){
                                    log.warn("Unable to determine species name");
                                } else {
                                    st.msi.submissionTitle = "Whole Genome Shotgun sequencing of "+speciesName;
                                }
                            } else if (tsa){
                                String speciesName = null;
                                for (SampleNode sn : st.scd.getNodes(SampleNode.class)){
                                    for (SCDNodeAttribute a : sn.getAttributes()){
                                        if (OrganismAttribute.class.isInstance(a)){
                                            OrganismAttribute oa = (OrganismAttribute) a;
                                            speciesName = a.getAttributeValue();
                                        }
                                    }
                                }
                                if (speciesName == null){
                                    log.warn("Unable to determine species name");
                                } else {
                                    st.msi.submissionTitle = "Transcriptome Shotgun sequencing of "+speciesName;
                                }
                            } else if (bar){
                                st.msi.submissionTitle = st.msi.submissionIdentifier;
                            }
                            log.debug("No. of publications = "+st.msi.publications.size());
                            log.debug("Empty? "+st.msi.publications.isEmpty());
                            File outputSubDir = new File(outputFile, st.msi.submissionIdentifier);
                            File sampletabPre = new File(outputSubDir, "sampletab.pre.txt");
                            outputSubDir.mkdirs();
                            log.info("Writing "+sampletabPre);
                            SampleTabWriter sampletabwriter = null;
                            try {
                                sampletabwriter = new SampleTabWriter(new BufferedWriter(new FileWriter(sampletabPre)));
                                sampletabwriter.write(st);
                            } catch (IOException e) {
                                log.error("Unable to write to "+sampletabPre, e);
                            } finally {
                                if (sampletabwriter != null){
                                    try {
                                        sampletabwriter.close();
                                    } catch (IOException e) {
                                    }
                                }
                            }
                            groupMap.remove(id);
                            stMap.remove(id);
                        }
                    }
                }
            }
            reader.close();
        } finally {
            try {
                if (reader != null){
                    reader.close();
                }
            } catch (IOException e){
            }
        }
    }

    private void parseInput(File inputFile) throws IOException {
        CSVReader reader = null;
        Map<String, Set<String>> groupMap = new HashMap<String, Set<String>>();
        Map<String, Set<Publication>> publicationMap = new HashMap<String, Set<Publication>>();
        Map<String, SampleData> stMap = new HashMap<String, SampleData>();
        int linecount;
        String [] nextLine;
        try {
            reader = new CSVReader(new FileReader(inputFile), "\t".charAt(0));
            linecount = 0;
            while ((nextLine = reader.readNext()) != null) {
                linecount += 1;
                if (this.headers == null || linecount == 0){
                    this.headers = new ArrayList<String>();
                    for (String header : nextLine){
                        if (header.startsWith("V_")){
                            header = header.substring(2);
                        }
                        log.info("Found header : "+header);
                        headers.add(header);
                    }
                    this.doiindex = this.headers.indexOf("DOI");
                    if (this.doiindex < 0){
                        throw new IOException("Headers does not contain DOI");
                    }
                    this.pubmedindex = this.headers.indexOf("PUBMED_ID");
                    if (this.pubmedindex < 0){
                        throw new IOException("Headers does not contain PUBMED_ID");
                    }
                    this.projheaderindex = this.headers.indexOf("PROJECT_ACC");
                    this.pubheaderindex = this.headers.indexOf("ENA_PUBID");
                    if (this.pubheaderindex < 0){
                        throw new IOException("Headers does not contain ENA_PUBID");
                    }
                    this.collectedbyindex = this.headers.indexOf("COLLECTED_BY");
                    if (this.collectedbyindex < 0){
                        throw new IOException("Headers does not contain COLLECTED_BY");
                    }
                    this.identifiedbyindex = this.headers.indexOf("IDENTIFIED_BY");
                    if (this.identifiedbyindex < 0){
                        throw new IOException("Headers does not contain IDENTIFIED_BY");
                    }
                    this.taxidindex = this.headers.indexOf("TAX_ID");
                    if (this.taxidindex < 0){
                        throw new IOException("Headers does not contain TAX_ID");
                    }
                } else {
                    if (nextLine.length > headers.size()){
                        log.warn("Line longer than headers "+linecount);
                    }
                    String accession = nextLine[0].trim();
                    log.debug("First processing "+accession);
                    for (String id : getGroupIdentifiers(nextLine)){
                        if(!groupMap.containsKey(id)){
                            groupMap.put(id, new HashSet<String>());
                        }
                        groupMap.get(id).add(accession);
                    }
                    publicationMap.put(accession, getPublications(nextLine));
                    log.info(accession+" "+getPublications(nextLine).size());
                }
            }
            reader.close();
        } finally {
            try {
                if (reader != null){
                    reader.close();
                }
            } catch (IOException e){
            }
        }
        try {
            reader = new CSVReader(new FileReader(inputFile), "\t".charAt(0));
            linecount = 0;
            while ((nextLine = reader.readNext()) != null) {
                linecount += 1;
                if (this.headers == null || linecount == 0){
                } else {
                    if (nextLine.length > this.headers.size()){
                        log.warn("Line longer than headers "+linecount);
                    }
                    String accession = nextLine[0].trim();
                    log.debug("Second processing "+accession);
                    for (String id : getGroupIdentifiers(nextLine)){
                        if (!groupMap.containsKey(id)){
                            continue;
                        }
                        if(!stMap.containsKey(id)){
                            stMap.put(id, new SampleData());
                        }
                        SampleData st = stMap.get(id);
                        SampleNode s = lineToSample(nextLine, st);
                        if (s.getNodeName() == null){
                            log.error("Unable to add node with null name");
                            continue;
                        }
                        try {
                            if (s.getNodeName() == null){
                                log.error("Unable to add node with null name");
                            } else if (st.scd.getNode(s.getNodeName(), SampleNode.class) != null) {
                                log.error("Unable to add duplicate node with name "+s.getNodeName());
                            } else if (s.getAttributes().size() <= 1){
                                log.warn("Refusing to add sample "+s.getNodeName()+" without attributes");
                            } else {
                                st.scd.addNode(s);
                            }
                        } catch (ParseException e) {
                            log.error("Unable to add node "+s.getNodeName(), e);
                        }     
                        if (!groupMap.containsKey(id)){
                            log.error("Problem locating publication ID "+id+" in publication maping");
                            continue;
                        }
                        if (!groupMap.get(id).contains(s.getNodeName())){
                            log.error("Problem removing sample "+s.getNodeName()+" from publication maping");
                            continue;
                        }
                        if (publicationMap.containsKey(accession)){
                            st.msi.publications.addAll(publicationMap.get(accession));
                            log.debug(accession+" "+publicationMap.get(accession).size());
                            log.debug(accession+" "+st.msi.publications.size());
                        }
                        groupMap.get(id).remove(s.getNodeName());
                        if (groupMap.get(id).size() == 0){
                            st.msi.submissionIdentifier = prefix+"-"+id;
                            st.msi.submissionIdentifier = st.msi.submissionIdentifier.replace(" ", "-");
                            st.msi.submissionIdentifier = st.msi.submissionIdentifier.replace("&", "and");
                            if (wgs){
                                String speciesName = null;
                                for (SampleNode sn : st.scd.getNodes(SampleNode.class)){
                                    for (SCDNodeAttribute a : sn.getAttributes()){
                                        if (OrganismAttribute.class.isInstance(a)){
                                            OrganismAttribute oa = (OrganismAttribute) a;
                                            speciesName = a.getAttributeValue();
                                        }
                                    }
                                }
                                if (speciesName == null){
                                    log.warn("Unable to determine species name");
                                } else {
                                    st.msi.submissionTitle = "Whole Genome Shotgun sequencing of "+speciesName;
                                }
                            } else if (tsa){
                                String speciesName = null;
                                for (SampleNode sn : st.scd.getNodes(SampleNode.class)){
                                    for (SCDNodeAttribute a : sn.getAttributes()){
                                        if (OrganismAttribute.class.isInstance(a)){
                                            OrganismAttribute oa = (OrganismAttribute) a;
                                            speciesName = a.getAttributeValue();
                                        }
                                    }
                                }
                                if (speciesName == null){
                                    log.warn("Unable to determine species name");
                                } else {
                                    st.msi.submissionTitle = "Transcriptome Shotgun sequencing of "+speciesName;
                                }
                            } else if (bar){
                                st.msi.submissionTitle = st.msi.submissionIdentifier;
                            }
                            log.debug("No. of publications = "+st.msi.publications.size());
                            log.debug("Empty? "+st.msi.publications.isEmpty());
                            File outputSubDir = new File(outputFile, st.msi.submissionIdentifier);
                            File sampletabPre = new File(outputSubDir, "sampletab.pre.txt");
                            outputSubDir.mkdirs();
                            log.info("Writing "+sampletabPre);
                            SampleTabWriter sampletabwriter = null;
                            try {
                                sampletabwriter = new SampleTabWriter(new BufferedWriter(new FileWriter(sampletabPre)));
                                sampletabwriter.write(st);
                            } catch (IOException e) {
                                log.error("Unable to write to "+sampletabPre, e);
                            } finally {
                                if (sampletabwriter != null){
                                    try {
                                        sampletabwriter.close();
                                    } catch (IOException e) {
                                    }
                                }
                            }
                            groupMap.remove(id);
                            stMap.remove(id);
                        }
                    }
                }
            }
            reader.close();
        } finally {
            try {
                if (reader != null){
                    reader.close();
                }
            } catch (IOException e){
            }
        }
    }
