<commit_before>package uk.ac.ebi.atlas.experimentimport.experimentdesign.condensedSdrf;

import com.google.common.collect.ImmutableSet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import uk.ac.ebi.atlas.commons.readers.TsvReader;
import uk.ac.ebi.atlas.commons.readers.FileTsvReaderBuilder;
import uk.ac.ebi.atlas.commons.readers.UrlTsvReaderBuilder;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * Created by <NAME> <<EMAIL>> on 29/07/15.
 */

@Named
@Scope("prototype")
public class IdfParser {

    @Value("#{configuration['experiment.magetab.idf.path.template']}")
    private String idfPathTemplate;

    @Value("#{configuration['experiment.magetab.idf.url.template']}")
    private String idfUrlTemplate;

    private static final String INVESTIGATION_TITLE_ID = "Investigation Title";
    private static final String PUBMED_ID = "PubMed ID";

    private FileTsvReaderBuilder fileTsvReaderBuilder;
    private UrlTsvReaderBuilder urlTsvReaderBuilder;

    private String title = "";
    private ImmutableSet<String> pubmedIds;


    @Inject
    public IdfParser(FileTsvReaderBuilder fileTsvReaderBuilder, UrlTsvReaderBuilder urlTsvReaderBuilder) {
        this.urlTsvReaderBuilder = urlTsvReaderBuilder.forTsvFileUrlTemplate(idfUrlTemplate);
        this.fileTsvReaderBuilder = fileTsvReaderBuilder.forTsvFilePathTemplate(idfPathTemplate);
    }

    public void parse(String experimentAccession) {

        TsvReader idfReader;

        try {
            idfReader = urlTsvReaderBuilder.forTsvFileUrlTemplate(idfUrlTemplate).withExperimentAccession(experimentAccession).build();
        } catch (IllegalStateException e) {
            idfReader = fileTsvReaderBuilder.forTsvFilePathTemplate(idfPathTemplate).withExperimentAccession(experimentAccession).build();
        }

        ImmutableSet.Builder<String> pubmedIdsBuilder = new ImmutableSet.Builder<>();
        for (String tsvLine[]: idfReader.readAll()) {
            if (tsvLine[0].equalsIgnoreCase(INVESTIGATION_TITLE_ID)) {
                title = tsvLine[1];
            } else if (tsvLine[0].equalsIgnoreCase(PUBMED_ID)) {
                for (int i = 1 ; i < tsvLine.length ; i++) {
                    pubmedIdsBuilder.add(tsvLine[i]);
                }
            }
        }
        pubmedIds = pubmedIdsBuilder.build();<commit_msg>Don’t add empty PubMed ids to the experiment design<commit_after>package uk.ac.ebi.atlas.experimentimport.experimentdesign.condensedSdrf;

import com.google.common.collect.ImmutableSet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import uk.ac.ebi.atlas.commons.readers.TsvReader;
import uk.ac.ebi.atlas.commons.readers.FileTsvReaderBuilder;
import uk.ac.ebi.atlas.commons.readers.UrlTsvReaderBuilder;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * Created by <NAME> <<EMAIL>> on 29/07/15.
 */

@Named
@Scope("prototype")
public class IdfParser {

    @Value("#{configuration['experiment.magetab.idf.path.template']}")
    private String idfPathTemplate;

    @Value("#{configuration['experiment.magetab.idf.url.template']}")
    private String idfUrlTemplate;

    private static final String INVESTIGATION_TITLE_ID = "Investigation Title";
    private static final String PUBMED_ID = "PubMed ID";

    private FileTsvReaderBuilder fileTsvReaderBuilder;
    private UrlTsvReaderBuilder urlTsvReaderBuilder;

    private String title = "";
    private ImmutableSet<String> pubmedIds;


    @Inject
    public IdfParser(FileTsvReaderBuilder fileTsvReaderBuilder, UrlTsvReaderBuilder urlTsvReaderBuilder) {
        this.urlTsvReaderBuilder = urlTsvReaderBuilder.forTsvFileUrlTemplate(idfUrlTemplate);
        this.fileTsvReaderBuilder = fileTsvReaderBuilder.forTsvFilePathTemplate(idfPathTemplate);
    }

    public void parse(String experimentAccession) {

        TsvReader idfReader;

        try {
            idfReader = urlTsvReaderBuilder.forTsvFileUrlTemplate(idfUrlTemplate).withExperimentAccession(experimentAccession).build();
        } catch (IllegalStateException e) {
            idfReader = fileTsvReaderBuilder.forTsvFilePathTemplate(idfPathTemplate).withExperimentAccession(experimentAccession).build();
        }

        ImmutableSet.Builder<String> pubmedIdsBuilder = new ImmutableSet.Builder<>();
        for (String tsvLine[]: idfReader.readAll()) {
            if (tsvLine[0].equalsIgnoreCase(INVESTIGATION_TITLE_ID)) {
                title = tsvLine[1];
            } else if (tsvLine[0].equalsIgnoreCase(PUBMED_ID)) {
                for (int i = 1 ; i < tsvLine.length ; i++) {
                    if (!tsvLine[i].isEmpty()) {
                        pubmedIdsBuilder.add(tsvLine[i]);
                    }
                }
            }
        }
        pubmedIds = pubmedIdsBuilder.build();
{'fraction_non_alphanumeric': 0.1003064351378958, 'fraction_numerical': 0.0040858018386108275, 'mean_word_length': 3.6451612903225805, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2376135', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1458, 'n_words': 233}