Changeset 5142


Ignore:
Timestamp:
Nov 22, 2018, 1:33:00 PM (5 months ago)
Author:
Nicklas Nordborg
Message:

References #1081: The release exporter should export more data

Added BloodDnaWriter implementation. The query filter is DoNotUse=null and not annotations are currently exported.

This requried a change in the code for converting items names to release ID names since the blood items have '.b' suffix instead of a digit as specimen have. To be on the safe side, the exporter will now throw an exception if it encounters a name that can't be mapped instead of letting the name pass through unchanged. This might complicate things for file names, but this can now be controlled via flag.

Location:
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/AlignedWriter.java

    r5106 r5142  
    6161      {
    6262        JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false));     
    63         jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.BAM, aligned, fileFilterHisat));
    64         jsonFiles.addAll(item.getLinkedFilesJSON(aligned, fileFilterHisat));
     63        jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.BAM, aligned, fileFilterHisat, false));
     64        jsonFiles.addAll(item.getLinkedFilesJSON(aligned, fileFilterHisat, false));
    6565        if (jsonFiles.size() > 0)
    6666        {
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/BloodWriter.java

    r5138 r5142  
    4242      Sample blood = b.getItem();
    4343     
    44       JSONObject jsonCase = new JSONObject();
    45       jsonCase.put("name", blood.getExternalId());
    46       jsonCase.put("type", blood.getType().name());
    47       jsonCase.put("subtype", getName(blood.getItemSubtype()));
    48       jsonCase.put("parent", patient.getExternalId());
     44      JSONObject jsonBlood = new JSONObject();
     45      jsonBlood.put("name", blood.getExternalId());
     46      jsonBlood.put("type", blood.getType().name());
     47      jsonBlood.put("subtype", getName(blood.getItemSubtype()));
     48      jsonBlood.put("parent", patient.getExternalId());
    4949 
    5050      JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false));
    5151      jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.CONSENT, blood, null));
    52       jsonCase.put("annotations", jsonAnnotations);
    53       json.add(jsonCase);
     52      jsonBlood.put("annotations", jsonAnnotations);
     53      json.add(jsonBlood);
    5454    }
    5555   
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/CohortItem.java

    r5139 r5142  
    4242import net.sf.basedb.reggie.dao.Annotationtype;
    4343import net.sf.basedb.reggie.dao.Blood;
     44import net.sf.basedb.reggie.dao.BloodDna;
    4445import net.sf.basedb.reggie.dao.Case;
    4546import net.sf.basedb.reggie.dao.Datafiletype;
     
    9192  private List<Case> cases;
    9293  private List<Blood> blood;
     94  private List<BloodDna> bloodDna;
    9395  private List<SpecimenTube> specimens;
    9496  private List<NoSpecimen> noSpecimens;
     
    214216      ItemQuery<Sample> query = queryManager.getBloodQuery(patient);
    215217      blood = query == null ? Collections.emptyList() : Blood.toList(query.list(dc));
     218      NAME_TO_EXTERNAL_ID.map(blood);
    216219    }
    217220    return blood;
    218221  }
    219222
    220  
     223  /**
     224    Get all blood DNA extract that belong to this patient and have
     225    a valid blood parent item. The extracts must have DoNotUse=null.
     226    @since 4.21
     227  */
     228  public List<BloodDna> getBloodDna()
     229  {
     230    if (bloodDna == null)
     231    {
     232      ItemQuery<Extract> query = queryManager.getBloodDnaQuery(getBlood());
     233      bloodDna = query == null ? Collections.emptyList() : BloodDna.toBloodDna(query.list(dc));
     234    }
     235    return bloodDna;
     236  }
     237
    221238  /**
    222239    Get all specimen that belong to this patient and have a valid Case.
     
    589606 
    590607  @SuppressWarnings("unchecked")
    591   public JSONArray getDataFilesJSON(Datafiletype dft, FileStoreEnabled item, Filter<File> filter)
     608  public JSONArray getDataFilesJSON(Datafiletype dft, FileStoreEnabled item, Filter<File> filter, boolean translateFilenames)
    592609  {
    593610    JSONArray jsonFiles = new JSONArray();
     
    601618        if (filter.evaluate(f))
    602619        {
     620          String filename = f.getName();
    603621          JSONObject jsonFile = new FilteredJSONObject(new NotNullFilter<>(false));
    604622          jsonFile.put("type", dft.getName());
    605           jsonFile.put("originalName", f.getName());
    606           jsonFile.put("name", toReleaseId(f.getName()));
     623          jsonFile.put("originalName", filename);
     624          jsonFile.put("name", translateFilenames ? toReleaseId(filename) : filename);
    607625          jsonFile.put("size", f.getSize());
    608626          jsonFile.put("mimeType", f.getMimeType());
     
    616634 
    617635  @SuppressWarnings("unchecked")
    618   public JSONArray getLinkedFilesJSON(BasicItem item, Filter<File> filter)
     636  public JSONArray getLinkedFilesJSON(BasicItem item, Filter<File> filter, boolean translateFilenames)
    619637  {
    620638    ItemQuery<AnyToAny> fileQuery = AnyToAny.getLinksFrom(item);
     
    627645      if (filter.evaluate(f))
    628646      {
     647        String filename = f.getName();
    629648        JSONObject jsonFile = new FilteredJSONObject(new NotNullFilter<>(false));
    630649        jsonFile.put("link", any.getName());
    631         jsonFile.put("originalName", f.getName());
    632         jsonFile.put("name", toReleaseId(f.getName()));
     650        jsonFile.put("originalName", filename);
     651        jsonFile.put("name", translateFilenames ? toReleaseId(filename) : filename);
    633652        jsonFile.put("size", f.getSize());
    634653        jsonFile.put("mimeType", f.getMimeType());
     
    696715    NameToExternalIdConverter()
    697716    {
    698       this.specimenNamePattern = Pattern.compile("(\\d{7}\\.\\d+)(.*)");
     717      this.specimenNamePattern = Pattern.compile("(\\d{7}\\.\\w+)(.*)");
    699718      this.nameToExternalId = new HashMap<>();
    700719    }
     
    718737        if (externalId == null)
    719738        {
    720           throw new InvalidDataException("Could not find release ID for: " + spName);
     739          throw new InvalidDataException("Could not find ReleaseID for: " + spName + " (" + nameWithScanBId + ")");
    721740        }
    722741        return externalId + m.group(2);
    723742      }
    724       return nameWithScanBId;
     743      throw new InvalidDataException("Can't convert name to ReleaseID since it doesn't match expected pattern for SCAN-B specimen: " + nameWithScanBId);
    725744    }
    726745  }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/CufflinksWriter.java

    r5106 r5142  
    118118   
    119119      JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false));
    120       jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.FPKM, rba, fileFilterCufflinks));
    121       jsonFiles.addAll(item.getLinkedFilesJSON(rba, fileFilterCufflinks));
     120      jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.FPKM, rba, fileFilterCufflinks, false));
     121      jsonFiles.addAll(item.getLinkedFilesJSON(rba, fileFilterCufflinks, false));
    122122      jsonRaw.put("files", jsonFiles);
    123123     
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/MergedWriter.java

    r5106 r5142  
    103103      JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false));
    104104      jsonMerged.put("files", jsonFiles);
    105       jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.FASTQ, merged, null));
     105      jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.FASTQ, merged, null, true));
    106106
    107107      if (scriptWriter != null)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/QueryManager.java

    r5138 r5142  
    2222import net.sf.basedb.reggie.dao.AlignedSequences;
    2323import net.sf.basedb.reggie.dao.Annotationtype;
     24import net.sf.basedb.reggie.dao.Blood;
    2425import net.sf.basedb.reggie.dao.Case;
    2526import net.sf.basedb.reggie.dao.Histology;
     
    5556  private ItemQuery<Sample> histologyQuery;
    5657  private ItemQuery<Sample> goodStainQuery;
     58  private ItemQuery<Extract> bloodDnaQuery;
    5759  private ItemQuery<Extract> lysateQuery;
    5860  private ItemQuery<Extract> rnaQuery;
     
    115117
    116118  /**
     119    Get a query that is returning all BloodDNA items that are related
     120    to the given list of parent Blood. The query is filtered to only return
     121    items with DoNotUse=null.
     122    @return A query or null if the list is null or empty
     123  */
     124  public ItemQuery<Extract> getBloodDnaQuery(List<Blood> blood)
     125  {
     126    if (blood == null || blood.isEmpty()) return null;
     127    if (bloodDnaQuery == null)
     128    {
     129      bloodDnaQuery = Extract.getQuery();
     130      initBioMaterialQuery(bloodDnaQuery, Subtype.BLOOD_DNA, Subtype.BLOOD, ParentRestriction.LIST_ID);
     131      annotationEquals(bloodDnaQuery, Annotationtype.DO_NOT_USE, null);
     132    }
     133    bloodDnaQuery.setParameter("parents", idList(blood), Type.INT);
     134    return bloodDnaQuery;
     135  }
     136
     137 
     138  /**
    117139    Get a query that is returning all specimen tubes that are related
    118140    to the given list of cases. The query is filtered to only return
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/ReleaseExporter.java

    r5139 r5142  
    163163      jsonWriter.registerItemWriter(new NoWriter(dc, options));
    164164      jsonWriter.registerItemWriter(new BloodWriter(dc, options));
     165      jsonWriter.registerItemWriter(new BloodDnaWriter(dc, options));
    165166      jsonWriter.registerItemWriter(new CaseWriter(dc, options));
    166167      jsonWriter.registerItemWriter(new IncaWriter(dc, options));
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/StringTieWriter.java

    r5106 r5142  
    9696   
    9797      JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false));
    98       jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.GENERIC_RAWDATA, rba, fileFilterStringTie));
    99       jsonFiles.addAll(item.getLinkedFilesJSON(rba, fileFilterStringTie));
     98      jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.GENERIC_RAWDATA, rba, fileFilterStringTie, false));
     99      jsonFiles.addAll(item.getLinkedFilesJSON(rba, fileFilterStringTie, false));
    100100      jsonRaw.put("files", jsonFiles);
    101101     
Note: See TracChangeset for help on using the changeset viewer.